@ashley-shrok/viewmodel-shell 0.3.4 → 0.3.5
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/package.json +1 -1
- package/src/index.ts +17 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ashley-shrok/viewmodel-shell",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "A server-driven UI framework where the wire format is structured enough that agents can build full-stack apps without ever opening a browser and all UI tests are pure unit tests with no browser runtime. Server returns a JSON tree of typed nodes; a thin TypeScript adapter renders it to DOM. Backend-agnostic — a .NET reference backend ships with the repo, but any language can produce the JSON contract.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/index.ts
CHANGED
|
@@ -194,11 +194,20 @@ export interface ShellOptions {
|
|
|
194
194
|
onRedirect?: (url: string) => void;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
export interface ShellSideEffect {
|
|
198
|
+
/** "set-local-storage" | "set-session-storage" — unknown types are silently ignored. */
|
|
199
|
+
type: string;
|
|
200
|
+
key?: string;
|
|
201
|
+
value?: string;
|
|
202
|
+
}
|
|
203
|
+
|
|
197
204
|
export interface ShellResponse {
|
|
198
205
|
vm: ViewNode;
|
|
199
206
|
state: unknown;
|
|
200
207
|
/** When set, the shell navigates to this URL instead of re-rendering. */
|
|
201
208
|
redirect?: string;
|
|
209
|
+
/** Applied in order before redirect or re-render. */
|
|
210
|
+
sideEffects?: ShellSideEffect[];
|
|
202
211
|
}
|
|
203
212
|
|
|
204
213
|
export class ViewModelShell {
|
|
@@ -258,6 +267,14 @@ export class ViewModelShell {
|
|
|
258
267
|
});
|
|
259
268
|
if (!res.ok) throw new Error(`Action '${action.name}' failed: ${res.status}`);
|
|
260
269
|
const body = (await res.json()) as ShellResponse;
|
|
270
|
+
for (const effect of body.sideEffects ?? []) {
|
|
271
|
+
if (effect.type === "set-local-storage" && effect.key != null) {
|
|
272
|
+
localStorage.setItem(effect.key, effect.value ?? "");
|
|
273
|
+
} else if (effect.type === "set-session-storage" && effect.key != null) {
|
|
274
|
+
sessionStorage.setItem(effect.key, effect.value ?? "");
|
|
275
|
+
}
|
|
276
|
+
// unknown types silently ignored — forward-compatible
|
|
277
|
+
}
|
|
261
278
|
if (body.redirect) {
|
|
262
279
|
if (this.options.onRedirect) {
|
|
263
280
|
this.options.onRedirect(body.redirect);
|