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