@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.esm.js CHANGED
@@ -294,10 +294,16 @@ class Subscriber {
294
294
  if (!this.active || !using.has(key))
295
295
  return;
296
296
  const handler = using.get(key);
297
- if (typeof handler == "function")
298
- if (handler() !== true)
299
- return;
300
- const notify = this.onUpdate(key, parent);
297
+ let notify;
298
+ if (typeof handler == "function") {
299
+ const callback = handler();
300
+ if (typeof callback == "function")
301
+ notify = callback;
302
+ else if (callback === true)
303
+ notify = this.onUpdate(key, parent);
304
+ }
305
+ else
306
+ notify = this.onUpdate(key, parent);
301
307
  const getWhy = () => {
302
308
  const update = getUpdate(parent.subject);
303
309
  const applicable = update.filter(k => using.has(k));
@@ -932,10 +938,9 @@ function parent(Expects, required) {
932
938
 
933
939
  const ANY$1 = Symbol("any");
934
940
  function managedMap(control, property, initial) {
941
+ const managed = new ManagedMap(initial, emit);
935
942
  const context = new WeakMap();
936
943
  const lastUpdate = new Set();
937
- let managed;
938
- let value;
939
944
  function reset() {
940
945
  lastUpdate.clear();
941
946
  }
@@ -944,89 +949,103 @@ function managedMap(control, property, initial) {
944
949
  control.update(property);
945
950
  control.waiting.add(reset);
946
951
  }
947
- function setValue(next, initial) {
948
- value = next;
949
- managed = create(next);
952
+ function setValue(next) {
950
953
  control.state.set(property, next);
951
- if (!initial)
952
- emit(ANY$1);
953
- managed.set = (k, v) => {
954
- emit(k);
955
- return value.set(k, v);
956
- };
957
- managed.delete = (k) => {
958
- emit(k);
959
- return value.delete(k);
960
- };
961
- managed.clear = () => {
962
- emit(ANY$1);
963
- value.clear();
964
- };
954
+ managed.source = next;
955
+ emit(ANY$1);
965
956
  }
966
957
  function getValue(local) {
967
958
  if (!local)
968
959
  return managed;
969
960
  if (context.has(local))
970
961
  return context.get(local);
971
- const proxy = Object.create(managed);
962
+ const refresh = local.onUpdate(property, control);
963
+ const proxy = create(managed);
972
964
  const using = new Set();
973
- context.set(local, proxy);
974
- local.add(property, () => {
965
+ const update = () => {
975
966
  if (using.has(ANY$1) || lastUpdate.has(ANY$1) && using.size)
976
- return true;
977
- for (const key of lastUpdate)
978
- if (using.has(key))
979
- return true;
980
- });
981
- const watch = (key) => {
967
+ refresh();
968
+ else
969
+ for (const key of lastUpdate)
970
+ if (using.has(key)) {
971
+ refresh();
972
+ break;
973
+ }
974
+ };
975
+ local.add(property, () => update);
976
+ context.set(local, proxy);
977
+ proxy.watch = (key) => {
982
978
  if (!local.active)
983
979
  using.add(key);
984
980
  };
985
- proxy.get = (key) => {
986
- watch(key);
987
- return value.get(key);
988
- };
989
- proxy.has = (key) => {
990
- watch(key);
991
- return value.has(key);
992
- };
993
- proxy.values = () => {
994
- watch(ANY$1);
995
- return value.values();
996
- };
997
- proxy.keys = () => {
998
- watch(ANY$1);
999
- return value.keys();
1000
- };
1001
- proxy.entries = () => {
1002
- watch(ANY$1);
1003
- return value.entries();
1004
- };
1005
- proxy[Symbol.iterator] = () => {
1006
- watch(ANY$1);
1007
- return value[Symbol.iterator]();
1008
- };
1009
- defineProperty(proxy, "size", {
1010
- get() {
1011
- watch(ANY$1);
1012
- return value.size;
1013
- }
1014
- });
1015
981
  return proxy;
1016
982
  }
1017
- setValue(initial, true);
1018
983
  return {
984
+ value: initial,
1019
985
  set: setValue,
1020
986
  get: getValue
1021
987
  };
988
+ }
989
+ class ManagedMap {
990
+ constructor(source, emit) {
991
+ this.source = source;
992
+ this.emit = emit;
993
+ }
994
+ watch(_key) { }
995
+ set(key, value) {
996
+ this.source.set(key, value);
997
+ this.emit(key);
998
+ return this;
999
+ }
1000
+ ;
1001
+ delete(key) {
1002
+ this.emit(key);
1003
+ return this.source.delete(key);
1004
+ }
1005
+ ;
1006
+ clear() {
1007
+ this.emit(ANY$1);
1008
+ this.source.clear();
1009
+ }
1010
+ get(key) {
1011
+ this.watch(key);
1012
+ return this.source.get(key);
1013
+ }
1014
+ ;
1015
+ has(key) {
1016
+ this.watch(key);
1017
+ return this.source.has(key);
1018
+ }
1019
+ ;
1020
+ values() {
1021
+ this.watch(ANY$1);
1022
+ return this.source.values();
1023
+ }
1024
+ keys() {
1025
+ this.watch(ANY$1);
1026
+ return this.source.keys();
1027
+ }
1028
+ entries() {
1029
+ this.watch(ANY$1);
1030
+ return this.source.entries();
1031
+ }
1032
+ ;
1033
+ [Symbol.iterator]() {
1034
+ this.watch(ANY$1);
1035
+ return this.source[Symbol.iterator]();
1036
+ }
1037
+ ;
1038
+ get size() {
1039
+ this.watch(ANY$1);
1040
+ return this.source.size;
1041
+ }
1022
1042
  }
1023
1043
 
1024
1044
  const ANY = Symbol("any");
1025
1045
  function managedSet(control, property, initial) {
1046
+ const managed = new ManagedSet(initial, emit);
1026
1047
  const context = new WeakMap();
1027
1048
  const lastUpdate = new Set();
1028
- let managed;
1029
- let value;
1030
1049
  function reset() {
1031
1050
  lastUpdate.clear();
1032
1051
  }
@@ -1035,77 +1054,90 @@ function managedSet(control, property, initial) {
1035
1054
  control.update(property);
1036
1055
  control.waiting.add(reset);
1037
1056
  }
1038
- function setValue(next, initial) {
1039
- value = next;
1040
- managed = create(next);
1057
+ function setValue(next) {
1058
+ managed.source = next;
1041
1059
  control.state.set(property, next);
1042
- if (!initial)
1043
- emit(ANY);
1044
- managed.add = (k) => {
1045
- emit(k);
1046
- return value.add(k);
1047
- };
1048
- managed.delete = (k) => {
1049
- emit(k);
1050
- return value.delete(k);
1051
- };
1052
- managed.clear = () => {
1053
- emit(ANY);
1054
- value.clear();
1055
- };
1060
+ emit(ANY);
1056
1061
  }
1057
1062
  function getValue(local) {
1058
1063
  if (!local)
1059
1064
  return managed;
1060
1065
  if (context.has(local))
1061
1066
  return context.get(local);
1062
- const proxy = Object.create(managed);
1067
+ const refresh = local.onUpdate(property, control);
1068
+ const proxy = create(managed);
1063
1069
  const using = new Set();
1064
- context.set(local, proxy);
1065
- local.add(property, () => {
1070
+ const update = () => {
1066
1071
  if (using.has(ANY) || lastUpdate.has(ANY) && using.size)
1067
- return true;
1068
- for (const key of lastUpdate)
1069
- if (using.has(key))
1070
- return true;
1071
- });
1072
- const watch = (key) => {
1072
+ refresh();
1073
+ else
1074
+ for (const key of lastUpdate)
1075
+ if (using.has(key)) {
1076
+ refresh();
1077
+ break;
1078
+ }
1079
+ };
1080
+ local.add(property, () => update);
1081
+ context.set(local, proxy);
1082
+ proxy.watch = (key) => {
1073
1083
  if (!local.active)
1074
1084
  using.add(key);
1075
1085
  };
1076
- proxy.has = (key) => {
1077
- watch(key);
1078
- return value.has(key);
1079
- };
1080
- proxy.values = () => {
1081
- watch(ANY);
1082
- return value.values();
1083
- };
1084
- proxy.keys = () => {
1085
- watch(ANY);
1086
- return value.keys();
1087
- };
1088
- proxy.entries = () => {
1089
- watch(ANY);
1090
- return value.entries();
1091
- };
1092
- proxy[Symbol.iterator] = () => {
1093
- watch(ANY);
1094
- return value[Symbol.iterator]();
1095
- };
1096
- defineProperty(proxy, "size", {
1097
- get() {
1098
- watch(ANY);
1099
- return value.size;
1100
- }
1101
- });
1102
1086
  return proxy;
1103
1087
  }
1104
- setValue(initial, true);
1105
1088
  return {
1089
+ value: initial,
1106
1090
  set: setValue,
1107
1091
  get: getValue
1108
1092
  };
1093
+ }
1094
+ class ManagedSet {
1095
+ constructor(source, emit) {
1096
+ this.source = source;
1097
+ this.emit = emit;
1098
+ }
1099
+ watch(_key) { }
1100
+ add(key) {
1101
+ this.emit(key);
1102
+ return this.source.add(key);
1103
+ }
1104
+ ;
1105
+ delete(key) {
1106
+ this.emit(key);
1107
+ return this.source.delete(key);
1108
+ }
1109
+ ;
1110
+ clear() {
1111
+ this.emit(ANY);
1112
+ this.source.clear();
1113
+ }
1114
+ has(key) {
1115
+ this.watch(key);
1116
+ return this.source.has(key);
1117
+ }
1118
+ ;
1119
+ values() {
1120
+ this.watch(ANY);
1121
+ return this.source.values();
1122
+ }
1123
+ keys() {
1124
+ this.watch(ANY);
1125
+ return this.source.keys();
1126
+ }
1127
+ entries() {
1128
+ this.watch(ANY);
1129
+ return this.source.entries();
1130
+ }
1131
+ ;
1132
+ [Symbol.iterator]() {
1133
+ this.watch(ANY);
1134
+ return this.source[Symbol.iterator]();
1135
+ }
1136
+ ;
1137
+ get size() {
1138
+ this.watch(ANY);
1139
+ return this.source.size;
1140
+ }
1109
1141
  }
1110
1142
 
1111
1143
  const Oops$5 = issues({