Skip to content

Commit 68710c1

Browse files
committed
Merge pull request #4 from feat/load-data-argument
Add data argument to the load() method
2 parents 0e3e0fc + 27b6f5b commit 68710c1

File tree

4 files changed

+36
-19
lines changed

4 files changed

+36
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ The log below details the changes during development of this version:
1515
* 2025-04-23: Fix in JSON-schemas: Changed `main` property in Graphics manifest to be **mandatory**.
1616
(Before, it was defined as mandatory in the specification document, but not in the JSON-schemas.)
1717
* 2025-05-16: Add `renderRequirements` property to Graphics manifest
18+
* 2025-05-16: Add `data` argument to the `load` method.
19+
Before, the `data`-payload was only sent using the `updateData()` method. Now it must be sent on `load()` as well.

v1-draft-0/examples/l3rd-name/graphic.mjs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class MyGraphic extends HTMLElement {
2323
// 2. Setup the DOM
2424
// 3. Initialize the GSAP timeline
2525

26+
2627
// Load the GSAP scripts ---------------------------------------------------
2728
const importsPromises = {
2829
gsap: import(import.meta.resolve("./lib/gsap-core.js")),
@@ -109,6 +110,13 @@ class MyGraphic extends HTMLElement {
109110
this.timeline.pause();
110111
} else throw new Error("Unsupported renderType: " + loadParams.renderType);
111112

113+
// Load initial data:
114+
this.initialData = loadParams.data
115+
await this._doAction("updateAction", {
116+
data: this.initialData || {},
117+
skipAnimation: true
118+
});
119+
112120
// When everything is loaded we can return:
113121
return;
114122
}
@@ -171,6 +179,12 @@ class MyGraphic extends HTMLElement {
171179

172180
// Initial state:
173181

182+
// Load initial data:
183+
await this._doAction("updateAction", {
184+
data: this.initialData || {},
185+
skipAnimation: true
186+
});
187+
174188
for (const event of (this.nonRealTimeState.schedule || [])) {
175189
const tweens = this._getActionAnimation(
176190
event.action.type,
@@ -247,24 +261,26 @@ class MyGraphic extends HTMLElement {
247261
_getUpdateAnimation(params) {
248262
const gsap = this.g.gsap;
249263

250-
this.displayState.data = params.data
264+
this.displayState.data = params.data || {}
265+
266+
const speed = params.skipAnimation ? 0 : 1
251267

252268
const showTitle = this.displayState.data.title
253269
const isPlaying = this.displayState.isPlaying
254270

255271
return [
256272
gsap.to(this.elements.nameText, {
257-
duration: 0.4,
258-
text: params.data.name,
273+
duration: speed * 0.4,
274+
text: this.displayState.data.name,
259275
}),
260276
gsap.to(this.elements.nameText2, {
261-
duration: 0.4,
262-
text: params.data.title,
277+
duration: speed * 0.4,
278+
text: this.displayState.data.title,
263279
}),
264280
(
265281
isPlaying &&
266282
gsap.to(this.elements.container2, {
267-
duration: 0.3,
283+
duration: speed * 0.3,
268284
y: 0,
269285
opacity: showTitle ? 1 : 0,
270286
ease: "power2.out",
@@ -273,7 +289,7 @@ class MyGraphic extends HTMLElement {
273289
(
274290
isPlaying &&
275291
gsap.to(this.elements.container, {
276-
duration: 0.3,
292+
duration: speed * 0.3,
277293
borderBottomLeftRadius: showTitle ? "0" : "20px",
278294
ease: "power2.out",
279295
})
@@ -285,7 +301,7 @@ class MyGraphic extends HTMLElement {
285301

286302
this.displayState.isPlaying = true
287303

288-
const showTitle = Boolean(this.displayState.data?.title)
304+
const showTitle = Boolean(this.displayState.data.title)
289305

290306

291307
return [
@@ -297,10 +313,6 @@ class MyGraphic extends HTMLElement {
297313
ease: "power2.out",
298314
}),
299315

300-
gsap.to(this.elements.nameText, {
301-
duration: 0.4,
302-
// text: this._currentData.name,
303-
}),
304316
gsap.to(this.elements.container2, {
305317
delay: 0.3,
306318
duration: 0.8,
@@ -311,7 +323,6 @@ class MyGraphic extends HTMLElement {
311323
gsap.to(this.elements.nameText2, {
312324
delay: 0.7,
313325
duration: 0.8,
314-
// text: this._currentData.name,
315326
}),
316327
gsap.to(this.elements.logo, {
317328
duration: 0.5,
@@ -321,7 +332,6 @@ class MyGraphic extends HTMLElement {
321332
duration: 1.5,
322333
rotation: 360,
323334
scale: 1
324-
// text: this._currentData.name,
325335
}),
326336
];
327337
}

v1-draft-0/specification/docs/Specification.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ The manifest file is a JSON file containing metadata about the Graphic. It consi
6666
| customActions | Action[] | | | An array of `Action` objects. They correspond to the custom actions that can be invoked on the Graphic. See below for details about the fields inside an `Action`. |
6767
| supportsRealTime | boolean | X | | Indicates whether the Graphic supports real-time rendering. |
6868
| supportsNonRealTime | boolean | X | | Indicates whether the Graphic supports non-real-time rendering. If true, the Graphic MUST implement the non-real-time functions `goToTime()` and `setActionsSchedule()`. |
69-
| schema | object | | | The JSON schema definition for the parameter of the `updateAction()` function. This schema can be seen as the (public) state model of the Graphic. |
69+
| schema | object | | | The JSON schema definition for the `data` argument to the `load()` and `updateAction()` methods. This schema can be seen as the (public) state model of the Graphic. |
7070
| stepCount | integer | | 1 | The number of steps a Graphic consists of. |
7171
| renderRequirements | RenderRequirement[]| | | A list of requirements that this Graphic has for the rendering environment. At least one of the requirements must be met for the graphic to be expected to work. |
7272

@@ -185,7 +185,9 @@ In [Typescript interface](#typescript-interface-for-graphic), the full interface
185185

186186

187187
Every Graphic MUST implement the following functions:
188-
* `load: ({}) => Promise<ReturnPayload>`: Called by the Renderer when the Graphic has been loaded into the DOM.
188+
* `load: ({ data:any }) => Promise<ReturnPayload>`: Called by the Renderer when the Graphic has been loaded into the DOM.
189+
The `data`-payload MUST contain the initial internal state of the Graphic.
190+
The schema of the `data`-payload of this function is described in the Manifest using the `schema` field.
189191
A Promise is returned that resolves when everything is loaded by the Graphic.
190192
* `dispose: ({}) => Promise<ReturnPayload>`: Called by the Renderer to force the Graphic to terminate/dispose/clear any loaded resources. A Promise
191193
is returned that resolves when the Graphic completed the necessary cleanup.
@@ -198,7 +200,7 @@ Every Graphic MUST implement the following functions:
198200
* `stopAction: ({skipAnimation: boolean}) => Promise<ReturnPayload>`: Called by the Renderer to stop the Graphic from being displayed.
199201
This can be with or without animation, depending on the value of the `skipAnimation` field. The returned Promise resolves to an `ReturnPayload` object.
200202
* `updateAction: ({ data: any }) => Promise<ReturnPayload>`: Called by the Renderer to update one or more fields of the internal state of the Graphic. The schema of the
201-
payload of this function is described in the Manifest using the `schema` field. The returned Promise resolves to an `ReturnPayload` object.
203+
`data`-payload of this function is described in the Manifest using the `schema` field. The returned Promise resolves to an `ReturnPayload` object.
202204
* `customAction: ({ id: string, payload: any}) => Promise<ReturnPayload>`: Called by the Renderer to invoke a custom action on the Graphic.
203205
The `id` field MUST correspond to an `id` of an Action that is defined in the Manifest file, inside the `actions` field.
204206
The schema for the `payload` field is the described in the corresponding Action inside the Manifest file. A Promise
@@ -271,7 +273,7 @@ The above manifest refers to the Javascript file `lower-third.mjs`, which is the
271273

272274
```typescript
273275
class Graphic extends HTMLElement {
274-
async load(loadParams) {
276+
async load({ data: { name: string } } ) {
275277
// Load resources and initialize
276278
}
277279
async dispose() {

v1-draft-0/typescript-definitions/src/apis/graphicsAPI.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export interface Graphic {
2828
*/
2929
load: (
3030
params: {
31+
/** The data send here is defined in the manifest "schema". Note: This data MUST HAVE the same type as the `data` argument in updateAction method. */
32+
data: unknown;
33+
3134
/** Whether the rendering is done in realtime or non-realtime */
3235
renderType: "realtime" | "non-realtime";
3336

@@ -45,7 +48,7 @@ export interface Graphic {
4548
/** This is called whenever user send a new data payload. */
4649
updateAction: (
4750
params: {
48-
/** The data send here is defined in the manifest "schema". */
51+
/** The data send here is defined in the manifest "schema". Note: This data MUST HAVE the same type as the `data` argument in the load method. */
4952
data: unknown;
5053
} & VendorExtend
5154
) => Promise<ReturnPayload>;

0 commit comments

Comments
 (0)