@expressive/mvc 0.4.4 → 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 +12 -6
- package/lib/index.esm.js +107 -195
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +108 -195
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -174,7 +174,7 @@ const Oops$a = issues({
|
|
|
174
174
|
const INFO = new WeakMap();
|
|
175
175
|
const KEYS = new WeakMap();
|
|
176
176
|
const ORDER = new WeakMap();
|
|
177
|
-
function
|
|
177
|
+
function get(source, arg1, arg2) {
|
|
178
178
|
return apply(function from(key) {
|
|
179
179
|
const { subject, state } = this;
|
|
180
180
|
const required = arg2 === true || arg1 === true;
|
|
@@ -944,219 +944,135 @@ function parent(Expects, required) {
|
|
|
944
944
|
});
|
|
945
945
|
}
|
|
946
946
|
|
|
947
|
-
const ANY
|
|
948
|
-
function
|
|
949
|
-
const
|
|
950
|
-
const
|
|
951
|
-
const
|
|
947
|
+
const ANY = Symbol("any");
|
|
948
|
+
function keyed(control, property, initial) {
|
|
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
|
-
observers.forEach(notify => notify(key));
|
|
958
|
-
control.update(property);
|
|
959
965
|
control.waiting.add(reset);
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
966
|
+
control.update(property);
|
|
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;
|
|
972
1007
|
}
|
|
973
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
|
+
}
|
|
974
1025
|
});
|
|
975
|
-
local.add(property, false);
|
|
976
|
-
context.set(local, proxy);
|
|
977
|
-
proxy.watch = (key) => {
|
|
978
|
-
if (!local.active)
|
|
979
|
-
using.add(key);
|
|
980
|
-
};
|
|
981
|
-
return proxy;
|
|
982
|
-
}
|
|
983
|
-
return {
|
|
984
|
-
value: initial,
|
|
985
|
-
get(local) {
|
|
986
|
-
if (!local)
|
|
987
|
-
return managed;
|
|
988
|
-
if (context.has(local))
|
|
989
|
-
return context.get(local);
|
|
990
|
-
return init(local);
|
|
991
|
-
},
|
|
992
|
-
set(next) {
|
|
993
|
-
managed.source = next;
|
|
994
|
-
control.state.set(property, next);
|
|
995
|
-
emit(ANY$1);
|
|
996
|
-
},
|
|
997
|
-
destroy() {
|
|
998
|
-
observers.clear();
|
|
999
|
-
}
|
|
1000
|
-
};
|
|
1001
|
-
}
|
|
1002
|
-
class ManagedMap {
|
|
1003
|
-
constructor(source, emit) {
|
|
1004
|
-
this.source = source;
|
|
1005
|
-
this.emit = emit;
|
|
1006
|
-
}
|
|
1007
|
-
watch(_key) { }
|
|
1008
|
-
set(key, value) {
|
|
1009
|
-
this.source.set(key, value);
|
|
1010
|
-
this.emit(key);
|
|
1011
|
-
return this;
|
|
1012
|
-
}
|
|
1013
|
-
;
|
|
1014
|
-
delete(key) {
|
|
1015
|
-
this.emit(key);
|
|
1016
|
-
return this.source.delete(key);
|
|
1017
|
-
}
|
|
1018
|
-
;
|
|
1019
|
-
clear() {
|
|
1020
|
-
this.emit(ANY$1);
|
|
1021
|
-
this.source.clear();
|
|
1022
|
-
}
|
|
1023
|
-
get(key) {
|
|
1024
|
-
this.watch(key);
|
|
1025
|
-
return this.source.get(key);
|
|
1026
|
-
}
|
|
1027
|
-
;
|
|
1028
|
-
has(key) {
|
|
1029
|
-
this.watch(key);
|
|
1030
|
-
return this.source.has(key);
|
|
1031
|
-
}
|
|
1032
|
-
;
|
|
1033
|
-
values() {
|
|
1034
|
-
this.watch(ANY$1);
|
|
1035
|
-
return this.source.values();
|
|
1036
|
-
}
|
|
1037
|
-
keys() {
|
|
1038
|
-
this.watch(ANY$1);
|
|
1039
|
-
return this.source.keys();
|
|
1040
|
-
}
|
|
1041
|
-
entries() {
|
|
1042
|
-
this.watch(ANY$1);
|
|
1043
|
-
return this.source.entries();
|
|
1044
|
-
}
|
|
1045
|
-
;
|
|
1046
|
-
[Symbol.iterator]() {
|
|
1047
|
-
this.watch(ANY$1);
|
|
1048
|
-
return this.source[Symbol.iterator]();
|
|
1049
1026
|
}
|
|
1050
|
-
|
|
1051
|
-
get size() {
|
|
1052
|
-
this.watch(ANY$1);
|
|
1053
|
-
return this.source.size;
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
const ANY = Symbol("any");
|
|
1058
|
-
function managedSet(control, property, initial) {
|
|
1059
|
-
const managed = new ManagedSet(initial, emit);
|
|
1060
|
-
const context = new WeakMap();
|
|
1061
|
-
const observers = new Set();
|
|
1062
|
-
const frozen = new Set();
|
|
1063
|
-
function reset() {
|
|
1064
|
-
frozen.clear();
|
|
1065
|
-
}
|
|
1066
|
-
function emit(key) {
|
|
1067
|
-
observers.forEach(notify => notify(key));
|
|
1068
|
-
control.update(property);
|
|
1069
|
-
control.waiting.add(reset);
|
|
1070
|
-
}
|
|
1071
|
-
function init(local) {
|
|
1027
|
+
function subscribe(local) {
|
|
1072
1028
|
const proxy = create(managed);
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
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
|
+
}
|
|
1082
1042
|
}
|
|
1083
1043
|
}
|
|
1084
|
-
|
|
1085
|
-
|
|
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
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
watched.set(proxy, watch);
|
|
1086
1057
|
context.set(local, proxy);
|
|
1087
|
-
proxy.watch = (key) => {
|
|
1088
|
-
if (!local.active)
|
|
1089
|
-
using.add(key);
|
|
1090
|
-
};
|
|
1091
1058
|
return proxy;
|
|
1092
1059
|
}
|
|
1093
1060
|
return {
|
|
1094
1061
|
value: initial,
|
|
1095
1062
|
get(local) {
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
return context.get(local);
|
|
1100
|
-
return init(local);
|
|
1063
|
+
return local ?
|
|
1064
|
+
context.get(local) || subscribe(local) :
|
|
1065
|
+
managed;
|
|
1101
1066
|
},
|
|
1102
1067
|
set(next) {
|
|
1103
|
-
managed.source = next;
|
|
1104
1068
|
control.state.set(property, next);
|
|
1069
|
+
manage(next);
|
|
1105
1070
|
emit(ANY);
|
|
1106
1071
|
},
|
|
1107
1072
|
destroy() {
|
|
1108
|
-
|
|
1073
|
+
update.clear();
|
|
1109
1074
|
}
|
|
1110
1075
|
};
|
|
1111
|
-
}
|
|
1112
|
-
class ManagedSet {
|
|
1113
|
-
constructor(source, emit) {
|
|
1114
|
-
this.source = source;
|
|
1115
|
-
this.emit = emit;
|
|
1116
|
-
}
|
|
1117
|
-
watch(_key) { }
|
|
1118
|
-
add(key) {
|
|
1119
|
-
this.source.add(key);
|
|
1120
|
-
this.emit(key);
|
|
1121
|
-
return this;
|
|
1122
|
-
}
|
|
1123
|
-
;
|
|
1124
|
-
delete(key) {
|
|
1125
|
-
this.emit(key);
|
|
1126
|
-
return this.source.delete(key);
|
|
1127
|
-
}
|
|
1128
|
-
;
|
|
1129
|
-
clear() {
|
|
1130
|
-
this.emit(ANY);
|
|
1131
|
-
this.source.clear();
|
|
1132
|
-
}
|
|
1133
|
-
has(key) {
|
|
1134
|
-
this.watch(key);
|
|
1135
|
-
return this.source.has(key);
|
|
1136
|
-
}
|
|
1137
|
-
;
|
|
1138
|
-
values() {
|
|
1139
|
-
this.watch(ANY);
|
|
1140
|
-
return this.source.values();
|
|
1141
|
-
}
|
|
1142
|
-
keys() {
|
|
1143
|
-
this.watch(ANY);
|
|
1144
|
-
return this.source.keys();
|
|
1145
|
-
}
|
|
1146
|
-
entries() {
|
|
1147
|
-
this.watch(ANY);
|
|
1148
|
-
return this.source.entries();
|
|
1149
|
-
}
|
|
1150
|
-
;
|
|
1151
|
-
[Symbol.iterator]() {
|
|
1152
|
-
this.watch(ANY);
|
|
1153
|
-
return this.source[Symbol.iterator]();
|
|
1154
|
-
}
|
|
1155
|
-
;
|
|
1156
|
-
get size() {
|
|
1157
|
-
this.watch(ANY);
|
|
1158
|
-
return this.source.size;
|
|
1159
|
-
}
|
|
1160
1076
|
}
|
|
1161
1077
|
|
|
1162
1078
|
const Oops$5 = issues({
|
|
@@ -1166,15 +1082,11 @@ function use$1(input, argument) {
|
|
|
1166
1082
|
return apply(function use(key) {
|
|
1167
1083
|
const { state, subject } = this;
|
|
1168
1084
|
if (typeof input === "function")
|
|
1169
|
-
input =
|
|
1170
|
-
? new input()
|
|
1171
|
-
: input();
|
|
1085
|
+
input = "prototype" in input ? new input() : input();
|
|
1172
1086
|
else if (input && typeof input !== "object")
|
|
1173
1087
|
throw Oops$5.BadArgument(typeof input);
|
|
1174
|
-
if (input instanceof Map)
|
|
1175
|
-
return
|
|
1176
|
-
if (input instanceof Set)
|
|
1177
|
-
return managedSet(this, key, input);
|
|
1088
|
+
if (input instanceof Map || input instanceof Set)
|
|
1089
|
+
return keyed(this, key, input);
|
|
1178
1090
|
function onUpdate(next) {
|
|
1179
1091
|
state.set(key, next);
|
|
1180
1092
|
if (next) {
|
|
@@ -1629,7 +1541,8 @@ exports.act = act;
|
|
|
1629
1541
|
exports.apply = apply;
|
|
1630
1542
|
exports.array = array;
|
|
1631
1543
|
exports["default"] = MVC;
|
|
1632
|
-
exports.from =
|
|
1544
|
+
exports.from = get;
|
|
1545
|
+
exports.get = get;
|
|
1633
1546
|
exports.parent = parent;
|
|
1634
1547
|
exports.put = put;
|
|
1635
1548
|
exports.ref = ref;
|