-
Notifications
You must be signed in to change notification settings - Fork 0
feat(Campaign): make context creation extensible via async overridable template method #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
8dc419d
2383e28
c0f59a2
3a7b2fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,29 @@ export class Campaign extends NostoElement { | |
| async load() { | ||
| await loadCampaign(this) | ||
| } | ||
|
|
||
| /** | ||
| * Extension point: override to enrich or modify the template context. | ||
| * This method is called during campaign rendering to create the context object | ||
| * that will be passed to the template. Subclasses can override this method | ||
| * to add custom properties, feature flags, or transform the data. | ||
| * | ||
| * @param raw - The raw JSON result from the Nosto API | ||
| * @returns The context object to be used in template rendering | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * class CustomCampaign extends Campaign { | ||
| * createContext(raw) { | ||
| * const context = super.createContext(raw); | ||
| * return { ...context, customProperty: 'value' }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am still not understanding.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Functions that could be useful are
We replace Nosto recommendation data with Shopify data for alignment |
||
| * } | ||
| * } | ||
| * ``` | ||
| */ | ||
| createContext(raw: JSONResult): object { | ||
|
||
| return getContext(raw) | ||
| } | ||
| } | ||
|
|
||
| export async function loadCampaign(element: Campaign) { | ||
|
|
@@ -85,7 +108,7 @@ export async function loadCampaign(element: Campaign) { | |
| if (rec) { | ||
| if (useTemplate) { | ||
| const template = getTemplate(element) | ||
| compile(element, template, getContext(rec as JSONResult)) | ||
| compile(element, template, element.createContext(rec as JSONResult)) | ||
| api.attributeProductClicksInCampaign(element, rec as JSONResult) | ||
| } else { | ||
| await api.placements.injectCampaigns( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the cases where we would extend the Campaign custom element? Wouldn't it make it complex trying to promote inheritance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see good alternatives for inheritance here, since registration of custom functionality into custom element classes is also not something that is available as a standard pattern