@mulanjs/mulanjs 1.0.1-dev.20260227181914 → 1.0.1-dev.20260228083459
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/dist/core/reactive.js +30 -2
- package/dist/mulan.esm.js +30 -2
- package/dist/mulan.esm.js.map +1 -1
- package/dist/mulan.js +2416 -2388
- package/dist/mulan.js.map +1 -1
- package/dist/types/core/reactive.d.ts +2 -1
- package/package.json +6 -2
package/dist/core/reactive.js
CHANGED
|
@@ -146,12 +146,23 @@ function trigger(target, key) {
|
|
|
146
146
|
});
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
+
// Array mutating methods that must trigger reactive updates
|
|
150
|
+
const ARRAY_MUTATION_METHODS = ['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse', 'fill'];
|
|
151
|
+
// Proxy cache: ensures the same object always returns the same Proxy
|
|
152
|
+
// This is CRITICAL for array reactivity — mu-for and array mutations must
|
|
153
|
+
// share the same Proxy instance, otherwise triggers reach different subscribers.
|
|
154
|
+
const proxyCache = new WeakMap();
|
|
149
155
|
/**
|
|
150
156
|
* Creates a reactive proxy object (Vue-compatible).
|
|
151
|
-
*
|
|
157
|
+
* Intercepts array mutation methods to trigger reactive updates,
|
|
158
|
+
* since methods like push() bypass the Proxy 'set' trap.
|
|
152
159
|
*/
|
|
153
160
|
function reactive(target) {
|
|
154
|
-
|
|
161
|
+
// Return cached proxy if it already exists for this target
|
|
162
|
+
if (proxyCache.has(target)) {
|
|
163
|
+
return proxyCache.get(target);
|
|
164
|
+
}
|
|
165
|
+
const proxy = new Proxy(target, {
|
|
155
166
|
get(obj, prop, receiver) {
|
|
156
167
|
// IRON FORTRESS: Prototype Pollution Protection (Read)
|
|
157
168
|
if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') {
|
|
@@ -159,6 +170,17 @@ function reactive(target) {
|
|
|
159
170
|
}
|
|
160
171
|
track(obj, prop);
|
|
161
172
|
const val = Reflect.get(obj, prop, receiver);
|
|
173
|
+
// Intercept array mutation methods to trigger length + index updates
|
|
174
|
+
if (Array.isArray(obj) && typeof prop === 'string' && ARRAY_MUTATION_METHODS.includes(prop)) {
|
|
175
|
+
return function (...args) {
|
|
176
|
+
const result = val.apply(obj, args);
|
|
177
|
+
// Trigger on 'length' — this is what mu-for subscribes to
|
|
178
|
+
trigger(obj, 'length');
|
|
179
|
+
// Also trigger on the array itself for any parent effects
|
|
180
|
+
trigger(obj, prop);
|
|
181
|
+
return result;
|
|
182
|
+
};
|
|
183
|
+
}
|
|
162
184
|
if (val !== null && typeof val === 'object') {
|
|
163
185
|
return reactive(val);
|
|
164
186
|
}
|
|
@@ -172,9 +194,15 @@ function reactive(target) {
|
|
|
172
194
|
}
|
|
173
195
|
const result = Reflect.set(obj, prop, value, receiver);
|
|
174
196
|
trigger(obj, prop);
|
|
197
|
+
// If array length changed (e.g. index assignment), also trigger length
|
|
198
|
+
if (Array.isArray(obj) && prop !== 'length') {
|
|
199
|
+
trigger(obj, 'length');
|
|
200
|
+
}
|
|
175
201
|
return result;
|
|
176
202
|
},
|
|
177
203
|
});
|
|
204
|
+
proxyCache.set(target, proxy);
|
|
205
|
+
return proxy;
|
|
178
206
|
}
|
|
179
207
|
exports.reactive = reactive;
|
|
180
208
|
/**
|
package/dist/mulan.esm.js
CHANGED
|
@@ -242,12 +242,23 @@ function trigger(target, key) {
|
|
|
242
242
|
});
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
|
+
// Array mutating methods that must trigger reactive updates
|
|
246
|
+
const ARRAY_MUTATION_METHODS = ['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse', 'fill'];
|
|
247
|
+
// Proxy cache: ensures the same object always returns the same Proxy
|
|
248
|
+
// This is CRITICAL for array reactivity — mu-for and array mutations must
|
|
249
|
+
// share the same Proxy instance, otherwise triggers reach different subscribers.
|
|
250
|
+
const proxyCache = new WeakMap();
|
|
245
251
|
/**
|
|
246
252
|
* Creates a reactive proxy object (Vue-compatible).
|
|
247
|
-
*
|
|
253
|
+
* Intercepts array mutation methods to trigger reactive updates,
|
|
254
|
+
* since methods like push() bypass the Proxy 'set' trap.
|
|
248
255
|
*/
|
|
249
256
|
function reactive(target) {
|
|
250
|
-
|
|
257
|
+
// Return cached proxy if it already exists for this target
|
|
258
|
+
if (proxyCache.has(target)) {
|
|
259
|
+
return proxyCache.get(target);
|
|
260
|
+
}
|
|
261
|
+
const proxy = new Proxy(target, {
|
|
251
262
|
get(obj, prop, receiver) {
|
|
252
263
|
// IRON FORTRESS: Prototype Pollution Protection (Read)
|
|
253
264
|
if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') {
|
|
@@ -255,6 +266,17 @@ function reactive(target) {
|
|
|
255
266
|
}
|
|
256
267
|
track(obj, prop);
|
|
257
268
|
const val = Reflect.get(obj, prop, receiver);
|
|
269
|
+
// Intercept array mutation methods to trigger length + index updates
|
|
270
|
+
if (Array.isArray(obj) && typeof prop === 'string' && ARRAY_MUTATION_METHODS.includes(prop)) {
|
|
271
|
+
return function (...args) {
|
|
272
|
+
const result = val.apply(obj, args);
|
|
273
|
+
// Trigger on 'length' — this is what mu-for subscribes to
|
|
274
|
+
trigger(obj, 'length');
|
|
275
|
+
// Also trigger on the array itself for any parent effects
|
|
276
|
+
trigger(obj, prop);
|
|
277
|
+
return result;
|
|
278
|
+
};
|
|
279
|
+
}
|
|
258
280
|
if (val !== null && typeof val === 'object') {
|
|
259
281
|
return reactive(val);
|
|
260
282
|
}
|
|
@@ -268,9 +290,15 @@ function reactive(target) {
|
|
|
268
290
|
}
|
|
269
291
|
const result = Reflect.set(obj, prop, value, receiver);
|
|
270
292
|
trigger(obj, prop);
|
|
293
|
+
// If array length changed (e.g. index assignment), also trigger length
|
|
294
|
+
if (Array.isArray(obj) && prop !== 'length') {
|
|
295
|
+
trigger(obj, 'length');
|
|
296
|
+
}
|
|
271
297
|
return result;
|
|
272
298
|
},
|
|
273
299
|
});
|
|
300
|
+
proxyCache.set(target, proxy);
|
|
301
|
+
return proxy;
|
|
274
302
|
}
|
|
275
303
|
/**
|
|
276
304
|
* Creates a standalone reactive reference.
|