@expressive/mvc 0.36.0 → 0.36.1
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/dist/index.d.ts +1 -1
- package/dist/index.js +33 -30
- package/dist/index.mjs +33 -30
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ interface Model {
|
|
|
54
54
|
is: this;
|
|
55
55
|
}
|
|
56
56
|
declare class Model {
|
|
57
|
-
constructor(
|
|
57
|
+
constructor(arg?: string | (() => void | (() => void)));
|
|
58
58
|
/** Pull current values from state. Flattens all models and exotic values recursively. */
|
|
59
59
|
get(): Model.State<this>;
|
|
60
60
|
/** Run a function which will run automatically when accessed values change. */
|
package/dist/index.js
CHANGED
|
@@ -159,45 +159,25 @@ var NOTIFY = /* @__PURE__ */ new WeakMap();
|
|
|
159
159
|
var PENDING2 = /* @__PURE__ */ new WeakMap();
|
|
160
160
|
var define = Object.defineProperty;
|
|
161
161
|
var Model = class _Model {
|
|
162
|
-
constructor(
|
|
162
|
+
constructor(arg) {
|
|
163
163
|
let Type = this.constructor;
|
|
164
|
-
const state = {};
|
|
165
164
|
define(this, "is", { value: this });
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
id = void 0;
|
|
169
|
-
this.get(() => cb());
|
|
170
|
-
}
|
|
171
|
-
STATE.set(this, state);
|
|
172
|
-
ID.set(this, id ? String(id) : `${Type}-${uid()}`);
|
|
165
|
+
STATE.set(this, {});
|
|
166
|
+
ID.set(this, typeof arg == "string" ? arg : `${Type}-${uid()}`);
|
|
173
167
|
while (true) {
|
|
174
168
|
new Set(NOTIFY.get(Type)).forEach((x) => addListener(this, x));
|
|
175
169
|
if (Type === _Model)
|
|
176
170
|
break;
|
|
177
171
|
Type = Object.getPrototypeOf(Type);
|
|
178
172
|
}
|
|
179
|
-
addListener(this,
|
|
180
|
-
|
|
181
|
-
const desc = Object.getOwnPropertyDescriptor(this, key);
|
|
182
|
-
if ("value" in desc) {
|
|
183
|
-
state[key] = desc.value;
|
|
184
|
-
define(this, key, {
|
|
185
|
-
enumerable: true,
|
|
186
|
-
set: (x) => update(this, key, x),
|
|
187
|
-
get() {
|
|
188
|
-
return watch(this, key, state[key]);
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
}
|
|
173
|
+
addListener(this, bootstrap);
|
|
174
|
+
if (typeof arg == "function")
|
|
193
175
|
addListener(this, () => {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
return null;
|
|
200
|
-
});
|
|
176
|
+
const cleanup = arg();
|
|
177
|
+
if (typeof cleanup == "function")
|
|
178
|
+
addListener(this, cleanup, null);
|
|
179
|
+
return null;
|
|
180
|
+
});
|
|
201
181
|
}
|
|
202
182
|
get(arg1, arg2) {
|
|
203
183
|
const self = this.is;
|
|
@@ -286,6 +266,29 @@ define(Model, "toString", {
|
|
|
286
266
|
return this.name;
|
|
287
267
|
}
|
|
288
268
|
});
|
|
269
|
+
function bootstrap() {
|
|
270
|
+
const state = STATE.get(this);
|
|
271
|
+
for (const key in this) {
|
|
272
|
+
const desc = Object.getOwnPropertyDescriptor(this, key);
|
|
273
|
+
if ("value" in desc) {
|
|
274
|
+
state[key] = desc.value;
|
|
275
|
+
define(this, key, {
|
|
276
|
+
configurable: false,
|
|
277
|
+
set: (x) => update(this, key, x),
|
|
278
|
+
get() {
|
|
279
|
+
return watch(this, key, state[key]);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
addListener(this, () => {
|
|
285
|
+
for (const [_, value] of this)
|
|
286
|
+
if (value instanceof Model && PARENT.get(value) === this)
|
|
287
|
+
value.set(null);
|
|
288
|
+
Object.freeze(state);
|
|
289
|
+
}, null);
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
289
292
|
function fetch(subject, property, required) {
|
|
290
293
|
const state = STATE.get(subject);
|
|
291
294
|
if (property in state || required === false) {
|
package/dist/index.mjs
CHANGED
|
@@ -126,45 +126,25 @@ var NOTIFY = /* @__PURE__ */ new WeakMap();
|
|
|
126
126
|
var PENDING2 = /* @__PURE__ */ new WeakMap();
|
|
127
127
|
var define = Object.defineProperty;
|
|
128
128
|
var Model = class _Model {
|
|
129
|
-
constructor(
|
|
129
|
+
constructor(arg) {
|
|
130
130
|
let Type = this.constructor;
|
|
131
|
-
const state = {};
|
|
132
131
|
define(this, "is", { value: this });
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
id = void 0;
|
|
136
|
-
this.get(() => cb());
|
|
137
|
-
}
|
|
138
|
-
STATE.set(this, state);
|
|
139
|
-
ID.set(this, id ? String(id) : `${Type}-${uid()}`);
|
|
132
|
+
STATE.set(this, {});
|
|
133
|
+
ID.set(this, typeof arg == "string" ? arg : `${Type}-${uid()}`);
|
|
140
134
|
while (true) {
|
|
141
135
|
new Set(NOTIFY.get(Type)).forEach((x) => addListener(this, x));
|
|
142
136
|
if (Type === _Model)
|
|
143
137
|
break;
|
|
144
138
|
Type = Object.getPrototypeOf(Type);
|
|
145
139
|
}
|
|
146
|
-
addListener(this,
|
|
147
|
-
|
|
148
|
-
const desc = Object.getOwnPropertyDescriptor(this, key);
|
|
149
|
-
if ("value" in desc) {
|
|
150
|
-
state[key] = desc.value;
|
|
151
|
-
define(this, key, {
|
|
152
|
-
enumerable: true,
|
|
153
|
-
set: (x) => update(this, key, x),
|
|
154
|
-
get() {
|
|
155
|
-
return watch(this, key, state[key]);
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
140
|
+
addListener(this, bootstrap);
|
|
141
|
+
if (typeof arg == "function")
|
|
160
142
|
addListener(this, () => {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
return null;
|
|
167
|
-
});
|
|
143
|
+
const cleanup = arg();
|
|
144
|
+
if (typeof cleanup == "function")
|
|
145
|
+
addListener(this, cleanup, null);
|
|
146
|
+
return null;
|
|
147
|
+
});
|
|
168
148
|
}
|
|
169
149
|
get(arg1, arg2) {
|
|
170
150
|
const self = this.is;
|
|
@@ -253,6 +233,29 @@ define(Model, "toString", {
|
|
|
253
233
|
return this.name;
|
|
254
234
|
}
|
|
255
235
|
});
|
|
236
|
+
function bootstrap() {
|
|
237
|
+
const state = STATE.get(this);
|
|
238
|
+
for (const key in this) {
|
|
239
|
+
const desc = Object.getOwnPropertyDescriptor(this, key);
|
|
240
|
+
if ("value" in desc) {
|
|
241
|
+
state[key] = desc.value;
|
|
242
|
+
define(this, key, {
|
|
243
|
+
configurable: false,
|
|
244
|
+
set: (x) => update(this, key, x),
|
|
245
|
+
get() {
|
|
246
|
+
return watch(this, key, state[key]);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
addListener(this, () => {
|
|
252
|
+
for (const [_, value] of this)
|
|
253
|
+
if (value instanceof Model && PARENT.get(value) === this)
|
|
254
|
+
value.set(null);
|
|
255
|
+
Object.freeze(state);
|
|
256
|
+
}, null);
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
256
259
|
function fetch(subject, property, required) {
|
|
257
260
|
const state = STATE.get(subject);
|
|
258
261
|
if (property in state || required === false) {
|
package/package.json
CHANGED