@expressive/mvc 0.4.0 → 0.4.1

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/lib/index.js CHANGED
@@ -940,8 +940,9 @@ function parent(Expects, required) {
940
940
 
941
941
  const ANY$1 = Symbol("any");
942
942
  function managedMap(control, property, initial) {
943
- const context = new WeakMap();
944
943
  const lastUpdate = new Set();
944
+ const context = new WeakMap();
945
+ const assoc = new WeakMap();
945
946
  let managed;
946
947
  let value;
947
948
  function reset() {
@@ -958,6 +959,11 @@ function managedMap(control, property, initial) {
958
959
  control.state.set(property, next);
959
960
  if (!initial)
960
961
  emit(ANY$1);
962
+ const watch = (key, on) => {
963
+ const local = assoc.get(on);
964
+ if (local)
965
+ local(key);
966
+ };
961
967
  managed.set = (k, v) => {
962
968
  emit(k);
963
969
  return value.set(k, v);
@@ -970,56 +976,56 @@ function managedMap(control, property, initial) {
970
976
  emit(ANY$1);
971
977
  value.clear();
972
978
  };
973
- }
974
- function getValue(local) {
975
- if (!local)
976
- return managed;
977
- if (context.has(local))
978
- return context.get(local);
979
- const proxy = Object.create(managed);
980
- const using = new Set();
981
- context.set(local, proxy);
982
- local.add(property, () => {
983
- if (using.has(ANY$1) || lastUpdate.has(ANY$1) && using.size)
984
- return true;
985
- for (const key of lastUpdate)
986
- if (using.has(key))
987
- return true;
988
- });
989
- const watch = (key) => {
990
- if (!local.active)
991
- using.add(key);
992
- };
993
- proxy.get = (key) => {
994
- watch(key);
979
+ managed.get = function (key) {
980
+ watch(key, this);
995
981
  return value.get(key);
996
982
  };
997
- proxy.has = (key) => {
998
- watch(key);
983
+ managed.has = function (key) {
984
+ watch(key, this);
999
985
  return value.has(key);
1000
986
  };
1001
- proxy.values = () => {
1002
- watch(ANY$1);
987
+ managed.values = function () {
988
+ watch(ANY$1, this);
1003
989
  return value.values();
1004
990
  };
1005
- proxy.keys = () => {
1006
- watch(ANY$1);
991
+ managed.keys = function () {
992
+ watch(ANY$1, this);
1007
993
  return value.keys();
1008
994
  };
1009
- proxy.entries = () => {
1010
- watch(ANY$1);
995
+ managed.entries = function () {
996
+ watch(ANY$1, this);
1011
997
  return value.entries();
1012
998
  };
1013
- proxy[Symbol.iterator] = () => {
1014
- watch(ANY$1);
999
+ managed[Symbol.iterator] = function () {
1000
+ watch(ANY$1, this);
1015
1001
  return value[Symbol.iterator]();
1016
1002
  };
1017
- defineProperty(proxy, "size", {
1003
+ defineProperty(managed, "size", {
1018
1004
  get() {
1019
- watch(ANY$1);
1005
+ watch(ANY$1, this);
1020
1006
  return value.size;
1021
1007
  }
1022
1008
  });
1009
+ }
1010
+ function getValue(local) {
1011
+ if (!local)
1012
+ return managed;
1013
+ if (context.has(local))
1014
+ return context.get(local);
1015
+ const proxy = Object.create(managed);
1016
+ const using = new Set();
1017
+ context.set(local, proxy);
1018
+ assoc.set(proxy, (key) => {
1019
+ if (!local.active)
1020
+ using.add(key);
1021
+ });
1022
+ local.add(property, () => {
1023
+ if (using.has(ANY$1) || lastUpdate.has(ANY$1) && using.size)
1024
+ return true;
1025
+ for (const key of lastUpdate)
1026
+ if (using.has(key))
1027
+ return true;
1028
+ });
1023
1029
  return proxy;
1024
1030
  }
1025
1031
  setValue(initial, true);
@@ -1031,8 +1037,9 @@ function managedMap(control, property, initial) {
1031
1037
 
1032
1038
  const ANY = Symbol("any");
1033
1039
  function managedSet(control, property, initial) {
1034
- const context = new WeakMap();
1035
1040
  const lastUpdate = new Set();
1041
+ const context = new WeakMap();
1042
+ const assoc = new WeakMap();
1036
1043
  let managed;
1037
1044
  let value;
1038
1045
  function reset() {
@@ -1049,6 +1056,11 @@ function managedSet(control, property, initial) {
1049
1056
  control.state.set(property, next);
1050
1057
  if (!initial)
1051
1058
  emit(ANY);
1059
+ const watch = (key, on) => {
1060
+ const local = assoc.get(on);
1061
+ if (local)
1062
+ local(key);
1063
+ };
1052
1064
  managed.add = (k) => {
1053
1065
  emit(k);
1054
1066
  return value.add(k);
@@ -1061,6 +1073,32 @@ function managedSet(control, property, initial) {
1061
1073
  emit(ANY);
1062
1074
  value.clear();
1063
1075
  };
1076
+ managed.has = function (key) {
1077
+ watch(key, this);
1078
+ return value.has(key);
1079
+ };
1080
+ managed.values = function () {
1081
+ watch(ANY, this);
1082
+ return value.values();
1083
+ };
1084
+ managed.keys = function () {
1085
+ watch(ANY, this);
1086
+ return value.keys();
1087
+ };
1088
+ managed.entries = function () {
1089
+ watch(ANY, this);
1090
+ return value.entries();
1091
+ };
1092
+ managed[Symbol.iterator] = function () {
1093
+ watch(ANY, this);
1094
+ return value[Symbol.iterator]();
1095
+ };
1096
+ defineProperty(managed, "size", {
1097
+ get() {
1098
+ watch(ANY, this);
1099
+ return value.size;
1100
+ }
1101
+ });
1064
1102
  }
1065
1103
  function getValue(local) {
1066
1104
  if (!local)
@@ -1070,6 +1108,10 @@ function managedSet(control, property, initial) {
1070
1108
  const proxy = Object.create(managed);
1071
1109
  const using = new Set();
1072
1110
  context.set(local, proxy);
1111
+ assoc.set(proxy, (key) => {
1112
+ if (!local.active)
1113
+ using.add(key);
1114
+ });
1073
1115
  local.add(property, () => {
1074
1116
  if (using.has(ANY) || lastUpdate.has(ANY) && using.size)
1075
1117
  return true;
@@ -1077,36 +1119,6 @@ function managedSet(control, property, initial) {
1077
1119
  if (using.has(key))
1078
1120
  return true;
1079
1121
  });
1080
- const watch = (key) => {
1081
- if (!local.active)
1082
- using.add(key);
1083
- };
1084
- proxy.has = (key) => {
1085
- watch(key);
1086
- return value.has(key);
1087
- };
1088
- proxy.values = () => {
1089
- watch(ANY);
1090
- return value.values();
1091
- };
1092
- proxy.keys = () => {
1093
- watch(ANY);
1094
- return value.keys();
1095
- };
1096
- proxy.entries = () => {
1097
- watch(ANY);
1098
- return value.entries();
1099
- };
1100
- proxy[Symbol.iterator] = () => {
1101
- watch(ANY);
1102
- return value[Symbol.iterator]();
1103
- };
1104
- defineProperty(proxy, "size", {
1105
- get() {
1106
- watch(ANY);
1107
- return value.size;
1108
- }
1109
- });
1110
1122
  return proxy;
1111
1123
  }
1112
1124
  setValue(initial, true);