@expressive/mvc 0.4.2 → 0.4.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/lib/index.js CHANGED
@@ -946,11 +946,9 @@ function parent(Expects, required) {
946
946
 
947
947
  const ANY$1 = Symbol("any");
948
948
  function managedMap(control, property, initial) {
949
- const lastUpdate = new Set();
949
+ const managed = new ManagedMap(initial, emit);
950
950
  const context = new WeakMap();
951
- const assoc = new WeakMap();
952
- let managed;
953
- let value;
951
+ const lastUpdate = new Set();
954
952
  function reset() {
955
953
  lastUpdate.clear();
956
954
  }
@@ -959,59 +957,10 @@ function managedMap(control, property, initial) {
959
957
  control.update(property);
960
958
  control.waiting.add(reset);
961
959
  }
962
- function setValue(next, initial) {
963
- value = next;
964
- managed = create(next);
960
+ function setValue(next) {
965
961
  control.state.set(property, next);
966
- if (!initial)
967
- emit(ANY$1);
968
- const watch = (key, on) => {
969
- const local = assoc.get(on);
970
- if (local)
971
- local(key);
972
- };
973
- managed.set = (k, v) => {
974
- emit(k);
975
- return value.set(k, v);
976
- };
977
- managed.delete = (k) => {
978
- emit(k);
979
- return value.delete(k);
980
- };
981
- managed.clear = () => {
982
- emit(ANY$1);
983
- value.clear();
984
- };
985
- managed.get = function (key) {
986
- watch(key, this);
987
- return value.get(key);
988
- };
989
- managed.has = function (key) {
990
- watch(key, this);
991
- return value.has(key);
992
- };
993
- managed.values = function () {
994
- watch(ANY$1, this);
995
- return value.values();
996
- };
997
- managed.keys = function () {
998
- watch(ANY$1, this);
999
- return value.keys();
1000
- };
1001
- managed.entries = function () {
1002
- watch(ANY$1, this);
1003
- return value.entries();
1004
- };
1005
- managed[Symbol.iterator] = function () {
1006
- watch(ANY$1, this);
1007
- return value[Symbol.iterator]();
1008
- };
1009
- defineProperty(managed, "size", {
1010
- get() {
1011
- watch(ANY$1, this);
1012
- return value.size;
1013
- }
1014
- });
962
+ managed.source = next;
963
+ emit(ANY$1);
1015
964
  }
1016
965
  function getValue(local) {
1017
966
  if (!local)
@@ -1019,7 +968,7 @@ function managedMap(control, property, initial) {
1019
968
  if (context.has(local))
1020
969
  return context.get(local);
1021
970
  const refresh = local.onUpdate(property, control);
1022
- const proxy = Object.create(managed);
971
+ const proxy = create(managed);
1023
972
  const using = new Set();
1024
973
  const update = () => {
1025
974
  if (using.has(ANY$1) || lastUpdate.has(ANY$1) && using.size)
@@ -1031,28 +980,80 @@ function managedMap(control, property, initial) {
1031
980
  break;
1032
981
  }
1033
982
  };
983
+ local.add(property, () => update);
1034
984
  context.set(local, proxy);
1035
- assoc.set(proxy, (key) => {
985
+ proxy.watch = (key) => {
1036
986
  if (!local.active)
1037
987
  using.add(key);
1038
- });
1039
- local.add(property, () => update);
988
+ };
1040
989
  return proxy;
1041
990
  }
1042
- setValue(initial, true);
1043
991
  return {
992
+ value: initial,
1044
993
  set: setValue,
1045
994
  get: getValue
1046
995
  };
996
+ }
997
+ class ManagedMap {
998
+ constructor(source, emit) {
999
+ this.source = source;
1000
+ this.emit = emit;
1001
+ }
1002
+ watch(_key) { }
1003
+ set(key, value) {
1004
+ this.source.set(key, value);
1005
+ this.emit(key);
1006
+ return this;
1007
+ }
1008
+ ;
1009
+ delete(key) {
1010
+ this.emit(key);
1011
+ return this.source.delete(key);
1012
+ }
1013
+ ;
1014
+ clear() {
1015
+ this.emit(ANY$1);
1016
+ this.source.clear();
1017
+ }
1018
+ get(key) {
1019
+ this.watch(key);
1020
+ return this.source.get(key);
1021
+ }
1022
+ ;
1023
+ has(key) {
1024
+ this.watch(key);
1025
+ return this.source.has(key);
1026
+ }
1027
+ ;
1028
+ values() {
1029
+ this.watch(ANY$1);
1030
+ return this.source.values();
1031
+ }
1032
+ keys() {
1033
+ this.watch(ANY$1);
1034
+ return this.source.keys();
1035
+ }
1036
+ entries() {
1037
+ this.watch(ANY$1);
1038
+ return this.source.entries();
1039
+ }
1040
+ ;
1041
+ [Symbol.iterator]() {
1042
+ this.watch(ANY$1);
1043
+ return this.source[Symbol.iterator]();
1044
+ }
1045
+ ;
1046
+ get size() {
1047
+ this.watch(ANY$1);
1048
+ return this.source.size;
1049
+ }
1047
1050
  }
1048
1051
 
1049
1052
  const ANY = Symbol("any");
1050
1053
  function managedSet(control, property, initial) {
1051
- const lastUpdate = new Set();
1054
+ const managed = new ManagedSet(initial, emit);
1052
1055
  const context = new WeakMap();
1053
- const assoc = new WeakMap();
1054
- let managed;
1055
- let value;
1056
+ const lastUpdate = new Set();
1056
1057
  function reset() {
1057
1058
  lastUpdate.clear();
1058
1059
  }
@@ -1061,55 +1062,10 @@ function managedSet(control, property, initial) {
1061
1062
  control.update(property);
1062
1063
  control.waiting.add(reset);
1063
1064
  }
1064
- function setValue(next, initial) {
1065
- value = next;
1066
- managed = create(next);
1065
+ function setValue(next) {
1066
+ managed.source = next;
1067
1067
  control.state.set(property, next);
1068
- if (!initial)
1069
- emit(ANY);
1070
- const watch = (key, on) => {
1071
- const local = assoc.get(on);
1072
- if (local)
1073
- local(key);
1074
- };
1075
- managed.add = (k) => {
1076
- emit(k);
1077
- return value.add(k);
1078
- };
1079
- managed.delete = (k) => {
1080
- emit(k);
1081
- return value.delete(k);
1082
- };
1083
- managed.clear = () => {
1084
- emit(ANY);
1085
- value.clear();
1086
- };
1087
- managed.has = function (key) {
1088
- watch(key, this);
1089
- return value.has(key);
1090
- };
1091
- managed.values = function () {
1092
- watch(ANY, this);
1093
- return value.values();
1094
- };
1095
- managed.keys = function () {
1096
- watch(ANY, this);
1097
- return value.keys();
1098
- };
1099
- managed.entries = function () {
1100
- watch(ANY, this);
1101
- return value.entries();
1102
- };
1103
- managed[Symbol.iterator] = function () {
1104
- watch(ANY, this);
1105
- return value[Symbol.iterator]();
1106
- };
1107
- defineProperty(managed, "size", {
1108
- get() {
1109
- watch(ANY, this);
1110
- return value.size;
1111
- }
1112
- });
1068
+ emit(ANY);
1113
1069
  }
1114
1070
  function getValue(local) {
1115
1071
  if (!local)
@@ -1117,7 +1073,7 @@ function managedSet(control, property, initial) {
1117
1073
  if (context.has(local))
1118
1074
  return context.get(local);
1119
1075
  const refresh = local.onUpdate(property, control);
1120
- const proxy = Object.create(managed);
1076
+ const proxy = create(managed);
1121
1077
  const using = new Set();
1122
1078
  const update = () => {
1123
1079
  if (using.has(ANY) || lastUpdate.has(ANY) && using.size)
@@ -1129,19 +1085,67 @@ function managedSet(control, property, initial) {
1129
1085
  break;
1130
1086
  }
1131
1087
  };
1088
+ local.add(property, () => update);
1132
1089
  context.set(local, proxy);
1133
- assoc.set(proxy, (key) => {
1090
+ proxy.watch = (key) => {
1134
1091
  if (!local.active)
1135
1092
  using.add(key);
1136
- });
1137
- local.add(property, () => update);
1093
+ };
1138
1094
  return proxy;
1139
1095
  }
1140
- setValue(initial, true);
1141
1096
  return {
1097
+ value: initial,
1142
1098
  set: setValue,
1143
1099
  get: getValue
1144
1100
  };
1101
+ }
1102
+ class ManagedSet {
1103
+ constructor(source, emit) {
1104
+ this.source = source;
1105
+ this.emit = emit;
1106
+ }
1107
+ watch(_key) { }
1108
+ add(key) {
1109
+ this.emit(key);
1110
+ return this.source.add(key);
1111
+ }
1112
+ ;
1113
+ delete(key) {
1114
+ this.emit(key);
1115
+ return this.source.delete(key);
1116
+ }
1117
+ ;
1118
+ clear() {
1119
+ this.emit(ANY);
1120
+ this.source.clear();
1121
+ }
1122
+ has(key) {
1123
+ this.watch(key);
1124
+ return this.source.has(key);
1125
+ }
1126
+ ;
1127
+ values() {
1128
+ this.watch(ANY);
1129
+ return this.source.values();
1130
+ }
1131
+ keys() {
1132
+ this.watch(ANY);
1133
+ return this.source.keys();
1134
+ }
1135
+ entries() {
1136
+ this.watch(ANY);
1137
+ return this.source.entries();
1138
+ }
1139
+ ;
1140
+ [Symbol.iterator]() {
1141
+ this.watch(ANY);
1142
+ return this.source[Symbol.iterator]();
1143
+ }
1144
+ ;
1145
+ get size() {
1146
+ this.watch(ANY);
1147
+ return this.source.size;
1148
+ }
1145
1149
  }
1146
1150
 
1147
1151
  const Oops$5 = issues({