@mintjamsinc/ichigojs 0.1.52 → 0.1.54

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/ichigo.cjs CHANGED
@@ -7891,7 +7891,7 @@
7891
7891
  }
7892
7892
  // Create the proxy with path captured in closure
7893
7893
  const proxy = new Proxy(target, {
7894
- get(obj, key) {
7894
+ get(obj, key, receiver) {
7895
7895
  const value = Reflect.get(obj, key);
7896
7896
  // If the value is an object or array, make it reactive too
7897
7897
  if (typeof value === 'object' && value !== null) {
@@ -7910,16 +7910,42 @@
7910
7910
  const nestedPath = path ? (Array.isArray(obj) ? `${path}[${keyStr}]` : `${path}.${keyStr}`) : keyStr;
7911
7911
  return ReactiveProxy.create(value, onChange, nestedPath);
7912
7912
  }
7913
- // For arrays, intercept mutation methods
7914
- if (Array.isArray(obj) && typeof value === 'function') {
7915
- const arrayMutationMethods = ['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse'];
7916
- if (arrayMutationMethods.includes(key)) {
7913
+ // If the value is a function, we need to wrap it to ensure that any mutations it performs also trigger onChange
7914
+ if (typeof value === 'function') {
7915
+ // For arrays, we only want to wrap mutation methods, not read methods like 'slice', 'concat', etc.
7916
+ if (Array.isArray(obj)) {
7917
+ const arrayMutationMethods = ['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse'];
7918
+ if (!arrayMutationMethods.includes(key)) {
7919
+ return value;
7920
+ }
7917
7921
  return function (...args) {
7918
- const result = value.apply(obj, args);
7922
+ const result = value.apply(this === receiver ? obj : this, args);
7919
7923
  onChange(path || undefined);
7920
7924
  return result;
7921
7925
  };
7922
7926
  }
7927
+ // For Map, we only want to wrap mutation methods, not read methods like 'get' or 'has'
7928
+ if (obj.constructor.name === 'Map') {
7929
+ const mapMutationMethods = ['set', 'delete', 'clear'];
7930
+ return function (...args) {
7931
+ const result = value.apply(this === receiver ? obj : this, args);
7932
+ if (mapMutationMethods.includes(key)) {
7933
+ onChange(path || undefined);
7934
+ }
7935
+ return result;
7936
+ };
7937
+ }
7938
+ // For Set, we only want to wrap mutation methods, not read methods like 'has'
7939
+ if (obj.constructor.name === 'Set') {
7940
+ const setMutationMethods = ['add', 'delete', 'clear'];
7941
+ return function (...args) {
7942
+ const result = value.apply(this === receiver ? obj : this, args);
7943
+ if (setMutationMethods.includes(key)) {
7944
+ onChange(path || undefined);
7945
+ }
7946
+ return result;
7947
+ };
7948
+ }
7923
7949
  }
7924
7950
  return value;
7925
7951
  },