@supersoniks/concorde 4.7.4 → 4.8.0

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 (143) hide show
  1. package/README.md +1 -1
  2. package/ai/cursor/rules/concorde.mdc +1 -1
  3. package/ai/skills/concorde-scope/SKILL.md +2 -2
  4. package/build-infos.json +1 -1
  5. package/concorde-core.bundle.js +289 -289
  6. package/concorde-core.es.js +4837 -4544
  7. package/dist/concorde-core.bundle.js +289 -289
  8. package/dist/concorde-core.es.js +4837 -4544
  9. package/dist/docs-mock-api-sw.js +19 -0
  10. package/dist/docs-mock-api-sw.js.map +2 -2
  11. package/docs/assets/index-wyNMyWT9.js +11196 -0
  12. package/docs/docs-mock-api-sw.js +19 -0
  13. package/docs/docs-mock-api-sw.js.map +2 -2
  14. package/docs/index.html +1 -1
  15. package/package.json +9 -1
  16. package/public/docs-mock-api-sw.js +19 -0
  17. package/public/docs-mock-api-sw.js.map +2 -2
  18. package/src/core/components/functional/example/example.ts +3 -3
  19. package/src/core/components/ui/icon/icon.ts +17 -2
  20. package/src/core/components/ui/menu/menu.ts +12 -3
  21. package/src/core/decorators/api.post.spec.ts +293 -0
  22. package/src/core/decorators/api.spec.ts +6 -6
  23. package/src/core/decorators/api.ts +643 -12
  24. package/src/core/decorators/subscriber/bind.ts +13 -5
  25. package/src/core/decorators/subscriber/dynamicPath.spec.ts +53 -0
  26. package/src/core/decorators/subscriber/dynamicPath.ts +23 -1
  27. package/src/core/decorators/subscriber/handle.ts +3 -1
  28. package/src/core/decorators/subscriber/onAssign.ts +10 -2
  29. package/src/core/decorators/subscriber/publish.ts +12 -2
  30. package/src/core/utils/PublisherProxy.ts +95 -11
  31. package/src/core/utils/api.ts +72 -3
  32. package/src/core/utils/dpOptions.spec.ts +56 -0
  33. package/src/core/utils/endpoint.ts +3 -3
  34. package/src/decorators.ts +17 -1
  35. package/src/docs/_core-concept/dataFlow.md +9 -3
  36. package/src/docs/_decorators/bind.md +2 -2
  37. package/src/docs/_decorators/get.md +13 -4
  38. package/src/docs/_decorators/handle.md +5 -1
  39. package/src/docs/_decorators/on-assign.md +2 -0
  40. package/src/docs/_decorators/patch.md +45 -0
  41. package/src/docs/_decorators/post.md +93 -0
  42. package/src/docs/_decorators/publish.md +1 -1
  43. package/src/docs/_decorators/put.md +43 -0
  44. package/src/docs/_decorators/subscribe.md +4 -1
  45. package/src/docs/_directives/sub.md +1 -1
  46. package/src/docs/_getting-started/my-first-component.md +1 -1
  47. package/src/docs/_misc/api-configuration.md +3 -1
  48. package/src/docs/_misc/dataProviderKey.md +2 -2
  49. package/src/docs/_misc/dynamic-path.md +71 -0
  50. package/src/docs/_misc/endpoint.md +5 -3
  51. package/src/docs/components/docs-demo-sources.ts +102 -3
  52. package/src/docs/components/docs-lit-demo-raw.ts +2 -26
  53. package/src/docs/components/docs-lit-demo.ts +9 -42
  54. package/src/docs/components/docs-source-excerpt.ts +53 -0
  55. package/src/docs/components/docs-source-link.ts +24 -8
  56. package/src/docs/components/docs-source-raw.ts +34 -0
  57. package/src/docs/example/decorators-demo-geo.ts +2 -2
  58. package/src/docs/example/decorators-demo-post.ts +249 -0
  59. package/src/docs/example/decorators-demo-subscribe-publish-get-demos.ts +5 -5
  60. package/src/docs/example/decorators-demo.ts +1 -0
  61. package/src/docs/example/docs-api-config-demos.ts +5 -5
  62. package/src/docs/mock-api/router.ts +20 -0
  63. package/src/docs/navigation/navigation.ts +16 -0
  64. package/src/docs/search/docs-search.json +540 -15
  65. package/src/tsconfig.json +24 -0
  66. package/src/tsconfig.tsbuildinfo +1 -1
  67. package/vite.config.mts +1 -1
  68. package/docs/assets/index-CwtPzTFq.js +0 -7508
  69. package/docs/src/core/components/functional/date/date.md +0 -290
  70. package/docs/src/core/components/functional/fetch/fetch.md +0 -125
  71. package/docs/src/core/components/functional/if/if.md +0 -9
  72. package/docs/src/core/components/functional/list/list.md +0 -65
  73. package/docs/src/core/components/functional/mix/mix.md +0 -41
  74. package/docs/src/core/components/functional/queue/queue.md +0 -72
  75. package/docs/src/core/components/functional/router/router.md +0 -94
  76. package/docs/src/core/components/functional/sdui/default-library.json +0 -108
  77. package/docs/src/core/components/functional/sdui/example.json +0 -99
  78. package/docs/src/core/components/functional/sdui/sdui.md +0 -356
  79. package/docs/src/core/components/functional/states/states.md +0 -87
  80. package/docs/src/core/components/functional/submit/submit.md +0 -114
  81. package/docs/src/core/components/functional/subscriber/subscriber.md +0 -91
  82. package/docs/src/core/components/functional/value/value.md +0 -35
  83. package/docs/src/core/components/ui/alert/alert.md +0 -121
  84. package/docs/src/core/components/ui/alert-messages/alert-messages.md +0 -0
  85. package/docs/src/core/components/ui/badge/badge.md +0 -127
  86. package/docs/src/core/components/ui/button/button.md +0 -182
  87. package/docs/src/core/components/ui/captcha/captcha.md +0 -12
  88. package/docs/src/core/components/ui/card/card.md +0 -97
  89. package/docs/src/core/components/ui/divider/divider.md +0 -35
  90. package/docs/src/core/components/ui/form/checkbox/checkbox.md +0 -77
  91. package/docs/src/core/components/ui/form/fieldset/fieldset.md +0 -129
  92. package/docs/src/core/components/ui/form/form-actions/form-actions.md +0 -77
  93. package/docs/src/core/components/ui/form/form-layout/form-layout.md +0 -44
  94. package/docs/src/core/components/ui/form/input/input.md +0 -142
  95. package/docs/src/core/components/ui/form/input-autocomplete/input-autocomplete.md +0 -133
  96. package/docs/src/core/components/ui/form/radio/radio.md +0 -57
  97. package/docs/src/core/components/ui/form/select/select.md +0 -71
  98. package/docs/src/core/components/ui/form/switch/switch.md +0 -57
  99. package/docs/src/core/components/ui/form/textarea/textarea.md +0 -65
  100. package/docs/src/core/components/ui/group/group.md +0 -75
  101. package/docs/src/core/components/ui/icon/icon.md +0 -125
  102. package/docs/src/core/components/ui/icon/icons.json +0 -1
  103. package/docs/src/core/components/ui/image/image.md +0 -107
  104. package/docs/src/core/components/ui/link/link.md +0 -43
  105. package/docs/src/core/components/ui/loader/loader.md +0 -55
  106. package/docs/src/core/components/ui/menu/menu.md +0 -329
  107. package/docs/src/core/components/ui/modal/modal.md +0 -119
  108. package/docs/src/core/components/ui/pop/pop.md +0 -96
  109. package/docs/src/core/components/ui/progress/progress.md +0 -63
  110. package/docs/src/core/components/ui/table/table.md +0 -455
  111. package/docs/src/core/components/ui/toast/toast.md +0 -166
  112. package/docs/src/core/components/ui/tooltip/tooltip.md +0 -82
  113. package/docs/src/docs/_core-concept/dataFlow.md +0 -73
  114. package/docs/src/docs/_core-concept/overview.md +0 -57
  115. package/docs/src/docs/_core-concept/subscriber.md +0 -75
  116. package/docs/src/docs/_decorators/ancestor-attribute.md +0 -79
  117. package/docs/src/docs/_decorators/auto-subscribe.md +0 -202
  118. package/docs/src/docs/_decorators/bind.md +0 -167
  119. package/docs/src/docs/_decorators/get.md +0 -68
  120. package/docs/src/docs/_decorators/handle.md +0 -171
  121. package/docs/src/docs/_decorators/on-assign.md +0 -388
  122. package/docs/src/docs/_decorators/publish.md +0 -55
  123. package/docs/src/docs/_decorators/subscribe.md +0 -97
  124. package/docs/src/docs/_decorators/wait-for-ancestors.md +0 -163
  125. package/docs/src/docs/_directives/sub.md +0 -91
  126. package/docs/src/docs/_getting-started/ai-agents.md +0 -56
  127. package/docs/src/docs/_getting-started/concorde-manual-install.md +0 -133
  128. package/docs/src/docs/_getting-started/concorde-outside.md +0 -33
  129. package/docs/src/docs/_getting-started/create-a-component.md +0 -139
  130. package/docs/src/docs/_getting-started/my-first-component.md +0 -236
  131. package/docs/src/docs/_getting-started/my-first-subscriber.md +0 -120
  132. package/docs/src/docs/_getting-started/pubsub.md +0 -37
  133. package/docs/src/docs/_getting-started/start.md +0 -47
  134. package/docs/src/docs/_getting-started/theming.md +0 -91
  135. package/docs/src/docs/_misc/api-configuration.md +0 -79
  136. package/docs/src/docs/_misc/dataProviderKey.md +0 -168
  137. package/docs/src/docs/_misc/docs-mock-api.md +0 -60
  138. package/docs/src/docs/_misc/endpoint.md +0 -43
  139. package/docs/src/docs/_misc/html-integration.md +0 -13
  140. package/docs/src/docs/search/docs-search.json +0 -8532
  141. package/docs/src/tag-list.json +0 -1
  142. package/docs/src/tsconfig-model.json +0 -23
  143. package/docs/src/tsconfig.json +0 -1095
