@rohal12/spindle 0.43.1 → 0.43.2
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
CHANGED
|
@@ -22,9 +22,9 @@ function parseComputedArgs(rawArgs: string): { target: string; expr: string } {
|
|
|
22
22
|
const target = trimmed.slice(0, i).trim();
|
|
23
23
|
const expr = trimmed.slice(i + 1).trim();
|
|
24
24
|
|
|
25
|
-
if (!target.match(/^[$_]\w+$/)) {
|
|
25
|
+
if (!target.match(/^[$_@]\w+$/)) {
|
|
26
26
|
throw new Error(
|
|
27
|
-
`{computed}: target must be $name or
|
|
27
|
+
`{computed}: target must be $name, _name, or @name, got "${target}"`,
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -58,12 +58,14 @@ function computeAndApply(
|
|
|
58
58
|
expr: string,
|
|
59
59
|
name: string,
|
|
60
60
|
isTemp: boolean,
|
|
61
|
+
isLocal: boolean,
|
|
61
62
|
variables: Record<string, unknown>,
|
|
62
63
|
temporary: Record<string, unknown>,
|
|
63
64
|
locals: Record<string, unknown>,
|
|
64
65
|
transient: Record<string, unknown>,
|
|
65
66
|
rawArgs: string,
|
|
66
67
|
prevRef: { current: unknown },
|
|
68
|
+
localsUpdate: ((key: string, value: unknown) => void) | null,
|
|
67
69
|
): void {
|
|
68
70
|
let newValue: unknown;
|
|
69
71
|
try {
|
|
@@ -78,9 +80,20 @@ function computeAndApply(
|
|
|
78
80
|
|
|
79
81
|
if (!valuesEqual(prevRef.current, newValue)) {
|
|
80
82
|
prevRef.current = newValue;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
if (isLocal) {
|
|
84
|
+
try {
|
|
85
|
+
localsUpdate!(name, newValue);
|
|
86
|
+
} catch (err) {
|
|
87
|
+
console.error(
|
|
88
|
+
`spindle: Error in {computed ${rawArgs}}${currentSourceLocation()}:`,
|
|
89
|
+
err,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
const state = useStoryStore.getState();
|
|
94
|
+
if (isTemp) state.setTemporary(name, newValue);
|
|
95
|
+
else state.setVariable(name, newValue);
|
|
96
|
+
}
|
|
84
97
|
}
|
|
85
98
|
}
|
|
86
99
|
|
|
@@ -102,8 +115,10 @@ defineMacro({
|
|
|
102
115
|
/>
|
|
103
116
|
);
|
|
104
117
|
}
|
|
118
|
+
const isLocal = target.startsWith('@');
|
|
105
119
|
const isTemp = target.startsWith('_');
|
|
106
120
|
const name = target.slice(1);
|
|
121
|
+
const localsUpdate = isLocal ? ctx.update : null;
|
|
107
122
|
|
|
108
123
|
const prevOutput = ctx.hooks.useRef<unknown>(undefined);
|
|
109
124
|
|
|
@@ -114,12 +129,14 @@ defineMacro({
|
|
|
114
129
|
expr,
|
|
115
130
|
name,
|
|
116
131
|
isTemp,
|
|
132
|
+
isLocal,
|
|
117
133
|
mergedVars,
|
|
118
134
|
mergedTemps,
|
|
119
135
|
mergedLocals,
|
|
120
136
|
mergedTrans,
|
|
121
137
|
rawArgs,
|
|
122
138
|
prevOutput,
|
|
139
|
+
localsUpdate,
|
|
123
140
|
);
|
|
124
141
|
}
|
|
125
142
|
|
|
@@ -128,12 +145,14 @@ defineMacro({
|
|
|
128
145
|
expr,
|
|
129
146
|
name,
|
|
130
147
|
isTemp,
|
|
148
|
+
isLocal,
|
|
131
149
|
mergedVars,
|
|
132
150
|
mergedTemps,
|
|
133
151
|
mergedLocals,
|
|
134
152
|
mergedTrans,
|
|
135
153
|
rawArgs,
|
|
136
154
|
prevOutput,
|
|
155
|
+
localsUpdate,
|
|
137
156
|
);
|
|
138
157
|
}, [mergedVars, mergedTemps, mergedLocals, mergedTrans]);
|
|
139
158
|
|