@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.
- package/README.md +1 -1
- package/ai/cursor/rules/concorde.mdc +1 -1
- package/ai/skills/concorde-scope/SKILL.md +2 -2
- package/build-infos.json +1 -1
- package/concorde-core.bundle.js +289 -289
- package/concorde-core.es.js +4837 -4544
- package/dist/concorde-core.bundle.js +289 -289
- package/dist/concorde-core.es.js +4837 -4544
- package/dist/docs-mock-api-sw.js +19 -0
- package/dist/docs-mock-api-sw.js.map +2 -2
- package/docs/assets/index-wyNMyWT9.js +11196 -0
- package/docs/docs-mock-api-sw.js +19 -0
- package/docs/docs-mock-api-sw.js.map +2 -2
- package/docs/index.html +1 -1
- package/package.json +9 -1
- package/public/docs-mock-api-sw.js +19 -0
- package/public/docs-mock-api-sw.js.map +2 -2
- package/src/core/components/functional/example/example.ts +3 -3
- package/src/core/components/ui/icon/icon.ts +17 -2
- package/src/core/components/ui/menu/menu.ts +12 -3
- package/src/core/decorators/api.post.spec.ts +293 -0
- package/src/core/decorators/api.spec.ts +6 -6
- package/src/core/decorators/api.ts +643 -12
- package/src/core/decorators/subscriber/bind.ts +13 -5
- package/src/core/decorators/subscriber/dynamicPath.spec.ts +53 -0
- package/src/core/decorators/subscriber/dynamicPath.ts +23 -1
- package/src/core/decorators/subscriber/handle.ts +3 -1
- package/src/core/decorators/subscriber/onAssign.ts +10 -2
- package/src/core/decorators/subscriber/publish.ts +12 -2
- package/src/core/utils/PublisherProxy.ts +95 -11
- package/src/core/utils/api.ts +72 -3
- package/src/core/utils/dpOptions.spec.ts +56 -0
- package/src/core/utils/endpoint.ts +3 -3
- package/src/decorators.ts +17 -1
- package/src/docs/_core-concept/dataFlow.md +9 -3
- package/src/docs/_decorators/bind.md +2 -2
- package/src/docs/_decorators/get.md +13 -4
- package/src/docs/_decorators/handle.md +5 -1
- package/src/docs/_decorators/on-assign.md +2 -0
- package/src/docs/_decorators/patch.md +45 -0
- package/src/docs/_decorators/post.md +93 -0
- package/src/docs/_decorators/publish.md +1 -1
- package/src/docs/_decorators/put.md +43 -0
- package/src/docs/_decorators/subscribe.md +4 -1
- package/src/docs/_directives/sub.md +1 -1
- package/src/docs/_getting-started/my-first-component.md +1 -1
- package/src/docs/_misc/api-configuration.md +3 -1
- package/src/docs/_misc/dataProviderKey.md +2 -2
- package/src/docs/_misc/dynamic-path.md +71 -0
- package/src/docs/_misc/endpoint.md +5 -3
- package/src/docs/components/docs-demo-sources.ts +102 -3
- package/src/docs/components/docs-lit-demo-raw.ts +2 -26
- package/src/docs/components/docs-lit-demo.ts +9 -42
- package/src/docs/components/docs-source-excerpt.ts +53 -0
- package/src/docs/components/docs-source-link.ts +24 -8
- package/src/docs/components/docs-source-raw.ts +34 -0
- package/src/docs/example/decorators-demo-geo.ts +2 -2
- package/src/docs/example/decorators-demo-post.ts +249 -0
- package/src/docs/example/decorators-demo-subscribe-publish-get-demos.ts +5 -5
- package/src/docs/example/decorators-demo.ts +1 -0
- package/src/docs/example/docs-api-config-demos.ts +5 -5
- package/src/docs/mock-api/router.ts +20 -0
- package/src/docs/navigation/navigation.ts +16 -0
- package/src/docs/search/docs-search.json +540 -15
- package/src/tsconfig.json +24 -0
- package/src/tsconfig.tsbuildinfo +1 -1
- package/vite.config.mts +1 -1
- package/docs/assets/index-CwtPzTFq.js +0 -7508
- package/docs/src/core/components/functional/date/date.md +0 -290
- package/docs/src/core/components/functional/fetch/fetch.md +0 -125
- package/docs/src/core/components/functional/if/if.md +0 -9
- package/docs/src/core/components/functional/list/list.md +0 -65
- package/docs/src/core/components/functional/mix/mix.md +0 -41
- package/docs/src/core/components/functional/queue/queue.md +0 -72
- package/docs/src/core/components/functional/router/router.md +0 -94
- package/docs/src/core/components/functional/sdui/default-library.json +0 -108
- package/docs/src/core/components/functional/sdui/example.json +0 -99
- package/docs/src/core/components/functional/sdui/sdui.md +0 -356
- package/docs/src/core/components/functional/states/states.md +0 -87
- package/docs/src/core/components/functional/submit/submit.md +0 -114
- package/docs/src/core/components/functional/subscriber/subscriber.md +0 -91
- package/docs/src/core/components/functional/value/value.md +0 -35
- package/docs/src/core/components/ui/alert/alert.md +0 -121
- package/docs/src/core/components/ui/alert-messages/alert-messages.md +0 -0
- package/docs/src/core/components/ui/badge/badge.md +0 -127
- package/docs/src/core/components/ui/button/button.md +0 -182
- package/docs/src/core/components/ui/captcha/captcha.md +0 -12
- package/docs/src/core/components/ui/card/card.md +0 -97
- package/docs/src/core/components/ui/divider/divider.md +0 -35
- package/docs/src/core/components/ui/form/checkbox/checkbox.md +0 -77
- package/docs/src/core/components/ui/form/fieldset/fieldset.md +0 -129
- package/docs/src/core/components/ui/form/form-actions/form-actions.md +0 -77
- package/docs/src/core/components/ui/form/form-layout/form-layout.md +0 -44
- package/docs/src/core/components/ui/form/input/input.md +0 -142
- package/docs/src/core/components/ui/form/input-autocomplete/input-autocomplete.md +0 -133
- package/docs/src/core/components/ui/form/radio/radio.md +0 -57
- package/docs/src/core/components/ui/form/select/select.md +0 -71
- package/docs/src/core/components/ui/form/switch/switch.md +0 -57
- package/docs/src/core/components/ui/form/textarea/textarea.md +0 -65
- package/docs/src/core/components/ui/group/group.md +0 -75
- package/docs/src/core/components/ui/icon/icon.md +0 -125
- package/docs/src/core/components/ui/icon/icons.json +0 -1
- package/docs/src/core/components/ui/image/image.md +0 -107
- package/docs/src/core/components/ui/link/link.md +0 -43
- package/docs/src/core/components/ui/loader/loader.md +0 -55
- package/docs/src/core/components/ui/menu/menu.md +0 -329
- package/docs/src/core/components/ui/modal/modal.md +0 -119
- package/docs/src/core/components/ui/pop/pop.md +0 -96
- package/docs/src/core/components/ui/progress/progress.md +0 -63
- package/docs/src/core/components/ui/table/table.md +0 -455
- package/docs/src/core/components/ui/toast/toast.md +0 -166
- package/docs/src/core/components/ui/tooltip/tooltip.md +0 -82
- package/docs/src/docs/_core-concept/dataFlow.md +0 -73
- package/docs/src/docs/_core-concept/overview.md +0 -57
- package/docs/src/docs/_core-concept/subscriber.md +0 -75
- package/docs/src/docs/_decorators/ancestor-attribute.md +0 -79
- package/docs/src/docs/_decorators/auto-subscribe.md +0 -202
- package/docs/src/docs/_decorators/bind.md +0 -167
- package/docs/src/docs/_decorators/get.md +0 -68
- package/docs/src/docs/_decorators/handle.md +0 -171
- package/docs/src/docs/_decorators/on-assign.md +0 -388
- package/docs/src/docs/_decorators/publish.md +0 -55
- package/docs/src/docs/_decorators/subscribe.md +0 -97
- package/docs/src/docs/_decorators/wait-for-ancestors.md +0 -163
- package/docs/src/docs/_directives/sub.md +0 -91
- package/docs/src/docs/_getting-started/ai-agents.md +0 -56
- package/docs/src/docs/_getting-started/concorde-manual-install.md +0 -133
- package/docs/src/docs/_getting-started/concorde-outside.md +0 -33
- package/docs/src/docs/_getting-started/create-a-component.md +0 -139
- package/docs/src/docs/_getting-started/my-first-component.md +0 -236
- package/docs/src/docs/_getting-started/my-first-subscriber.md +0 -120
- package/docs/src/docs/_getting-started/pubsub.md +0 -37
- package/docs/src/docs/_getting-started/start.md +0 -47
- package/docs/src/docs/_getting-started/theming.md +0 -91
- package/docs/src/docs/_misc/api-configuration.md +0 -79
- package/docs/src/docs/_misc/dataProviderKey.md +0 -168
- package/docs/src/docs/_misc/docs-mock-api.md +0 -60
- package/docs/src/docs/_misc/endpoint.md +0 -43
- package/docs/src/docs/_misc/html-integration.md +0 -13
- package/docs/src/docs/search/docs-search.json +0 -8532
- package/docs/src/tag-list.json +0 -1
- package/docs/src/tsconfig-model.json +0 -23
- 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
|
-
<div class="flex flex-col gap-2">
|
|
215
|
-
<sonic-select label="Users set" @change=${this.updateDataProvider}>
|
|
216
|
-
<option value="demoUsers">First set of users</option>
|
|
217
|
-
<option value="demoUsersAlt">Second set of users</option>
|
|
218
|
-
</sonic-select>
|
|
219
|
-
<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
|
-
></sonic-input>
|
|
228
|
-
<sonic-button @click=${this.updateCurrentUserData}>
|
|
229
|
-
Update current user data
|
|
230
|
-
</sonic-button>
|
|
231
|
-
<div class="flex flex-col gap-2 border p-2">
|
|
232
|
-
<div>
|
|
233
|
-
<sonic-icon name="user" library="heroicons"></sonic-icon>
|
|
234
|
-
${this.user?.firstName} ${this.user?.lastName}
|
|
235
|
-
</div>
|
|
236
|
-
<div>
|
|
237
|
-
<sonic-icon name="envelope" library="heroicons"></sonic-icon>
|
|
238
|
-
${this.user?.email}
|
|
239
|
-
</div>
|
|
240
|
-
<div>
|
|
241
|
-
Theme: ${this.userSettings?.theme} | Language:
|
|
242
|
-
${this.userSettings?.language}
|
|
243
|
-
</div>
|
|
244
|
-
</div>
|
|
245
|
-
</div>
|
|
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<User>("demoUser");
|
|
355
|
-
const settings = new DataProviderKey<Settings>("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<AppSettings>("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<Data>("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<{ items: string[] }>("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<User, { userIndex: number }>("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<
|
|
71
|
-
User,
|
|
72
|
-
{ dataProvider: string | null }
|
|
73
|
-
>("${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
|