@thatopen/services 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/AGENTS.md +86 -76
  2. package/dist/cli.js +10 -1
  3. package/docs/access-backend-data.md +19 -19
  4. package/docs/app-architecture.md +94 -94
  5. package/docs/app-layout.md +139 -139
  6. package/docs/app-wiring.md +123 -123
  7. package/docs/bim-components/coding-conventions.md +128 -128
  8. package/docs/bim-components/element-collections.md +69 -69
  9. package/docs/bim-components/expose-events.md +84 -84
  10. package/docs/bim-components/library-examples.md +28 -28
  11. package/docs/bim-components/observable-collections.md +83 -83
  12. package/docs/bim-components/overview.md +160 -160
  13. package/docs/bim-components/per-frame-updates.md +20 -20
  14. package/docs/bim-components/save-and-restore-state.md +21 -21
  15. package/docs/bim-components/setup-and-cleanup.md +64 -64
  16. package/docs/bim-components/type-conventions.md +49 -49
  17. package/docs/bim-components/user-driven-object-creation.md +56 -56
  18. package/docs/cli-setup.md +54 -54
  19. package/docs/cloud-components.md +74 -74
  20. package/docs/connect-logic-to-ui.md +113 -113
  21. package/docs/previewing.md +45 -45
  22. package/docs/publishing.md +35 -35
  23. package/docs/scaffolding.md +71 -54
  24. package/docs/ui-components/async-actions.md +18 -18
  25. package/docs/ui-components/confirmation-dialog.md +39 -39
  26. package/docs/ui-components/data-table.md +185 -185
  27. package/docs/ui-components/display-text.md +39 -39
  28. package/docs/ui-components/inline-form.md +44 -44
  29. package/docs/ui-components/library-examples.md +24 -24
  30. package/docs/ui-components/overview.md +194 -194
  31. package/docs/ui-components/rendering-patterns.md +129 -129
  32. package/docs/ui-components/sections-layout.md +123 -123
  33. package/docs/update-grid-elements.md +46 -46
  34. package/docs/using-colors.md +32 -32
  35. package/docs/using-icons.md +37 -37
  36. package/package.json +2 -2
  37. package/src/cli/templates/bim/CONTEXT.md +1 -4
  38. package/src/cli/templates/bim/package.json +0 -1
  39. package/src/cli/templates/bim/src/main.ts +1 -2
  40. package/src/cli/templates/bim-beta/CONTEXT.md +241 -0
  41. package/src/cli/templates/bim-beta/package.json +25 -0
  42. package/src/cli/templates/bim-beta/src/app.ts +16 -0
  43. package/src/cli/templates/bim-beta/src/bim-components/CloudRunner/index.ts +91 -0
  44. package/src/cli/templates/bim-beta/src/bim-components/CloudRunner/src/index.ts +1 -0
  45. package/src/cli/templates/bim-beta/src/bim-components/CloudRunner/src/types.ts +5 -0
  46. package/src/cli/templates/bim-beta/src/bim-components/index.ts +1 -0
  47. package/src/cli/templates/bim-beta/src/globals.ts +1 -0
  48. package/src/cli/templates/bim-beta/src/main.ts +89 -0
  49. package/src/cli/templates/bim-beta/src/setups/cloud-runner.ts +13 -0
  50. package/src/cli/templates/bim-beta/src/setups/index.ts +3 -0
  51. package/src/cli/templates/bim-beta/src/setups/ui-manager.ts +27 -0
  52. package/src/cli/templates/bim-beta/src/setups/viewports-manager.ts +22 -0
  53. package/src/cli/templates/bim-beta/src/ui-components/app-info-section/index.ts +26 -0
  54. package/src/cli/templates/bim-beta/src/ui-components/app-info-section/src/index.ts +1 -0
  55. package/src/cli/templates/bim-beta/src/ui-components/app-info-section/src/types.ts +15 -0
  56. package/src/cli/templates/bim-beta/src/ui-components/cloud-runner-section/index.ts +37 -0
  57. package/src/cli/templates/bim-beta/src/ui-components/cloud-runner-section/src/index.ts +1 -0
  58. package/src/cli/templates/bim-beta/src/ui-components/cloud-runner-section/src/types.ts +14 -0
  59. package/src/cli/templates/bim-beta/src/ui-components/index.ts +2 -0
  60. package/src/cli/templates/cloud/CONTEXT.md +205 -205
  61. package/src/cli/templates/cloud/src/main.ts +70 -70
  62. package/src/cli/templates/shared/AGENTS.md +30 -23
  63. package/src/cli/templates/shared/CLAUDE.md +1 -1
