-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Problem
NostoCampaign
currently calls getContext(...)
directly when preparing template data. This prevents subclasses or future variations (e.g., adding custom context enrichment, feature flags, A/B metadata) from extending or modifying the context before rendering.
Goal
Introduce a template method that centralizes context construction so it can be overridden or monkey‑patched without duplicating render logic.
Proposal
- Add a method (e.g.
createContext(raw: JSONResult): object
) inNostoCampaign
. - Replace direct
getContext(...)
usage withthis.createContext(...)
. - Document the extension point in TypeDoc.
Acceptance Criteria
- Campaign still renders identically (no behavioral changes).
- Tests pass (no snapshot/content change).
- Subclasses can override
createContext
to inject/transform values. - TypeDoc shows the new method.
- No lint/type errors.
Non-Goals
- No refactor of
getContext
itself. - No changes to other components yet.
Risks
- Overridden implementations might skip required normalization. Mitigate via doc note: “Call super.createContext(raw)” or reuse
getContext
.
Suggested Patch (illustrative)
// ...existing code...
import { getContext } from "../../templating/context"
// ...existing code...
export class NostoCampaign extends NostoElement {
// ...existing code...
/**
* Extension point: override to enrich or modify the template context
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
createContext(raw: JSONResult) {
return getContext(raw)
}
async #renderRecommendation(rec: Recommendation) {
// ...existing code...
// before:
// const ctx = getContext(base)
const ctx = this.createContext(base)
// ...existing code...
}
// ...existing code...
}
Follow-up Tasks
- Add a brief test with a subclass overriding
createContext
(optional but recommended). - Update README / developer docs (extension section) if such section exists.
Labels Suggested:
type: enhancement
, component: campaign
, extensibility
, good first issue
Let me know if you want the test scaffold added in the same issue.
Copilot
Metadata
Metadata
Assignees
Labels
No labels