@expressive/mvc 0.4.0 → 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
@@ -302,10 +302,16 @@ class Subscriber {
302
302
  if (!this.active || !using.has(key))
303
303
  return;
304
304
  const handler = using.get(key);
305
- if (typeof handler == "function")
306
- if (handler() !== true)
307
- return;
308
- const notify = this.onUpdate(key, parent);
305
+ let notify;
306
+ if (typeof handler == "function") {
307
+ const callback = handler();
308
+ if (typeof callback == "function")
309
+ notify = callback;
310
+ else if (callback === true)
311
+ notify = this.onUpdate(key, parent);
312
+ }
313
+ else
314
+ notify = this.onUpdate(key, parent);
309
315
  const getWhy = () => {
310
316
  const update = getUpdate(parent.subject);
311
317
  const applicable = update.filter(k => using.has(k));
@@ -940,10 +946,9 @@ function parent(Expects, required) {
940
946
 
941
947
  const ANY$1 = Symbol("any");
942
948
  function managedMap(control, property, initial) {
949
+ const managed = new ManagedMap(initial, emit);
943
950
  const context = new WeakMap();
944
951
  const lastUpdate = new Set();
945
- let managed;
946
- let value;
947
952
  function reset() {
948
953
  lastUpdate.clear();
949
954
  }
@@ -952,89 +957,103 @@ function managedMap(control, property, initial) {
952
957
  control.update(property);
953
958
  control.waiting.add(reset);
954
959
  }
955
- function setValue(next, initial) {
956
- value = next;
957
- managed = create(next);
960
+ function setValue(next) {
958
961
  control.state.set(property, next);
959
- if (!initial)
960
- emit(ANY$1);
961
- managed.set = (k, v) => {
962
- emit(k);
963
- return value.set(k, v);
964
- };
965
- managed.delete = (k) => {
966
- emit(k);
967
- return value.delete(k);
968
- };
969
- managed.clear = () => {
970
- emit(ANY$1);
971
- value.clear();
972
- };
962
+ managed.source = next;
963
+ emit(ANY$1);
973
964
  }
974
965
  function getValue(local) {
975
966
  if (!local)
976
967
  return managed;
977
968
  if (context.has(local))
978
969
  return context.get(local);
979
- const proxy = Object.create(managed);
970
+ const refresh = local.onUpdate(property, control);
971
+ const proxy = create(managed);
980
972
  const using = new Set();
981
- context.set(local, proxy);
982
- local.add(property, () => {
973
+ const update = () => {
983
974
  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) => {
975
+ refresh();
976
+ else
977
+ for (const key of lastUpdate)
978
+ if (using.has(key)) {
979
+ refresh();
980
+ break;
981
+ }
982
+ };
983
+ local.add(property, () => update);
984
+ context.set(local, proxy);
985
+ proxy.watch = (key) => {
990
986
  if (!local.active)
991
987
  using.add(key);
992
988
  };
993
- proxy.get = (key) => {
994
- watch(key);
995
- return value.get(key);
996
- };
997
- proxy.has = (key) => {
998
- watch(key);
999
- return value.has(key);
1000
- };
1001
- proxy.values = () => {
1002
- watch(ANY$1);
1003
- return value.values();
1004
- };
1005
- proxy.keys = () => {
1006
- watch(ANY$1);
1007
- return value.keys();
1008
- };
1009
- proxy.entries = () => {
1010
- watch(ANY$1);
1011
- return value.entries();
1012
- };
1013
- proxy[Symbol.iterator] = () => {
1014
- watch(ANY$1);
1015
- return value[Symbol.iterator]();
1016
- };
1017
- defineProperty(proxy, "size", {
1018
- get() {
1019
- watch(ANY$1);
1020
- return value.size;
1021
- }
1022
- });
1023
989
  return proxy;
1024
990
  }
1025
- setValue(initial, true);
1026
991
  return {
992
+ value: initial,
1027
993
  set: setValue,
1028
994
  get: getValue
1029
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
+ }
1030
1050
  }
1031
1051
 
1032
1052
  const ANY = Symbol("any");
1033
1053
  function managedSet(control, property, initial) {
1054
+ const managed = new ManagedSet(initial, emit);
1034
1055
  const context = new WeakMap();
1035
1056
  const lastUpdate = new Set();
1036
- let managed;
1037
- let value;
1038
1057
  function reset() {
1039
1058
  lastUpdate.clear();
1040
1059
  }
@@ -1043,77 +1062,90 @@ function managedSet(control, property, initial) {
1043
1062
  control.update(property);
1044
1063
  control.waiting.add(reset);
1045
1064
  }
1046
- function setValue(next, initial) {
1047
- value = next;
1048
- managed = create(next);
1065
+ function setValue(next) {
1066
+ managed.source = next;
1049
1067
  control.state.set(property, next);
1050
- if (!initial)
1051
- emit(ANY);
1052
- managed.add = (k) => {
1053
- emit(k);
1054
- return value.add(k);
1055
- };
1056
- managed.delete = (k) => {
1057
- emit(k);
1058
- return value.delete(k);
1059
- };
1060
- managed.clear = () => {
1061
- emit(ANY);
1062
- value.clear();
1063
- };
1068
+ emit(ANY);
1064
1069
  }
1065
1070
  function getValue(local) {
1066
1071
  if (!local)
1067
1072
  return managed;
1068
1073
  if (context.has(local))
1069
1074
  return context.get(local);
1070
- const proxy = Object.create(managed);
1075
+ const refresh = local.onUpdate(property, control);
1076
+ const proxy = create(managed);
1071
1077
  const using = new Set();
1072
- context.set(local, proxy);
1073
- local.add(property, () => {
1078
+ const update = () => {
1074
1079
  if (using.has(ANY) || lastUpdate.has(ANY) && using.size)
1075
- return true;
1076
- for (const key of lastUpdate)
1077
- if (using.has(key))
1078
- return true;
1079
- });
1080
- const watch = (key) => {
1080
+ refresh();
1081
+ else
1082
+ for (const key of lastUpdate)
1083
+ if (using.has(key)) {
1084
+ refresh();
1085
+ break;
1086
+ }
1087
+ };
1088
+ local.add(property, () => update);
1089
+ context.set(local, proxy);
1090
+ proxy.watch = (key) => {
1081
1091
  if (!local.active)
1082
1092
  using.add(key);
1083
1093
  };
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
1094
  return proxy;
1111
1095
  }
1112
- setValue(initial, true);
1113
1096
  return {
1097
+ value: initial,
1114
1098
  set: setValue,
1115
1099
  get: getValue
1116
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
+ }
1117
1149
  }
1118
1150
 
1119
1151
  const Oops$5 = issues({