@@ -1,388 +0,0 @@
1
- # @onAssign
2
-
3
- > **New apps:** use [@handle](#docs/_decorators/handle.md/handle) with `DataProviderKey` ([Data flow](#docs/_core-concept/dataFlow.md/dataFlow)). `@onAssign` uses untyped string paths; it remains documented for existing codebases — see **Migrating to @handle** below.
4
-
5
- The `@onAssign` decorator allows you to execute a method when one or more publishers are updated. The method is called only when all specified publishers have been assigned values.
6
-
7
- For a **typed** equivalent (recommended), use [@handle](#docs/_decorators/handle.md/handle).
8
-
9
- ## Principle
10
-
11
- This decorator subscribes to one or more publishers by **string path** (legacy). When all specified publishers have been assigned values (via `set`), the decorated method is called with all the values as arguments. Prefer [@handle](#docs/_decorators/handle.md/handle) + `DataProviderKey` and `get` / `set` from [Data flow](#docs/_core-concept/dataFlow.md/dataFlow).
12
-
13
- This is particularly useful when you need to wait for multiple data sources to be ready before executing logic.
14
-
15
- ## Usage
16
-
17
- ### Import
18
-
19
- <sonic-code language="typescript">
20
- <template>
21
- import { onAssign } from "@supersoniks/concorde/decorators";
22
- </template>
23
- </sonic-code>
24
-
25
- ### Basic example
26
-
27
-
28
- <sonic-code language="typescript">
29
- <template>
30
- //...
31
- @customElement("demo-on-assign")
32
- export class DemoOnAssign extends LitElement {
33
- static styles = [tailwind];
34
-
35
- @state() userWithSettings: any = null;
36
- @state() isReady: boolean = false;
37
- @state() lastUpdate: string = "";
38
-
39
- @onAssign("demoUser", "demoUserSettings")
40
- handleDataReady(user: any, settings: any) {
41
- this.isReady = Object.keys(user).length > 0 && Object.keys(settings).length > 0;
42
- this.userWithSettings = { ...user, ...settings };
43
- this.lastUpdate = new Date().toLocaleTimeString();
44
- this.requestUpdate();
45
- }
46
-
47
- render() {
48
- const { name, email, theme, language } = this.userWithSettings;
49
- return //...
50
- }
51
-
52
- updateData() {
53
- const user = PublisherManager.get("demoUser");
54
- const userSettings = PublisherManager.get("demoUserSettings");
55
- const userNumber = Math.floor(Math.random() * 100);
56
- user.set({
57
- name: `User n°${userNumber}`,
58
- email: `user-${userNumber}@example.com`,
59
- });
60
-
61
- userSettings.set({
62
- theme: ["light", "dark", "auto"][Math.floor(Math.random() * 3)],
63
- language: ["en", "fr", "es"][Math.floor(Math.random() * 3)],
64
- });
65
- }
66
- }
67
- </template>
68
- </sonic-code>
69
-
70
- <sonic-code>
71
- <template>
72
- <docs-demo-sources for="demo-on-assign"></docs-demo-sources>
73
- <demo-on-assign></demo-on-assign>
74
- </template>
75
- </sonic-code>
76
-
77
-
78
- ### Example with nested paths
79
-
80
- <sonic-code language="typescript">
81
- <template>
82
- @customElement("product-view")
83
- export class ProductView extends LitElement {
84
- product: any = null;
85
- inventory: any = null;
86
-
87
- @onAssign("store.product", "store.inventory")
88
- handleProductData(product: any, inventory: any) {
89
- this.product = product;
90
- this.inventory = inventory;
91
- this.requestUpdate();
92
- }
93
-
94
- render() {
95
- if (!this.product) return html`<div>Loading...</div>`;
96
-
97
- const stock = this.inventory[this.product.id] || 0;
98
- return html`
99
- <div>
100
- <h2>${this.product.name}</h2>
101
- <p>Price: ${this.product.price}€</p>
102
- <p>Stock: ${stock}</p>
103
- </div>
104
- `;
105
- }
106
- }
107
- </template>
108
- </sonic-code>
109
-
110
- ## Path syntax
111
-
112
- The path uses dot notation to navigate through the publisher structure:
113
-
114
- - **First segment**: dataProvider identifier (e.g., `"userData"`)
115
- - **Following segments**: nested properties (e.g., `"store.product"`)
116
- - **Array access**: use numeric index (e.g., `"data.items.0"`)
117
-
118
- ### Dynamic path driven by class properties
119
-
120
- You can now build the paths dynamically by referencing the host class properties inside the strings passed to `@onAssign`. Two placeholder syntaxes are supported:
121
-
122
- - `` ${myProperty} `` or `` ${this.myProperty} ``
123
- - `` {$myProperty} ``
124
-
125
- Each placeholder is replaced at runtime with the current value of the corresponding property. `@onAssign` automatically watches those properties and:
126
-
127
- - re-evaluates the final paths when one of them changes,
128
- - removes the previous subscriptions before attaching the new ones,
129
- - observe the changes inside `willUpdate(changedProperties)` so nothing touches the getters/setters.
130
-
131
-
132
- <sonic-code language="typescript">
133
- <template>
134
- @customElement("demo-on-assign-dynamic")
135
- export class DemoOnAssignDynamic extends LitElement {
136
- static styles = [tailwind];
137
-
138
- @property({ type: String })
139
- dataProvider: "demoUsers" | "demoUsersAlt" = "demoUsers";
140
-
141
- @property({ type: Number })
142
- userIndex: number = 0;
143
-
144
- @state() user: any = null;
145
- @state() userSettings: any = null;
146
-
147
- @onAssign("${dataProvider}.${userIndex}", "${dataProvider}Settings.${userIndex}")
148
- handleUserDataReady(user: any, settings: any) {
149
- this.user = user;
150
- this.userSettings = settings;
151
- }
152
-
153
- updateUserIndex(e: Event) {
154
- this.userIndex = parseInt((e.target as HTMLInputElement).value);
155
- }
156
-
157
- updateDataProvider(e: Event) {
158
- this.dataProvider = (e.target as HTMLSelectElement).value as
159
- | "demoUsers"
160
- | "demoUsersAlt";
161
- }
162
-
163
- updateCurrentUserData() {
164
- const usersPublisher = PublisherManager.get(this.dataProvider);
165
- const settingsPublisher = PublisherManager.get(
166
- `${this.dataProvider}Settings`
167
- );
168
- const userPublisher = Objects.traverse(
169
- usersPublisher,
170
- [String(this.userIndex)]
171
- ) as PublisherProxy;
172
- const settingPublisher = Objects.traverse(
173
- settingsPublisher,
174
- [String(this.userIndex)]
175
- ) as PublisherProxy;
176
-
177
- if (userPublisher && settingPublisher) {
178
- // Générer de nouvelles données aléatoires
179
- const randomNames = [
180
- { firstName: "Alice", lastName: "Wonder" },
181
- { firstName: "Bob", lastName: "Builder" },
182
- { firstName: "Charlie", lastName: "Chaplin" },
183
- ];
184
- const randomThemes = ["light", "dark", "auto"];
185
- const randomLanguages = ["en", "fr", "es"];
186
-
187
- const randomName =
188
- randomNames[Math.floor(Math.random() * randomNames.length)];
189
- const randomEmail = `${randomName.firstName.toLowerCase()}.${randomName.lastName.toLowerCase()}@example.com`;
190
- const randomTheme =
191
- randomThemes[Math.floor(Math.random() * randomThemes.length)];
192
- const randomLanguage =
193
- randomLanguages[Math.floor(Math.random() * randomLanguages.length)];
194
-
195
- // Mettre à jour l'utilisateur directement
196
- const currentUser = userPublisher.get() || {};
197
- userPublisher.set({
198
- ...currentUser,
199
- firstName: randomName.firstName,
200
- lastName: randomName.lastName,
201
- email: randomEmail,
202
- });
203
-
204
- // Mettre à jour les settings directement
205
- settingPublisher.set({
206
- theme: randomTheme,
207
- language: randomLanguage,
208
- });
209
- }
210
- }
211
-
212
- render() {
213
- return html`
214
- &lt;div class="flex flex-col gap-2"&gt;
215
- &lt;sonic-select label="Users set" @change=${this.updateDataProvider}&gt;
216
- &lt;option value="demoUsers"&gt;First set of users&lt;/option&gt;
217
- &lt;option value="demoUsersAlt"&gt;Second set of users&lt;/option&gt;
218
- &lt;/sonic-select&gt;
219
- &lt;sonic-input
220
- type="number"
221
- .value=${this.userIndex}
222
- @input=${this.updateUserIndex}
223
- min="0"
224
- max="9"
225
- label="Index"
226
- class="block"
227
- &gt;&lt;/sonic-input&gt;
228
- &lt;sonic-button @click=${this.updateCurrentUserData}&gt;
229
- Update current user data
230
- &lt;/sonic-button&gt;
231
- &lt;div class="flex flex-col gap-2 border p-2"&gt;
232
- &lt;div&gt;
233
- &lt;sonic-icon name="user" library="heroicons"&gt;&lt;/sonic-icon&gt;
234
- ${this.user?.firstName} ${this.user?.lastName}
235
- &lt;/div&gt;
236
- &lt;div&gt;
237
- &lt;sonic-icon name="envelope" library="heroicons"&gt;&lt;/sonic-icon&gt;
238
- ${this.user?.email}
239
- &lt;/div&gt;
240
- &lt;div&gt;
241
- Theme: ${this.userSettings?.theme} | Language:
242
- ${this.userSettings?.language}
243
- &lt;/div&gt;
244
- &lt;/div&gt;
245
- &lt;/div&gt;
246
- `;
247
- }
248
- }
249
- </template>
250
- </sonic-code>
251
-
252
- <sonic-code>
253
- <template>
254
- <docs-demo-sources for="demo-on-assign-dynamic"></docs-demo-sources>
255
- <demo-on-assign-dynamic></demo-on-assign-dynamic>
256
- </template>
257
- </sonic-code>
258
-
259
- > ⚠️ Use classic string literals: `@onAssign("${dataProvider}.${profileId}", "settings.${profileId}")`. Do **not** use template literals (backticks), otherwise JavaScript would try to interpolate the value immediately.
260
-
261
- Additional constraints:
262
-
263
- - The hosting class must expose a `willUpdate(changedProperties?: Map<PropertyKey, unknown>)` method (LitElement already provides it) so that `@onAssign` can listen to dependency changes.
264
- - Dependencies need to be reactive (e.g. `@property()` on LitElement) or you must call `this.requestUpdate("myProp")` manually after changing them, otherwise `willUpdate` will never be notified.
265
- - If you use nested expressions like `${user.id}`, the first segment (`user`) is the one being observed: you need to reassign `this.user` (e.g. with a new object) so that the binding can detect the change.
266
-
267
- ## Behavior
268
-
269
- - The method is called only when **all** specified publishers have been assigned values
270
- - The method receives the values of all publishers as arguments, in the same order as specified
271
- - Subscription happens at the time of `connectedCallback`
272
- - Unsubscription happens automatically at the time of `disconnectedCallback`
273
- - If a publisher doesn't exist yet, it will be created with the value `null`
274
- - The method is called with `this` bound to the component instance
275
-
276
- ## Use cases
277
-
278
- This decorator is particularly useful for:
279
-
280
- - **Waiting for multiple data sources** before rendering or executing logic
281
- - **Synchronizing data** from different publishers
282
- - **Initializing components** that depend on multiple data providers
283
- - **Handling complex data dependencies** where you need all data to be ready
284
-
285
- ## Complete example
286
-
287
- <sonic-code language="typescript">
288
- <template>
289
- import { html, LitElement } from "lit";
290
- import { customElement } from "lit/decorators.js";
291
- import { onAssign } from "@supersoniks/concorde/decorators";
292
- import { PublisherManager } from "@supersoniks/concorde/core/utils/PublisherProxy";
293
-
294
- @customElement("order-summary")
295
- export class OrderSummary extends LitElement {
296
- order: any = null;
297
- customer: any = null;
298
- shipping: any = null;
299
-
300
- @onAssign("orderData", "customerData", "shippingData")
301
- handleOrderReady(order: any, customer: any, shipping: any) {
302
- this.order = order;
303
- this.customer = customer;
304
- this.shipping = shipping;
305
- this.requestUpdate();
306
- }
307
-
308
- render() {
309
- if (!this.order || !this.customer || !this.shipping) {
310
- return html`<div>Loading order details...</div>`;
311
- }
312
-
313
- return html`
314
- <div class="order-summary">
315
- <h2>Order #${this.order.id}</h2>
316
- <p>Customer: ${this.customer.name}</p>
317
- <p>Shipping to: ${this.shipping.address}</p>
318
- <p>Total: ${this.order.total}€</p>
319
- </div>
320
- `;
321
- }
322
- }
323
- // Somewhere in your code, update the publishers:
324
- const orderPub = PublisherManager.get("orderData");
325
- const customerPub = PublisherManager.get("customerData");
326
- const shippingPub = PublisherManager.get("shippingData");
327
- // The method will be called only when all three are set:
328
- orderPub.set({ id: "123", total: 99.99 });
329
- customerPub.set({ name: "John Doe", email: "john@example.com" });
330
- shippingPub.set({ address: "123 Main St" });
331
- // handleOrderReady will be called with all three values
332
- </template>
333
- </sonic-code>
334
-
335
- ## Migrating to @handle
336
-
337
- `@handle` is the typed successor of `@onAssign`. The key behavioral difference: `@onAssign` waits for **all** values to be defined before calling the method, whereas `@handle` calls it on **every** assignment by default. Use the `waitForAllDefined` option to keep the old semantics.
338
-
339
- ### Why migrate
340
-
341
- - **Typed paths**: keys are `DataProviderKey<T>`, so the method arguments are strongly typed (no more `any`).
342
- - **Explicit intent**: `waitForAllDefined` and `skip` replace implicit behavior.
343
- - **Single API**: `@handle` covers the mono- and multi-path cases (up to 3 keys).
344
-
345
- ### Equivalent semantics (`waitForAllDefined`)
346
-
347
- <sonic-code language="typescript">
348
- <template>
349
- // Before
350
- @onAssign("demoUser", "demoUserSettings")
351
- handleDataReady(user: any, settings: any) { /* ... */ }
352
-
353
- // After — same "wait for everything" behavior, but typed
354
- const user = new DataProviderKey&lt;User&gt;("demoUser");
355
- const settings = new DataProviderKey&lt;Settings&gt;("demoUserSettings");
356
-
357
- @handle(user, settings, { waitForAllDefined: true })
358
- handleDataReady(user: User, settings: Settings) { /* ... */ }
359
- </template>
360
- </sonic-code>
361
-
362
- ### Single path
363
-
364
- <sonic-code language="typescript">
365
- <template>
366
- // Before
367
- @onAssign("settings.modules.logs_route.enabled")
368
- onLogRoute(value: boolean) { /* ... */ }
369
-
370
- // After
371
- const settings = new DataProviderKey&lt;AppSettings&gt;("settings");
372
-
373
- @handle(settings.modules.logs_route.enabled)
374
- onLogRoute(value: boolean) { /* ... */ }
375
- </template>
376
- </sonic-code>
377
-
378
- ### 4+ paths
379
-
380
- `@handle` is capped at 3 keys. For the rare case of 4 or more publishers, keep `@onAssign` for now, or split the logic into several `@handle` methods that each store their value and call a shared method (guarding against partial values).
381
-
382
- ## Notes
383
-
384
- - This decorator works with any component that has `connectedCallback` and `disconnectedCallback` methods (such as `LitElement` or components extending `Subscriber`)
385
- - The method is called synchronously when all publishers are ready
386
- - If you need to update the UI, remember to call `this.requestUpdate()` inside the method
387
- - For more information about publishers, see the documentation on [Sharing data](#docs/_getting-started/pubsub.md/pubsub)
388
-
@@ -1,55 +0,0 @@
1
- # @publish
2
-
3
- Write-only binding: assigning to the property publishes to the `DataProviderKey` path. No read subscription (inverse of [@subscribe](#docs/_decorators/subscribe.md/subscribe)).
4
-
5
- Similar to the “reflect” half of [@bind](#docs/_decorators/bind.md/bind) without listening to the publisher.
6
-
7
- ## Import
8
-
9
- <sonic-code language="typescript">
10
- <template>
11
- import { publish } from "@supersoniks/concorde/decorators";
12
- import { sub } from "@supersoniks/concorde/directives";
13
- import { DataProviderKey } from "@supersoniks/concorde/dataProviderKey";
14
- </template>
15
- </sonic-code>
16
-
17
- ## Example
18
-
19
- <sonic-code language="typescript">
20
- <template>
21
- type PublishDemoData = { email: string; message: string };
22
- const publishDemoKey = new DataProviderKey<PublishDemoData>("publishDemo");
23
- //
24
- @customElement("demo-publish")
25
- export class DemoPublish extends LitElement {
26
- @publish(publishDemoKey.email)
27
- @state()
28
- email = "";
29
- //
30
- @publish(publishDemoKey.message)
31
- @state()
32
- message = "";
33
- //
34
- render() {
35
- return html`
36
- <sonic-input
37
- .value=${this.email}
38
- @input=${(e) => (this.email = (e.target as HTMLInputElement).value)}
39
- label="Email"
40
- ></sonic-input>
41
- <p>${sub(publishDemoKey.email)}</p>
42
- `;
43
- }
44
- }
45
- </template>
46
- </sonic-code>
47
-
48
- <sonic-code>
49
- <template>
50
- <docs-demo-sources for="demo-publish"></docs-demo-sources>
51
- <demo-publish></demo-publish>
52
- </template>
53
- </sonic-code>
54
-
55
- Dynamic paths use the same placeholder rules as `@bind` / `@subscribe`.
@@ -1,97 +0,0 @@
1
- # @subscribe
2
-
3
- Keeps a **Lit property** in sync with a **read-only** slice of the DataProvider store. You pass a [`DataProviderKey`](#docs/_misc/dataProviderKey.md/dataProviderKey); when that path changes, the property updates and the component re-renders.
4
-
5
- Typical setup (same idea as [My first component](#docs/_getting-started/my-first-component.md/my-first-component)):
6
-
7
- | Piece | Role |
8
- |-------|------|
9
- | **Type** `T` | Shape of the object at that path (`DocsUserData`, `{ count: number }`, …) |
10
- | **Key** | `DataProviderKey<T, U>` — static path (`"cart"`) or dynamic (`"users.${userIndex}"`, `"${dataProvider}"`) |
11
- | **Scope on the host** | Properties listed in `U` (e.g. `dataProvider`, `userIndex`) — often filled via [`@ancestorAttribute`](#docs/_decorators/ancestor-attribute.md/ancestor-attribute) |
12
- | **`@subscribe(key)`** | Mirrors the store into `@state()` (or another property); read-only from the component side |
13
-
14
- For **writing** back to the store from component state, use [@publish](#docs/_decorators/publish.md/publish). In templates, the same paths work with [sub()](#docs/_directives/sub.md/sub).
15
-
16
- ## Import
17
-
18
- <sonic-code language="typescript">
19
- <template>
20
- import { subscribe } from "@supersoniks/concorde/decorators";
21
- import { DataProviderKey } from "@supersoniks/concorde/dataProviderKey";
22
-
23
- type Data = { count: number };
24
- const dataKey = new DataProviderKey&lt;Data&gt;("data");
25
-
26
- @subscribe(dataKey.count)
27
- @state()
28
- count = 0;
29
- </template>
30
- </sonic-code>
31
-
32
- ## Static path
33
-
34
- The key path is fixed. The property type must match `T` at that segment.
35
-
36
- <sonic-code language="typescript">
37
- <template>
38
- const cartKey = new DataProviderKey&lt;{ items: string[] }&gt;("cart");
39
-
40
- @subscribe(cartKey)
41
- @state()
42
- cart: { items: string[] } | null = null;
43
- </template>
44
- </sonic-code>
45
-
46
- ## Dynamic path and scope
47
-
48
- Placeholders `${prop}` in the key string are resolved from **properties on the same component**. Declare them in the key’s second generic so TypeScript expects them on the host:
49
-
50
- <sonic-code language="typescript">
51
- <template>
52
- type User = { firstName: string; lastName: string; email: string };
53
-
54
- @subscribe(new DataProviderKey&lt;User, { userIndex: number }&gt;("demoUsers.${userIndex}"))
55
- @state()
56
- user: User | null = null;
57
-
58
- @property({ type: Number }) userIndex = 0;
59
- </template>
60
- </sonic-code>
61
-
62
- When `userIndex` changes, `@subscribe` re-resolves the path and refreshes `user`.
63
-
64
- ## Row / ancestor scope
65
-
66
- List items (and wrappers like `<div dataProvider="…">`) set which branch the child reads. Pattern from the tutorial:
67
-
68
- <sonic-code language="typescript">
69
- <template>
70
- export const rowKey = new DataProviderKey&lt;
71
- User,
72
- { dataProvider: string | null }
73
- &gt;("${dataProvider}");
74
-
75
- @ancestorAttribute("dataProvider")
76
- dataProvider: string | null = null;
77
-
78
- @subscribe(rowKey)
79
- @state()
80
- user: User | null = null;
81
- </template>
82
- </sonic-code>
83
-
84
- ## Demo
85
-
86
- <sonic-code>
87
- <template>
88
- <docs-demo-sources for="demo-subscribe-dynamic"></docs-demo-sources>
89
- <demo-subscribe-dynamic></demo-subscribe-dynamic>
90
- </template>
91
- </sonic-code>
92
-
93
- ## See also
94
-
95
- - [Data flow](#docs/_core-concept/dataFlow.md/dataFlow) — overview
96
- - [DataProviderKey](#docs/_misc/dataProviderKey.md/dataProviderKey) — paths and host generics
97
- - [sub()](#docs/_directives/sub.md/sub) — same paths inside `html` templates