mobx-vue-bridge 1.0.2 → 1.0.3
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/mobxVueBridge.js +24 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-vue-bridge",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "A bridge between MobX observables and Vue 3 reactivity system, enabling seamless two-way data binding and state synchronization.",
|
|
5
5
|
"main": "src/mobxVueBridge.js",
|
|
6
6
|
"module": "src/mobxVueBridge.js",
|
package/src/mobxVueBridge.js
CHANGED
|
@@ -182,11 +182,22 @@ export function useMobxBridge(mobxObject, options = {}) {
|
|
|
182
182
|
return result;
|
|
183
183
|
},
|
|
184
184
|
set: (target, key, val) => {
|
|
185
|
+
// Check if direct mutation is allowed
|
|
186
|
+
if (!allowDirectMutation) {
|
|
187
|
+
warnDirectMutation(`${prop}.${String(key)}`);
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
|
|
185
191
|
target[key] = val;
|
|
186
192
|
// Update the Vue ref to trigger reactivity
|
|
187
193
|
propertyRefs[prop].value = clone(propertyRefs[prop].value);
|
|
188
194
|
// Update MobX immediately
|
|
189
|
-
|
|
195
|
+
updatingFromVue.add(prop);
|
|
196
|
+
try {
|
|
197
|
+
mobxObject[prop] = clone(propertyRefs[prop].value);
|
|
198
|
+
} finally {
|
|
199
|
+
updatingFromVue.delete(prop);
|
|
200
|
+
}
|
|
190
201
|
return true;
|
|
191
202
|
}
|
|
192
203
|
});
|
|
@@ -216,7 +227,12 @@ export function useMobxBridge(mobxObject, options = {}) {
|
|
|
216
227
|
}
|
|
217
228
|
// ALSO update MobX immediately (synchronous)
|
|
218
229
|
if (!isEqual(mobxObject[prop], cloned)) {
|
|
219
|
-
|
|
230
|
+
updatingFromVue.add(prop);
|
|
231
|
+
try {
|
|
232
|
+
mobxObject[prop] = cloned;
|
|
233
|
+
} finally {
|
|
234
|
+
updatingFromVue.delete(prop);
|
|
235
|
+
}
|
|
220
236
|
}
|
|
221
237
|
}
|
|
222
238
|
: () => warnDirectMutation(prop),
|
|
@@ -254,11 +270,14 @@ export function useMobxBridge(mobxObject, options = {}) {
|
|
|
254
270
|
// Update both refs
|
|
255
271
|
setterRefs[prop].value = value;
|
|
256
272
|
// Call the MobX setter immediately
|
|
273
|
+
updatingFromVue.add(prop);
|
|
257
274
|
try {
|
|
258
275
|
mobxObject[prop] = value;
|
|
259
276
|
// The getter ref will be updated by the reaction
|
|
260
277
|
} catch (error) {
|
|
261
278
|
console.warn(`Failed to set property '${prop}':`, error);
|
|
279
|
+
} finally {
|
|
280
|
+
updatingFromVue.delete(prop);
|
|
262
281
|
}
|
|
263
282
|
}
|
|
264
283
|
: () => warnDirectMutation(prop),
|
|
@@ -303,10 +322,13 @@ export function useMobxBridge(mobxObject, options = {}) {
|
|
|
303
322
|
setterRefs[prop].value = value;
|
|
304
323
|
|
|
305
324
|
// Call the MobX setter immediately
|
|
325
|
+
updatingFromVue.add(prop);
|
|
306
326
|
try {
|
|
307
327
|
mobxObject[prop] = value;
|
|
308
328
|
} catch (error) {
|
|
309
329
|
console.warn(`Failed to set property '${prop}':`, error);
|
|
330
|
+
} finally {
|
|
331
|
+
updatingFromVue.delete(prop);
|
|
310
332
|
}
|
|
311
333
|
}
|
|
312
334
|
: () => warnSetterMutation(prop),
|