aoye 0.0.60 → 0.0.62

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/aoye.cjs.js CHANGED
@@ -939,7 +939,8 @@ const deepSignal = (target, scope, deep = true) => {
939
939
  const meta = {
940
940
  deep,
941
941
  scope,
942
- cells
942
+ cells,
943
+ backup: null
943
944
  };
944
945
  const shared = createSharedHandler(cells, scope, deep, targetIsMap);
945
946
  const specific = targetIsMap ? createMapHandler(cells, scope, deep) : createSetHandler(cells, scope);
@@ -971,7 +972,8 @@ const deepSignal = (target, scope, deep = true) => {
971
972
  const meta = {
972
973
  deep,
973
974
  scope,
974
- cells
975
+ cells,
976
+ backup: null
975
977
  };
976
978
  const proxy = new Proxy(target, {
977
979
  get(obj, prop, receiver) {
@@ -981,11 +983,18 @@ const deepSignal = (target, scope, deep = true) => {
981
983
  case Keys.Meta:
982
984
  return meta;
983
985
  }
986
+ const hasP = Reflect.has(obj, prop) || cells.has(prop);
987
+ if (!hasP) {
988
+ const backup = findValidBackup(receiver, prop);
989
+ if (backup) {
990
+ return backup[prop];
991
+ }
992
+ }
984
993
  if (prop === Symbol.unscopables) return Reflect.get(obj, prop, receiver);
985
994
  if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
986
995
  return Reflect.get(obj, prop, receiver);
987
996
  }
988
- const desc = Reflect.getOwnPropertyDescriptor(obj, prop);
997
+ const desc = bobeShared.getPropertyDescriptorInChain(obj, prop);
989
998
  const isGetter = desc && typeof desc.get === 'function';
990
999
  if (isGetter) {
991
1000
  return handleGetterAsComputed(obj, prop, receiver, cells, scope);
@@ -996,7 +1005,7 @@ const deepSignal = (target, scope, deep = true) => {
996
1005
  if (targetIsArray) {
997
1006
  return arrayMethodReWrites[prop] || value;
998
1007
  } else {
999
- if (!Object.prototype.hasOwnProperty.call(obj, prop)) {
1008
+ if (!bobeShared.hasOwn(obj, prop)) {
1000
1009
  return value;
1001
1010
  }
1002
1011
  let s = cells.get(prop);
@@ -1020,6 +1029,14 @@ const deepSignal = (target, scope, deep = true) => {
1020
1029
  return s.get();
1021
1030
  },
1022
1031
  set(obj, prop, value, receiver) {
1032
+ const hasP = Reflect.has(obj, prop) || cells.has(prop);
1033
+ if (!hasP) {
1034
+ const backup = findValidBackup(receiver, prop);
1035
+ if (backup) {
1036
+ backup[prop] = value;
1037
+ return true;
1038
+ }
1039
+ }
1023
1040
  if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
1024
1041
  return Reflect.set(obj, prop, value, receiver);
1025
1042
  }
@@ -1042,7 +1059,7 @@ const deepSignal = (target, scope, deep = true) => {
1042
1059
  if (targetIsStore && isIgnoreKey(obj.constructor[StoreIgnoreKeys], prop)) {
1043
1060
  return Reflect.deleteProperty(obj, prop);
1044
1061
  }
1045
- if (typeof obj[prop] === 'function' && !Object.prototype.hasOwnProperty.call(obj, prop)) {
1062
+ if (typeof obj[prop] === 'function' && !bobeShared.hasOwn(obj, prop)) {
1046
1063
  return Reflect.deleteProperty(obj, prop);
1047
1064
  }
1048
1065
  cells.delete(prop);
@@ -1064,6 +1081,21 @@ const deepSignal = (target, scope, deep = true) => {
1064
1081
  rawToProxy.set(target, proxy);
1065
1082
  return proxy;
1066
1083
  };
1084
+ const backupSignal = (child, parent) => {
1085
+ child[Keys.Meta].backup = parent;
1086
+ };
1087
+ const findValidBackup = (child, key) => {
1088
+ let backup = child[Keys.Meta].backup;
1089
+ while (backup) {
1090
+ if (proxyHasKey(backup, key)) {
1091
+ return backup;
1092
+ }
1093
+ backup = backup[Keys.Meta].backup;
1094
+ }
1095
+ return null;
1096
+ };
1097
+ const getProxyHasKey = (proxy, key) => proxyHasKey(proxy, key) ? proxy : findValidBackup(proxy, key);
1098
+ const proxyHasKey = (proxy, key) => Reflect.has(proxy[Keys.Raw], key) || proxy[Keys.Meta].cells.has(key);
1067
1099
  const shareSignal = (from, fromPath, to, toPath) => {
1068
1100
  try {
1069
1101
  const toPaths = toPath.split('.');
@@ -1354,8 +1386,8 @@ const GetMethodConf = {
1354
1386
  ...GetMethodConf
1355
1387
  }, {
1356
1388
  key: 'find',
1357
- wrapReturn: true,
1358
- ...GetMethodConf
1389
+ ...GetMethodConf,
1390
+ wrapReturn: true
1359
1391
  }, {
1360
1392
  key: 'findLast',
1361
1393
  ...GetMethodConf,
@@ -1619,6 +1651,7 @@ exports.Scope = Scope;
1619
1651
  exports.Signal = Signal;
1620
1652
  exports.Store = Store;
1621
1653
  exports.StoreIgnoreKeys = StoreIgnoreKeys;
1654
+ exports.backupSignal = backupSignal;
1622
1655
  exports.batchDeep = batchDeep;
1623
1656
  exports.batchEnd = batchEnd;
1624
1657
  exports.batchStart = batchStart;
@@ -1628,7 +1661,9 @@ exports.effect = effect;
1628
1661
  exports.effectUt = effectUt;
1629
1662
  exports.execId = execId;
1630
1663
  exports.execIdInc = execIdInc;
1664
+ exports.findValidBackup = findValidBackup;
1631
1665
  exports.flushMicroEffectManual = flushMicroEffectManual;
1666
+ exports.getProxyHasKey = getProxyHasKey;
1632
1667
  exports.getPulling = getPulling;
1633
1668
  exports.ide = ide;
1634
1669
  exports.isStore = isStore;
@@ -1636,6 +1671,7 @@ exports.macro = macro;
1636
1671
  exports.micro = micro;
1637
1672
  exports.noopEffect = noopEffect;
1638
1673
  exports.now = now;
1674
+ exports.proxyHasKey = proxyHasKey;
1639
1675
  exports.runWithPulling = runWithPulling;
1640
1676
  exports.scope = scope;
1641
1677
  exports.setExecId = setExecId;