@expressive/mvc 0.4.6 → 0.4.7

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,129 +946,133 @@ function parent(Expects, required) {
946
946
 
947
947
  const ANY = Symbol("any");
948
948
  function keyed(control, property, initial) {
949
- const managed = new Stateful(initial, emit);
950
- const context = new WeakMap();
951
- const observers = new Set();
949
+ const context = new Map();
950
+ const users = new Map();
951
+ const watched = new WeakMap();
952
+ const update = new Set();
952
953
  const frozen = new Set();
954
+ let managed;
955
+ manage(initial);
953
956
  function reset() {
954
957
  frozen.clear();
955
958
  }
959
+ function watch(on, key) {
960
+ const include = watched.get(on);
961
+ if (include)
962
+ include.add(key);
963
+ }
956
964
  function emit(key) {
957
965
  control.waiting.add(reset);
958
966
  control.update(property);
959
- observers.forEach(notify => notify(key));
967
+ update.forEach(notify => notify(key));
968
+ }
969
+ function manage(current) {
970
+ managed = create(current);
971
+ context.clear();
972
+ assign(managed, {
973
+ delete(key) {
974
+ emit(key);
975
+ return current.delete(key);
976
+ },
977
+ clear() {
978
+ emit(ANY);
979
+ current.clear();
980
+ },
981
+ has(key) {
982
+ watch(this, key);
983
+ return current.has(key);
984
+ },
985
+ keys() {
986
+ watch(this, ANY);
987
+ return current.keys();
988
+ },
989
+ values() {
990
+ watch(this, ANY);
991
+ return current.values();
992
+ },
993
+ entries() {
994
+ watch(this, ANY);
995
+ return current.entries();
996
+ },
997
+ [Symbol.iterator]() {
998
+ watch(this, ANY);
999
+ return current[Symbol.iterator]();
1000
+ },
1001
+ }, current instanceof Set
1002
+ ? {
1003
+ add(key) {
1004
+ current.add(key);
1005
+ emit(key);
1006
+ return this;
1007
+ }
1008
+ }
1009
+ : {
1010
+ get(key) {
1011
+ watch(this, ANY);
1012
+ return current.get(key);
1013
+ },
1014
+ set(key, value) {
1015
+ current.set(key, value);
1016
+ emit(key);
1017
+ return this;
1018
+ }
1019
+ });
1020
+ defineProperty(managed, "size", {
1021
+ get() {
1022
+ watch(this, ANY);
1023
+ return current.size;
1024
+ }
1025
+ });
960
1026
  }
961
- function init(local) {
1027
+ function subscribe(local) {
962
1028
  const proxy = create(managed);
963
- const using = new Set();
964
- function onEvent(key) {
965
- if (frozen.has(local))
966
- return;
967
- if (key === ANY || using.has(key) || using.has(ANY)) {
968
- const refresh = local.onUpdate(property, control);
969
- if (refresh) {
970
- frozen.add(local);
971
- refresh();
1029
+ let watch = users.get(local);
1030
+ if (!watch) {
1031
+ const using = watch = new Set();
1032
+ users.set(local, using);
1033
+ function onEvent(key) {
1034
+ if (frozen.has(local))
1035
+ return;
1036
+ if (key === ANY || using.has(key) || using.has(ANY)) {
1037
+ const refresh = local.onUpdate(property, control);
1038
+ if (refresh) {
1039
+ frozen.add(local);
1040
+ refresh();
1041
+ }
972
1042
  }
973
1043
  }
1044
+ local.add(property, false);
1045
+ local.dependant.add({
1046
+ commit() {
1047
+ if (using.size === 0)
1048
+ using.add(ANY);
1049
+ update.add(onEvent);
1050
+ },
1051
+ release() {
1052
+ update.delete(onEvent);
1053
+ }
1054
+ });
974
1055
  }
1056
+ watched.set(proxy, watch);
975
1057
  context.set(local, proxy);
976
- proxy.watch = (key) => {
977
- if (!local.active)
978
- using.add(key);
979
- };
980
- local.add(property, false);
981
- local.dependant.add({
982
- commit() {
983
- if (using.size === 0)
984
- using.add(ANY);
985
- observers.add(onEvent);
986
- },
987
- release() {
988
- observers.delete(onEvent);
989
- }
990
- });
991
1058
  return proxy;
992
1059
  }
993
1060
  return {
994
1061
  value: initial,
995
1062
  get(local) {
996
1063
  return local ?
997
- context.get(local) || init(local) :
1064
+ context.get(local) || subscribe(local) :
998
1065
  managed;
999
1066
  },
1000
1067
  set(next) {
1001
- managed.source = next;
1002
1068
  control.state.set(property, next);
1069
+ manage(next);
1003
1070
  emit(ANY);
1004
1071
  },
1005
1072
  destroy() {
1006
- observers.clear();
1073
+ update.clear();
1007
1074
  }
1008
1075
  };
1009
- }
1010
- class Stateful {
1011
- constructor(source, emit) {
1012
- this.source = source;
1013
- this.emit = emit;
1014
- if (source instanceof Set)
1015
- assign(this, {
1016
- add(key) {
1017
- source.add(key);
1018
- emit(key);
1019
- return this;
1020
- }
1021
- });
1022
- else
1023
- assign(this, {
1024
- get(key) {
1025
- this.watch(key);
1026
- return source.get(key);
1027
- },
1028
- set(key, value) {
1029
- source.set(key, value);
1030
- emit(key);
1031
- return this;
1032
- }
1033
- });
1034
- }
1035
- watch(_key) { }
1036
- has(key) {
1037
- this.watch(key);
1038
- return this.source.has(key);
1039
- }
1040
- ;
1041
- delete(key) {
1042
- this.emit(key);
1043
- return this.source.delete(key);
1044
- }
1045
- ;
1046
- clear() {
1047
- this.emit(ANY);
1048
- this.source.clear();
1049
- }
1050
- keys() {
1051
- this.watch(ANY);
1052
- return this.source.keys();
1053
- }
1054
- values() {
1055
- this.watch(ANY);
1056
- return this.source.values();
1057
- }
1058
- entries() {
1059
- this.watch(ANY);
1060
- return this.source.entries();
1061
- }
1062
- ;
1063
- get size() {
1064
- this.watch(ANY);
1065
- return this.source.size;
1066
- }
1067
- [Symbol.iterator]() {
1068
- this.watch(ANY);
1069
- return this.source[Symbol.iterator]();
1070
- }
1071
- ;
1072
1076
  }
1073
1077
 
1074
1078
  const Oops$5 = issues({
@@ -1078,9 +1082,7 @@ function use$1(input, argument) {
1078
1082
  return apply(function use(key) {
1079
1083
  const { state, subject } = this;
1080
1084
  if (typeof input === "function")
1081
- input = Model.isTypeof(input)
1082
- ? new input()
1083
- : input();
1085
+ input = "prototype" in input ? new input() : input();
1084
1086
  else if (input && typeof input !== "object")
1085
1087
  throw Oops$5.BadArgument(typeof input);
1086
1088
  if (input instanceof Map || input instanceof Set)