@@ -1,83 +1,83 @@
1
- # Observable Collections
2
-
3
- `FRAGS.DataMap` and `FRAGS.DataSet` are lifecycle-aware extensions of `Map` and `Set`. The only difference from their native counterparts is that they emit events when items are added or removed, making the collection observable.
4
-
5
- Use `DataMap` when there is a clear key to identify each item. Use `DataSet` when the item itself is the identifier. `DataMap` is the default choice in most cases.
6
-
7
- ---
8
-
9
- ## `FRAGS.DataMap<K, V>`
10
-
11
- ### Declaration
12
-
13
- The primary collection of a component is conventionally named `list`:
14
-
15
- ```ts
16
- import * as FRAGS from "@thatopen/fragments"
17
-
18
- readonly list = new FRAGS.DataMap<string, SpotElevation>();
19
- ```
20
-
21
- ### Reactive events
22
-
23
- ```ts
24
- this.list.onItemSet.add(({ key, value }) => {
25
- // called after an item is added
26
- });
27
-
28
- this.list.onBeforeDelete.add(({ key, value }) => {
29
- // called before an item is removed — use to clean up resources
30
- });
31
-
32
- this.list.onItemDeleted.add(({ key }) => {
33
- // called after an item is removed
34
- });
35
- ```
36
-
37
- ### Get-or-create
38
-
39
- When inserting into a `DataMap` where the entry may not exist yet, use a get-or-create pattern:
40
-
41
- ```ts
42
- let entry = this.list.get(key);
43
- if (!entry) {
44
- entry = new SpotElevation();
45
- this.list.set(key, entry);
46
- }
47
- entry.doSomething();
48
- ```
49
-
50
- ### Guard
51
-
52
- A guard runs before every `set()` call and can block the insertion by returning `false`:
53
-
54
- ```ts
55
- this.list.guard = (key, value) => {
56
- return value.isValid;
57
- };
58
- ```
59
-
60
- ---
61
-
62
- ## `FRAGS.DataSet<T>`
63
-
64
- Same API as `DataMap` but without keys — the item itself is the identifier:
65
-
66
- ```ts
67
- readonly list = new FRAGS.DataSet<SpotElevation>();
68
-
69
- this.list.onItemSet.add(({ value }) => { ... });
70
- this.list.onBeforeDelete.add(({ value }) => { ... });
71
- ```
72
-
73
- ---
74
-
75
- ## Collections of auxiliary class instances
76
-
77
- When a component manages instances of its own auxiliary classes, cleanup typically happens in `onBeforeDelete`:
78
-
79
- ```ts
80
- this.list.onBeforeDelete.add(({ value: spotElevation }) => {
81
- spotElevation.dispose();
82
- });
83
- ```
1
+ # Observable Collections
2
+
3
+ `FRAGS.DataMap` and `FRAGS.DataSet` are lifecycle-aware extensions of `Map` and `Set`. The only difference from their native counterparts is that they emit events when items are added or removed, making the collection observable.
4
+
5
+ Use `DataMap` when there is a clear key to identify each item. Use `DataSet` when the item itself is the identifier. `DataMap` is the default choice in most cases.
6
+
7
+ ---
8
+
9
+ ## `FRAGS.DataMap<K, V>`
10
+
11
+ ### Declaration
12
+
13
+ The primary collection of a component is conventionally named `list`:
14
+
15
+ ```ts
16
+ import * as FRAGS from "@thatopen/fragments"
17
+
18
+ readonly list = new FRAGS.DataMap<string, SpotElevation>();
19
+ ```
20
+
21
+ ### Reactive events
22
+
23
+ ```ts
24
+ this.list.onItemSet.add(({ key, value }) => {
25
+ // called after an item is added
26
+ });
27
+
28
+ this.list.onBeforeDelete.add(({ key, value }) => {
29
+ // called before an item is removed — use to clean up resources
30
+ });
31
+
32
+ this.list.onItemDeleted.add(({ key }) => {
33
+ // called after an item is removed
34
+ });
35
+ ```
36
+
37
+ ### Get-or-create
38
+
39
+ When inserting into a `DataMap` where the entry may not exist yet, use a get-or-create pattern:
40
+
41
+ ```ts
42
+ let entry = this.list.get(key);
43
+ if (!entry) {
44
+ entry = new SpotElevation();
45
+ this.list.set(key, entry);
46
+ }
47
+ entry.doSomething();
48
+ ```
49
+
50
+ ### Guard
51
+
52
+ A guard runs before every `set()` call and can block the insertion by returning `false`:
53
+
54
+ ```ts
55
+ this.list.guard = (key, value) => {
56
+ return value.isValid;
57
+ };
58
+ ```
59
+
60
+ ---
61
+
62
+ ## `FRAGS.DataSet<T>`
63
+
64
+ Same API as `DataMap` but without keys — the item itself is the identifier:
65
+
66
+ ```ts
67
+ readonly list = new FRAGS.DataSet<SpotElevation>();
68
+
69
+ this.list.onItemSet.add(({ value }) => { ... });
70
+ this.list.onBeforeDelete.add(({ value }) => { ... });
71
+ ```
72
+
73
+ ---
74
+
75
+ ## Collections of auxiliary class instances
76
+
77
+ When a component manages instances of its own auxiliary classes, cleanup typically happens in `onBeforeDelete`:
78
+
79
+ ```ts
80
+ this.list.onBeforeDelete.add(({ value: spotElevation }) => {
81
+ spotElevation.dispose();
82
+ });
83
+ ```
@@ -1,160 +1,160 @@
1
- # BIM Component Creation
2
-
3
- Architecture, patterns, and step-by-step guide for creating BIM components with That Open Engine (OBC/OBF) — the domain-logic layer that wraps fragments, IFC data, measurements, selections, or any non-UI behavior.
4
-
5
- ## Working mode
6
-
7
- Before doing anything else, **read [`./library-examples.md`](./library-examples.md) and fetch the `paths.json` for both `engine_components` and `engine_fragment` in parallel.** Review all descriptions to understand what the engine already provides before forming any opinion about what needs to be built.
8
-
9
- Only after that, **propose an implementation plan and wait for the user's approval.**
10
-
11
- The proposal must describe:
12
- - Whether the need is covered by an existing engine component (consume via `components.get()`)
13
- - Whether existing components can be composed to cover it
14
- - Only if neither applies: which new component(s) will be created, what properties, events, and public methods it will expose, and whether it needs lifecycle, serialization, render loop, or interactive creation interfaces
15
-
16
- Only proceed with changes after the user explicitly confirms the plan. If the scope is unclear, ask first — do not assume.
17
-
18
- ---
19
-
20
- ## What is a BIM Component?
21
-
22
- That Open Engine is the collection of packages that power the app: `@thatopen/components`, `@thatopen/components-front`, `@thatopen/fragments`, `@thatopen/ui`, and `@thatopen/ui-obc`. BIM components are built on top of this ecosystem.
23
-
24
- A BIM component is a class that extends `OBC.Component` and encapsulates domain logic — IFC queries, calculations, data management, fragment operations, etc. It exposes that logic through a clean, event-driven interface that UI templates and other components can consume.
25
-
26
- ### The engine works with Fragments
27
-
28
- That Open Engine does not work with IFC STEP files directly. It works with **Fragments** — an open binary format (`.frag`) built for performance: a 2 GB IFC file becomes ~80 MB, loads in seconds at 60fps in the browser.
29
-
30
- The runtime representation of a loaded model is a `FragmentsModel`. Its data schema usually mirrors the IFC SCHEMA (local IDs map to IFC express IDs, the spatial structure parallels IFC hierarchy, properties follow IFC attributes and relations), but it is not IFC STEP — it is Fragments. Any component that queries elements, reads properties, or operates on geometry works through the `FragmentsModel` API.
31
-
32
- For loading models, querying elements, or reading properties, fetch the relevant example from [`./library-examples.md`](./library-examples.md) before writing any implementation code.
33
-
34
- ### When to create one
35
-
36
- Create a BIM component when custom domain logic is needed.
37
-
38
- After reviewing the `paths.json` descriptions fetched in the working mode step:
39
-
40
- - If an existing component covers the need → consume it via `this.components.get()` and fetch its example. Do not reimplement.
41
- - If existing components can be composed to cover it → compose them, fetching the relevant examples as building blocks.
42
- - Only if the need is genuinely not covered → propose creating a custom component.
43
-
44
- Custom components can themselves consume built-in components via `this.components.get()`, so examples remain useful even when building something new.
45
-
46
- ---
47
-
48
- ## Step 1 — Define the component
49
-
50
- Names should be short but descriptive. Use PascalCase for both folder and class, matching exactly:
51
-
52
- | Artifact | Convention | Example |
53
- |---|---|---|
54
- | Folder | PascalCase | `ActivityTracker/` |
55
- | Class | PascalCase | `ActivityTracker` |
56
- | Types prefix | PascalCase matching class | `ActivityTrackerConfig`, `ActivityTrackerResult` |
57
-
58
- Use the `Manager` suffix when the component creates instances of something or governs a broad concern — consistent with `FragmentsManager`, `Classifier`, etc. For focused, single-responsibility components, omit it.
59
-
60
- ---
61
-
62
- ## Step 2 — Create the file structure
63
-
64
- ```
65
- ActivityTracker/
66
- index.ts → class definition + re-exports ./src
67
- src/
68
- index.ts → re-exports types and support files
69
- types.ts → interfaces, type aliases, enums
70
- SpotElevation.ts → auxiliary class (if needed)
71
- ```
72
-
73
- Only one class per component extends `OBC.Component` — the main one in `index.ts`. Any other classes the component defines or instantiates are plain TypeScript classes that live in `src/` alongside `types.ts`, and never extend `OBC.Component`.
74
-
75
- ---
76
-
77
- ## Step 3 — Implement the class in `index.ts`
78
-
79
- ### Skeleton
80
-
81
- Every component needs a unique, hardcoded static UUID — a fixed string literal defined once and never changed. The constructor must call `super(components)` and register the instance with `components.add(UUID, this)` so it becomes globally retrievable via `components.get(ActivityTracker)`.
82
-
83
- Before writing the implementation, read [`./coding-conventions.md`](./coding-conventions.md) for naming rules, backing fields, and async patterns that apply throughout the class.
84
-
85
- ```ts
86
- import * as OBC from "@thatopen/components"
87
-
88
- export class ActivityTracker extends OBC.Component {
89
- static readonly uuid = "1b43361b-ef43-4207-9c40-dbed37bec0b6" as const;
90
-
91
- enabled = true;
92
-
93
- constructor(components: OBC.Components) {
94
- super(components);
95
- components.add(ActivityTracker.uuid, this);
96
- }
97
- }
98
-
99
- export * from "./src"
100
- ```
101
-
102
- ### Interfaces
103
-
104
- OBC defines capability interfaces that components can implement to stay consistent with each other and with the engine. Pick the resource that matches your need:
105
-
106
- | I need... | Resource |
107
- |---|---|
108
- | Initialize the component with config, or clean up resources when it's destroyed | [`./setup-and-cleanup.md`](./setup-and-cleanup.md) |
109
- | Save and restore state across sessions | [`./save-and-restore-state.md`](./save-and-restore-state.md) |
110
- | Run logic on every frame of the render loop | [`./per-frame-updates.md`](./per-frame-updates.md) |
111
- | Implement a flow where the user creates objects in the scene step by step | [`./user-driven-object-creation.md`](./user-driven-object-creation.md) |
112
- | Expose events or react to state changes | [`./expose-events.md`](./expose-events.md) |
113
-
114
- ### Accessing other components
115
-
116
- Resolve dependencies at call time — never store component instances as fields as it may create memory leaks:
117
-
118
- ```ts
119
- const fragments = this.components.get(OBC.FragmentsManager);
120
- const highlighter = this.components.get(OBF.Highlighter);
121
- ```
122
-
123
- ---
124
-
125
- ## Step 4 — Define types in `src/types.ts`
126
-
127
- Types are defined in parallel as the class needs them, not upfront. All typing for the component lives here — domain interfaces, event payloads, serialized types — so there is a single place to look.
128
-
129
- See [`./type-conventions.md`](./type-conventions.md) for common patterns (runtime vs serialized types, generics, etc.).
130
-
131
- ---
132
-
133
- ## Step 5 — Export from the barrel
134
-
135
- Re-export the component from the project's barrel index so it's accessible from a single import point:
136
-
137
- ```ts
138
- export * from "./ActivityTracker"
139
- ```
140
-
141
- ---
142
-
143
- ## Wiring up
144
-
145
- Instantiating the component and connecting it to engine events is not the component's responsibility — that belongs in external initialization code. The constructor should never call other components. See [`../app-wiring.md`](../app-wiring.md) for how this is done.
146
-
147
- ---
148
-
149
- ## See also
150
-
151
- - [`./library-examples.md`](./library-examples.md) — Find official usage examples and discover what the engine provides
152
- - [`./element-collections.md`](./element-collections.md) — Represent or combine element collections across components
153
- - [`./observable-collections.md`](./observable-collections.md) — Store component-internal data with reactive notifications
154
- - [`./expose-events.md`](./expose-events.md) — Expose events for other components or the UI to react to
155
- - [`./setup-and-cleanup.md`](./setup-and-cleanup.md) — Initialize the component with config or clean up resources on destroy
156
- - [`./save-and-restore-state.md`](./save-and-restore-state.md) — Persist and restore state across sessions
157
- - [`./per-frame-updates.md`](./per-frame-updates.md) — Run logic on every frame of the render loop
158
- - [`./user-driven-object-creation.md`](./user-driven-object-creation.md) — Let the user create objects in the scene step by step
159
- - [`./type-conventions.md`](./type-conventions.md) — Define component types (runtime vs serialized, generics)
160
- - [`./coding-conventions.md`](./coding-conventions.md) — Code conventions (naming, backing fields, async)
1
+ # BIM Component Creation
2
+
3
+ Architecture, patterns, and step-by-step guide for creating BIM components with That Open Engine (OBC/OBF) — the domain-logic layer that wraps fragments, IFC data, measurements, selections, or any non-UI behavior.
4
+
5
+ ## Working mode
6
+
7
+ Before doing anything else, **read [`./library-examples.md`](./library-examples.md) and fetch the `paths.json` for both `engine_components` and `engine_fragment` in parallel.** Review all descriptions to understand what the engine already provides before forming any opinion about what needs to be built.
8
+
9
+ Only after that, **propose an implementation plan and wait for the user's approval.**
10
+
11
+ The proposal must describe:
12
+ - Whether the need is covered by an existing engine component (consume via `components.get()`)
13
+ - Whether existing components can be composed to cover it
14
+ - Only if neither applies: which new component(s) will be created, what properties, events, and public methods it will expose, and whether it needs lifecycle, serialization, render loop, or interactive creation interfaces
15
+
16
+ Only proceed with changes after the user explicitly confirms the plan. If the scope is unclear, ask first — do not assume.
17
+
18
+ ---
19
+
20
+ ## What is a BIM Component?
21
+
22
+ That Open Engine is the collection of packages that power the app: `@thatopen/components`, `@thatopen/components-front`, `@thatopen/fragments`, `@thatopen/ui`, and `@thatopen/ui-obc`. BIM components are built on top of this ecosystem.
23
+
24
+ A BIM component is a class that extends `OBC.Component` and encapsulates domain logic — IFC queries, calculations, data management, fragment operations, etc. It exposes that logic through a clean, event-driven interface that UI templates and other components can consume.
25
+
26
+ ### The engine works with Fragments
27
+
28
+ That Open Engine does not work with IFC STEP files directly. It works with **Fragments** — an open binary format (`.frag`) built for performance: a 2 GB IFC file becomes ~80 MB, loads in seconds at 60fps in the browser.
29
+
30
+ The runtime representation of a loaded model is a `FragmentsModel`. Its data schema usually mirrors the IFC SCHEMA (local IDs map to IFC express IDs, the spatial structure parallels IFC hierarchy, properties follow IFC attributes and relations), but it is not IFC STEP — it is Fragments. Any component that queries elements, reads properties, or operates on geometry works through the `FragmentsModel` API.
31
+
32
+ For loading models, querying elements, or reading properties, fetch the relevant example from [`./library-examples.md`](./library-examples.md) before writing any implementation code.
33
+
34
+ ### When to create one
35
+
36
+ Create a BIM component when custom domain logic is needed.
37
+
38
+ After reviewing the `paths.json` descriptions fetched in the working mode step:
39
+
40
+ - If an existing component covers the need → consume it via `this.components.get()` and fetch its example. Do not reimplement.
41
+ - If existing components can be composed to cover it → compose them, fetching the relevant examples as building blocks.
42
+ - Only if the need is genuinely not covered → propose creating a custom component.
43
+
44
+ Custom components can themselves consume built-in components via `this.components.get()`, so examples remain useful even when building something new.
45
+
46
+ ---
47
+
48
+ ## Step 1 — Define the component
49
+
50
+ Names should be short but descriptive. Use PascalCase for both folder and class, matching exactly:
51
+
52
+ | Artifact | Convention | Example |
53
+ |---|---|---|
54
+ | Folder | PascalCase | `ActivityTracker/` |
55
+ | Class | PascalCase | `ActivityTracker` |
56
+ | Types prefix | PascalCase matching class | `ActivityTrackerConfig`, `ActivityTrackerResult` |
57
+
58
+ Use the `Manager` suffix when the component creates instances of something or governs a broad concern — consistent with `FragmentsManager`, `Classifier`, etc. For focused, single-responsibility components, omit it.
59
+
60
+ ---
61
+
62
+ ## Step 2 — Create the file structure
63
+
64
+ ```
65
+ ActivityTracker/
66
+ index.ts → class definition + re-exports ./src
67
+ src/
68
+ index.ts → re-exports types and support files
69
+ types.ts → interfaces, type aliases, enums
70
+ SpotElevation.ts → auxiliary class (if needed)
71
+ ```
72
+
73
+ Only one class per component extends `OBC.Component` — the main one in `index.ts`. Any other classes the component defines or instantiates are plain TypeScript classes that live in `src/` alongside `types.ts`, and never extend `OBC.Component`.
74
+
75
+ ---
76
+
77
+ ## Step 3 — Implement the class in `index.ts`
78
+
79
+ ### Skeleton
80
+
81
+ Every component needs a unique, hardcoded static UUID — a fixed string literal defined once and never changed. The constructor must call `super(components)` and register the instance with `components.add(UUID, this)` so it becomes globally retrievable via `components.get(ActivityTracker)`.
82
+
83
+ Before writing the implementation, read [`./coding-conventions.md`](./coding-conventions.md) for naming rules, backing fields, and async patterns that apply throughout the class.
84
+
85
+ ```ts
86
+ import * as OBC from "@thatopen/components"
87
+
88
+ export class ActivityTracker extends OBC.Component {
89
+ static readonly uuid = "1b43361b-ef43-4207-9c40-dbed37bec0b6" as const;
90
+
91
+ enabled = true;
92
+
93
+ constructor(components: OBC.Components) {
94
+ super(components);
95
+ components.add(ActivityTracker.uuid, this);
96
+ }
97
+ }
98
+
99
+ export * from "./src"
100
+ ```
101
+
102
+ ### Interfaces
103
+
104
+ OBC defines capability interfaces that components can implement to stay consistent with each other and with the engine. Pick the resource that matches your need:
105
+
106
+ | I need... | Resource |
107
+ |---|---|
108
+ | Initialize the component with config, or clean up resources when it's destroyed | [`./setup-and-cleanup.md`](./setup-and-cleanup.md) |
109
+ | Save and restore state across sessions | [`./save-and-restore-state.md`](./save-and-restore-state.md) |
110
+ | Run logic on every frame of the render loop | [`./per-frame-updates.md`](./per-frame-updates.md) |
111
+ | Implement a flow where the user creates objects in the scene step by step | [`./user-driven-object-creation.md`](./user-driven-object-creation.md) |
112
+ | Expose events or react to state changes | [`./expose-events.md`](./expose-events.md) |
113
+
114
+ ### Accessing other components
115
+
116
+ Resolve dependencies at call time — never store component instances as fields as it may create memory leaks:
117
+
118
+ ```ts
119
+ const fragments = this.components.get(OBC.FragmentsManager);
120
+ const highlighter = this.components.get(OBF.Highlighter);
121
+ ```
122
+
123
+ ---
124
+
125
+ ## Step 4 — Define types in `src/types.ts`
126
+
127
+ Types are defined in parallel as the class needs them, not upfront. All typing for the component lives here — domain interfaces, event payloads, serialized types — so there is a single place to look.
128
+
129
+ See [`./type-conventions.md`](./type-conventions.md) for common patterns (runtime vs serialized types, generics, etc.).
130
+
131
+ ---
132
+
133
+ ## Step 5 — Export from the barrel
134
+
135
+ Re-export the component from the project's barrel index so it's accessible from a single import point:
136
+
137
+ ```ts
138
+ export * from "./ActivityTracker"
139
+ ```
140
+
141
+ ---
142
+
143
+ ## Wiring up
144
+
145
+ Instantiating the component and connecting it to engine events is not the component's responsibility — that belongs in external initialization code. The constructor should never call other components. See [`../app-wiring.md`](../app-wiring.md) for how this is done.
146
+
147
+ ---
148
+
149
+ ## See also
150
+
151
+ - [`./library-examples.md`](./library-examples.md) — Find official usage examples and discover what the engine provides
152
+ - [`./element-collections.md`](./element-collections.md) — Represent or combine element collections across components
153
+ - [`./observable-collections.md`](./observable-collections.md) — Store component-internal data with reactive notifications
154
+ - [`./expose-events.md`](./expose-events.md) — Expose events for other components or the UI to react to
155
+ - [`./setup-and-cleanup.md`](./setup-and-cleanup.md) — Initialize the component with config or clean up resources on destroy
156
+ - [`./save-and-restore-state.md`](./save-and-restore-state.md) — Persist and restore state across sessions
157
+ - [`./per-frame-updates.md`](./per-frame-updates.md) — Run logic on every frame of the render loop
158
+ - [`./user-driven-object-creation.md`](./user-driven-object-creation.md) — Let the user create objects in the scene step by step
159
+ - [`./type-conventions.md`](./type-conventions.md) — Define component types (runtime vs serialized, generics)
160
+ - [`./coding-conventions.md`](./coding-conventions.md) — Code conventions (naming, backing fields, async)
@@ -1,20 +1,20 @@
1
- # Per-Frame Updates
2
-
3
- ## `OBC.Updateable`
4
-
5
- Implement when the component needs to execute logic on every frame — animating objects, polling state, updating visual feedback.
6
-
7
- ```ts
8
- export class ActivityTracker extends OBC.Component implements OBC.Updateable {
9
- readonly onBeforeUpdate = new OBC.Event<undefined>();
10
- readonly onAfterUpdate = new OBC.Event<undefined>();
11
-
12
- update(delta?: number) {
13
- this.onBeforeUpdate.trigger(undefined);
14
- // per-frame logic
15
- this.onAfterUpdate.trigger(undefined);
16
- }
17
- }
18
- ```
19
-
20
- The component is driven externally — a world or a setup file calls `update()` each frame. The component never drives itself.
1
+ # Per-Frame Updates
2
+
3
+ ## `OBC.Updateable`
4
+
5
+ Implement when the component needs to execute logic on every frame — animating objects, polling state, updating visual feedback.
6
+
7
+ ```ts
8
+ export class ActivityTracker extends OBC.Component implements OBC.Updateable {
9
+ readonly onBeforeUpdate = new OBC.Event<undefined>();
10
+ readonly onAfterUpdate = new OBC.Event<undefined>();
11
+
12
+ update(delta?: number) {
13
+ this.onBeforeUpdate.trigger(undefined);
14
+ // per-frame logic
15
+ this.onAfterUpdate.trigger(undefined);
16
+ }
17
+ }
18
+ ```
19
+
20
+ The component is driven externally — a world or a setup file calls `update()` each frame. The component never drives itself.
@@ -1,21 +1,21 @@
1
- # Save and Restore State
2
-
3
- ## `OBC.Serializable<D, S>`
4
-
5
- Implement when the component must persist its state — to a file, to the cloud, or across sessions.
6
-
7
- `D` is the runtime type, `S` is the serialized (JSON-safe) equivalent. Both are defined in `src/types.ts`. See [`./type-conventions.md`](./type-conventions.md) for the serialization patterns, including the `localId` → GUID conversion that must happen before storing any item references.
8
-
9
- ```ts
10
- export class ActivityTracker extends OBC.Component
11
- implements OBC.Serializable<ActivityTrackerData, SerializedActivityTrackerData> {
12
-
13
- export(): SerializedActivityTrackerData {
14
- // convert runtime state to JSON-safe structure
15
- }
16
-
17
- import(data: SerializedActivityTrackerData) {
18
- // restore runtime state from serialized structure
19
- }
20
- }
21
- ```
1
+ # Save and Restore State
2
+
3
+ ## `OBC.Serializable<D, S>`
4
+
5
+ Implement when the component must persist its state — to a file, to the cloud, or across sessions.
6
+
7
+ `D` is the runtime type, `S` is the serialized (JSON-safe) equivalent. Both are defined in `src/types.ts`. See [`./type-conventions.md`](./type-conventions.md) for the serialization patterns, including the `localId` → GUID conversion that must happen before storing any item references.
8
+
9
+ ```ts
10
+ export class ActivityTracker extends OBC.Component
11
+ implements OBC.Serializable<ActivityTrackerData, SerializedActivityTrackerData> {
12
+
13
+ export(): SerializedActivityTrackerData {
14
+ // convert runtime state to JSON-safe structure
15
+ }
16
+
17
+ import(data: SerializedActivityTrackerData) {
18
+ // restore runtime state from serialized structure
19
+ }
20
+ }
21
+ ```