@expressive/mvc 0.70.0 → 0.72.0

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.js CHANGED
@@ -22,17 +22,16 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  Context: () => Context,
24
24
  METHOD: () => METHOD,
25
- Model: () => Model,
26
25
  Observable: () => Observable,
26
+ State: () => State,
27
27
  addListener: () => addListener,
28
- createEffect: () => createEffect,
29
- default: () => Model,
28
+ default: () => State,
30
29
  event: () => event,
31
30
  get: () => get,
32
- has: () => has,
33
31
  ref: () => ref,
34
32
  set: () => set,
35
- use: () => use
33
+ use: () => use,
34
+ watch: () => watch
36
35
  });
37
36
  module.exports = __toCommonJS(index_exports);
38
37
 
@@ -49,40 +48,38 @@ function addListener(subject, callback, select) {
49
48
  LISTENERS.set(subject, listeners = /* @__PURE__ */ new Map([[onReady, void 0]]));
50
49
  if (select !== void 0 && !(select instanceof Set))
51
50
  select = /* @__PURE__ */ new Set([select]);
52
- if (!listeners.has(onReady) && !select)
51
+ if (!listeners.has(onReady) && !select) {
53
52
  callback.call(subject, true, subject);
53
+ }
54
54
  listeners.set(callback, select);
55
55
  return () => listeners.delete(callback);
56
56
  }
57
- function emit(model, key2) {
58
- const listeners = LISTENERS.get(model);
57
+ function emit(state, key2) {
58
+ const listeners = LISTENERS.get(state);
59
59
  const notReady = listeners.has(onReady);
60
- if (key2 === true && !notReady)
61
- return;
62
- let pending = PENDING.get(model);
60
+ if (key2 === true && !notReady) return;
61
+ let pending = PENDING.get(state);
63
62
  if (pending) {
64
63
  pending.add(key2);
65
64
  return;
66
65
  }
67
- PENDING.set(model, pending = new Set(notReady ? [true, key2] : [key2]));
66
+ PENDING.set(state, pending = new Set(notReady ? [true, key2] : [key2]));
68
67
  for (const key3 of pending)
69
68
  for (const [callback, filter] of listeners)
70
69
  if (!filter || filter.has(key3)) {
71
- const after = callback.call(model, key3, model);
72
- if (after)
70
+ const after = callback.call(state, key3, state);
71
+ if (after) {
73
72
  enqueue(after);
74
- else if (after === null)
73
+ } else if (after === null) {
75
74
  listeners.delete(callback);
75
+ }
76
76
  }
77
- if (key2 === null)
78
- listeners.clear();
79
- PENDING.delete(model);
77
+ if (key2 === null) listeners.clear();
78
+ PENDING.delete(state);
80
79
  }
81
80
  function event(subject, key2, silent) {
82
- if (key2 === null)
83
- return emit(subject, key2);
84
- if (!key2)
85
- return emit(subject, true);
81
+ if (key2 === null) return emit(subject, key2);
82
+ if (!key2) return emit(subject, true);
86
83
  let pending = PENDING_KEYS.get(subject);
87
84
  if (!pending) {
88
85
  PENDING_KEYS.set(subject, pending = /* @__PURE__ */ new Set());
@@ -93,8 +90,7 @@ function event(subject, key2, silent) {
93
90
  });
94
91
  }
95
92
  pending.add(key2);
96
- if (!silent)
97
- emit(subject, key2);
93
+ if (!silent) emit(subject, key2);
98
94
  }
99
95
  function enqueue(eventHandler) {
100
96
  if (!DISPATCH.size)
@@ -110,14 +106,13 @@ function enqueue(eventHandler) {
110
106
  }, 0);
111
107
  DISPATCH.add(eventHandler);
112
108
  }
113
- function createEffect(target, callback, argument) {
109
+ function watch(target, callback, argument) {
114
110
  let unset;
115
111
  let reset;
116
112
  function invoke() {
117
113
  let ignore = true;
118
114
  function onUpdate() {
119
- if (ignore || reset === null)
120
- return;
115
+ if (ignore || reset === null) return;
121
116
  ignore = true;
122
117
  if (reset && unset) {
123
118
  unset(true);
@@ -133,41 +128,34 @@ function createEffect(target, callback, argument) {
133
128
  ignore = false;
134
129
  reset = output === null ? null : invoke;
135
130
  unset = (key2) => {
136
- if (typeof output == "function")
137
- output(key2);
131
+ if (typeof output == "function") output(key2);
138
132
  flush();
139
133
  };
140
134
  } catch (err) {
141
135
  if (err instanceof Promise) {
142
136
  reset = void 0;
143
137
  err.then(invoke);
144
- } else
138
+ } else {
145
139
  throw err;
140
+ }
146
141
  }
147
142
  }
148
143
  function cleanup() {
149
- if (unset)
150
- unset(false);
144
+ if (unset) unset(false);
151
145
  reset = null;
152
146
  }
153
- ;
154
- if (EffectContext && argument !== false)
155
- EffectContext.add(cleanup);
147
+ if (EffectContext && argument !== false) EffectContext.add(cleanup);
156
148
  addListener(target, (key2) => {
157
- if (key2 === true)
158
- invoke();
159
- else if (!reset)
160
- return reset;
161
- if (key2 === null && unset)
162
- unset(null);
149
+ if (key2 === true) invoke();
150
+ else if (!reset) return reset;
151
+ if (key2 === null && unset) unset(null);
163
152
  });
164
153
  return cleanup;
165
154
  }
166
155
  var EffectContext;
167
156
  function enter(ignore) {
168
- if (ignore)
169
- return () => () => {
170
- };
157
+ if (ignore) return () => () => {
158
+ };
171
159
  const last = EffectContext;
172
160
  const context = EffectContext = /* @__PURE__ */ new Set();
173
161
  return () => {
@@ -176,7 +164,7 @@ function enter(ignore) {
176
164
  };
177
165
  }
178
166
 
179
- // src/model.ts
167
+ // src/state.ts
180
168
  var define = Object.defineProperty;
181
169
  var ID = /* @__PURE__ */ new WeakMap();
182
170
  var STATE = /* @__PURE__ */ new WeakMap();
@@ -184,7 +172,8 @@ var NOTIFY = /* @__PURE__ */ new WeakMap();
184
172
  var PARENT = /* @__PURE__ */ new WeakMap();
185
173
  var METHODS = /* @__PURE__ */ new WeakMap();
186
174
  var METHOD = /* @__PURE__ */ new WeakMap();
187
- var Model = class {
175
+ var EXPORT;
176
+ var State = class {
188
177
  constructor(...args) {
189
178
  prepare(this);
190
179
  define(this, "is", { value: this });
@@ -194,8 +183,7 @@ var Model = class {
194
183
  const watch2 = /* @__PURE__ */ new Set();
195
184
  const proxy = Object.create(this);
196
185
  addListener(this, (key2) => {
197
- if (watch2.has(key2))
198
- callback();
186
+ if (watch2.has(key2)) callback();
199
187
  });
200
188
  OBSERVER.set(proxy, (key2, value) => {
201
189
  if (value === void 0 && required)
@@ -209,19 +197,11 @@ var Model = class {
209
197
  }
210
198
  get(arg1, arg2) {
211
199
  const self = this.is;
212
- if (typeof arg1 == "function") {
213
- const effect = METHOD.get(arg1) || arg1;
214
- let pending = /* @__PURE__ */ new Set();
215
- return createEffect(self, (proxy) => {
216
- const cb = effect.call(proxy, proxy, pending);
217
- return cb === null ? null : (update2) => {
218
- pending = PENDING_KEYS.get(self);
219
- if (typeof cb == "function")
220
- cb(update2);
221
- };
222
- });
223
- }
224
- return arg1 === void 0 ? snapshot(self) : typeof arg2 == "function" ? addListener(self, arg2, arg1) : arg1 === null ? Object.isFrozen(STATE.get(self)) : fetch(self, arg1, arg2);
200
+ if (arg1 === void 0) return values(self);
201
+ if (typeof arg1 == "function") return effect(self, arg1);
202
+ if (typeof arg2 == "function") return addListener(self, arg2, arg1);
203
+ if (arg1 === null) return Object.isFrozen(STATE.get(self));
204
+ return access(self, arg1, arg2);
225
205
  }
226
206
  set(arg1, arg2, arg3) {
227
207
  const self = this.is;
@@ -230,14 +210,15 @@ var Model = class {
230
210
  if (arg2 === key2 || arg2 === void 0 && typeof key2 == "string")
231
211
  return arg1.call(self, key2, self);
232
212
  });
233
- if (arg1 && typeof arg1 == "object")
213
+ if (arg1 && typeof arg1 == "object") {
234
214
  assign(self, arg1, arg2 === true);
235
- else if (!arg2)
215
+ } else if (!arg2) {
236
216
  event(self, arg1);
237
- else if (arg3)
217
+ } else if (arg3) {
238
218
  manage(self, arg1, arg2);
239
- else
219
+ } else {
240
220
  update(self, arg1, arg2);
221
+ }
241
222
  const pending = PENDING_KEYS.get(this);
242
223
  if (pending)
243
224
  return {
@@ -252,21 +233,24 @@ var Model = class {
252
233
  };
253
234
  }
254
235
  /**
255
- * Iterate over managed properties in this instance of Model.
236
+ * Iterate over managed properties in this instance of State.
256
237
  * Yeilds the key and current value for each property.
257
238
  */
258
239
  [Symbol.iterator]() {
259
240
  return Object.entries(STATE.get(this.is))[Symbol.iterator]();
260
241
  }
261
242
  /**
262
- * Create and activate a new instance of this model.
263
- *
243
+ * Create and activate a new instance of this state.
244
+ *
264
245
  * **Important** - Unlike `new this(...)` - this method also activates state.
265
- *
246
+ *
266
247
  * @param args - arguments sent to constructor
267
248
  */
268
249
  static new(...args) {
269
- const instance = new this(...args);
250
+ const instance = new this(...args, (x) => {
251
+ const cb = x.new && x.new();
252
+ if (cb) x.set(cb, null);
253
+ });
270
254
  event(instance);
271
255
  return instance;
272
256
  }
@@ -280,22 +264,21 @@ var Model = class {
280
264
  return maybe === this || typeof maybe == "function" && maybe.prototype instanceof this;
281
265
  }
282
266
  /**
283
- * Register a callback to run when any instance of this Model is updated.
267
+ * Register a callback to run when any instance of this State is updated.
284
268
  */
285
269
  static on(listener) {
286
270
  let notify = NOTIFY.get(this);
287
- if (!notify)
288
- NOTIFY.set(this, notify = /* @__PURE__ */ new Set());
271
+ if (!notify) NOTIFY.set(this, notify = /* @__PURE__ */ new Set());
289
272
  notify.add(listener);
290
273
  return () => notify.delete(listener);
291
274
  }
292
275
  };
293
- define(Model.prototype, "toString", {
276
+ define(State.prototype, "toString", {
294
277
  value() {
295
278
  return ID.get(this.is);
296
279
  }
297
280
  });
298
- define(Model, "toString", {
281
+ define(State, "toString", {
299
282
  value() {
300
283
  return this.name;
301
284
  }
@@ -304,29 +287,29 @@ function assign(subject, data, silent) {
304
287
  const methods = METHODS.get(subject.constructor);
305
288
  for (const key2 in data) {
306
289
  const bind = methods.get(key2);
307
- if (bind)
308
- bind.call(subject, data[key2]);
290
+ if (bind) bind.call(subject, data[key2]);
309
291
  else if (key2 in subject && key2 !== "is") {
310
292
  const desc = Object.getOwnPropertyDescriptor(subject, key2);
311
293
  const set2 = desc && desc.set;
312
- if (set2)
294
+ if (set2) {
313
295
  set2.call(subject, data[key2], silent);
314
- else
296
+ } else {
315
297
  subject[key2] = data[key2];
298
+ }
316
299
  }
317
300
  }
318
301
  }
319
- function prepare(model) {
320
- let T = model.constructor;
321
- if (T === Model)
322
- throw new Error("Cannot create base Model.");
302
+ function prepare(state) {
303
+ let T = state.constructor;
304
+ if (T === State) throw new Error("Cannot create base State.");
323
305
  const chain = [];
324
306
  let keys2 = /* @__PURE__ */ new Map();
325
- ID.set(model, `${T}-${uid()}`);
307
+ ID.set(state, `${T}-${uid()}`);
326
308
  while (T.name) {
327
- for (const cb of NOTIFY.get(T) || [])
328
- addListener(model, cb);
329
- if (T === Model) break;
309
+ for (const cb of NOTIFY.get(T) || []) {
310
+ addListener(state, cb);
311
+ }
312
+ if (T === State) break;
330
313
  else chain.unshift(T);
331
314
  T = Object.getPrototypeOf(T);
332
315
  }
@@ -341,8 +324,7 @@ function prepare(model) {
341
324
  )) {
342
325
  let bind2 = function(original) {
343
326
  const { is } = this;
344
- if (is.hasOwnProperty(key2) && !original)
345
- return value;
327
+ if (is.hasOwnProperty(key2) && !original) return value;
346
328
  const fn = original || value;
347
329
  const bound = fn.bind(is);
348
330
  METHOD.set(bound, fn);
@@ -350,58 +332,85 @@ function prepare(model) {
350
332
  return bound;
351
333
  };
352
334
  var bind = bind2;
353
- if (!value || key2 == "constructor")
354
- continue;
335
+ if (!value || key2 == "constructor") continue;
355
336
  keys2.set(key2, bind2);
356
337
  define(type.prototype, key2, { get: bind2, set: bind2 });
357
338
  }
358
339
  }
359
340
  }
360
- function init(model, args) {
341
+ function init(self, args) {
361
342
  const state = {};
362
- STATE.set(model, state);
343
+ STATE.set(self, state);
363
344
  args = args.flat().filter((arg) => {
364
- if (typeof arg != "string")
365
- return true;
366
- ID.set(model, arg);
345
+ if (typeof arg == "string") ID.set(self, arg);
346
+ else return true;
367
347
  });
368
- addListener(model, () => {
369
- if (!PARENT.has(model))
370
- PARENT.set(model, null);
371
- for (const key2 in model) {
372
- const desc = Object.getOwnPropertyDescriptor(model, key2);
373
- if ("value" in desc)
374
- manage(model, key2, desc.value, true);
348
+ addListener(self, () => {
349
+ if (!PARENT.has(self)) PARENT.set(self, null);
350
+ for (const key2 in self) {
351
+ const desc = Object.getOwnPropertyDescriptor(self, key2);
352
+ if ("value" in desc) manage(self, key2, desc.value, true);
375
353
  }
376
354
  for (const arg of args) {
377
- const use2 = typeof arg == "function" ? arg.call(model, model) : arg;
355
+ const use2 = typeof arg == "function" ? arg.call(self, self) : arg;
378
356
  if (use2 instanceof Promise)
379
357
  use2.catch((err) => {
380
- console.error(`Async error in constructor for ${model}:`);
358
+ console.error(`Async error in constructor for ${self}:`);
381
359
  console.error(err);
382
360
  });
383
- else if (typeof use2 == "function")
384
- addListener(model, use2, null);
385
- else if (typeof use2 == "object")
386
- assign(model, use2, true);
361
+ else if (Array.isArray(use2)) args.push(...use2);
362
+ else if (typeof use2 == "function") addListener(self, use2, null);
363
+ else if (typeof use2 == "object") assign(self, use2, true);
387
364
  }
388
- addListener(model, () => {
389
- for (const [_, value] of model)
390
- if (value instanceof Model && PARENT.get(value) === model)
391
- value.set(null);
392
- Object.freeze(state);
393
- }, null);
365
+ addListener(
366
+ self,
367
+ () => {
368
+ for (const [_, value] of self)
369
+ if (value instanceof State && PARENT.get(value) === self)
370
+ value.set(null);
371
+ Object.freeze(state);
372
+ },
373
+ null
374
+ );
394
375
  return null;
395
376
  });
396
377
  }
378
+ function effect(target, fn) {
379
+ const effect2 = METHOD.get(fn) || fn;
380
+ let pending = /* @__PURE__ */ new Set();
381
+ return watch(target, (proxy) => {
382
+ const cb = effect2.call(proxy, proxy, pending);
383
+ if (cb === null) return cb;
384
+ return (update2) => {
385
+ pending = PENDING_KEYS.get(target);
386
+ if (typeof cb == "function") cb(update2);
387
+ };
388
+ });
389
+ }
390
+ function values(target) {
391
+ const values2 = {};
392
+ let isNotRecursive;
393
+ if (!EXPORT) {
394
+ isNotRecursive = true;
395
+ EXPORT = /* @__PURE__ */ new Map([[target, values2]]);
396
+ }
397
+ for (let [key2, value] of target) {
398
+ if (EXPORT.has(value)) value = EXPORT.get(value);
399
+ else if (value && typeof value == "object" && "get" in value && typeof value.get === "function")
400
+ EXPORT.set(value, value = value.get());
401
+ values2[key2] = value;
402
+ }
403
+ if (isNotRecursive) EXPORT = void 0;
404
+ return Object.freeze(values2);
405
+ }
397
406
  function manage(target, key2, value, silent) {
398
407
  const state = STATE.get(target);
399
408
  function get2() {
400
- return watch(this, key2, state[key2]);
409
+ return follow(this, key2, state[key2]);
401
410
  }
402
411
  function set2(value2, silent2) {
403
412
  update(target, key2, value2, silent2);
404
- if (value2 instanceof Model && !PARENT.has(value2)) {
413
+ if (value2 instanceof State && !PARENT.has(value2)) {
405
414
  PARENT.set(value2, target);
406
415
  event(value2);
407
416
  }
@@ -410,16 +419,15 @@ function manage(target, key2, value, silent) {
410
419
  set2(value, silent);
411
420
  }
412
421
  var OBSERVER = /* @__PURE__ */ new WeakMap();
413
- function watch(from, key2, value) {
414
- const access = OBSERVER.get(from);
415
- return access ? access(key2, value) : value;
422
+ function follow(from, key2, value) {
423
+ const observe = OBSERVER.get(from);
424
+ return observe ? observe(key2, value) : value;
416
425
  }
417
- function fetch(subject, property, required) {
426
+ function access(subject, property, required) {
418
427
  const state = STATE.get(subject);
419
428
  if (property in state || required === false) {
420
429
  const value = state[property];
421
- if (value !== void 0 || !required)
422
- return value;
430
+ if (value !== void 0 || !required) return value;
423
431
  }
424
432
  if (METHODS.get(subject.constructor).has(property))
425
433
  return METHOD.get(subject[property]);
@@ -430,8 +438,9 @@ function fetch(subject, property, required) {
430
438
  resolve(state[key2]);
431
439
  return null;
432
440
  }
433
- if (key2 === null)
441
+ if (key2 === null) {
434
442
  reject(new Error(`${subject} is destroyed.`));
443
+ }
435
444
  });
436
445
  });
437
446
  throw Object.assign(promise, {
@@ -441,148 +450,145 @@ function fetch(subject, property, required) {
441
450
  stack: error.stack
442
451
  });
443
452
  }
444
- var EXPORT;
445
- function snapshot(model) {
446
- const values = {};
447
- let isNotRecursive;
448
- if (!EXPORT) {
449
- isNotRecursive = true;
450
- EXPORT = /* @__PURE__ */ new Map([[model, values]]);
451
- }
452
- for (let [key2, value] of model) {
453
- if (EXPORT.has(value))
454
- value = EXPORT.get(value);
455
- else if (value && typeof value == "object" && "get" in value && typeof value.get === "function")
456
- EXPORT.set(value, value = value.get());
457
- values[key2] = value;
458
- }
459
- if (isNotRecursive)
460
- EXPORT = void 0;
461
- return Object.freeze(values);
462
- }
463
453
  function update(subject, key2, value, arg) {
464
454
  const state = STATE.get(subject);
465
455
  if (Object.isFrozen(state))
466
- throw new Error(`Tried to update ${subject}.${String(key2)} but model is destroyed.`);
456
+ throw new Error(
457
+ `Tried to update ${subject}.${String(key2)} but state is destroyed.`
458
+ );
467
459
  const previous = state[key2];
468
460
  if (typeof arg == "function") {
469
461
  const out = arg.call(subject, value, previous);
470
- if (out === false)
471
- return false;
472
- if (typeof out == "function")
473
- value = out();
462
+ if (out === false) return false;
463
+ if (typeof out == "function") value = out();
474
464
  }
475
- if (value === previous && key2 in state)
476
- return;
465
+ if (value === previous && key2 in state) return;
477
466
  state[key2] = value;
478
- if (arg !== true)
479
- event(subject, key2);
467
+ if (arg !== true) event(subject, key2);
480
468
  return true;
481
469
  }
482
470
  function uid() {
483
471
  return (0.278 + Math.random() * 0.722).toString(36).substring(2, 8).toUpperCase();
484
472
  }
485
473
 
474
+ // src/instruction/use.ts
475
+ var INSTRUCTION = /* @__PURE__ */ new Map();
476
+ function use(arg1, arg2) {
477
+ if (State.is(arg1)) arg1 = childInstruction(arg1, arg2);
478
+ const token = Symbol("instruction-" + uid());
479
+ INSTRUCTION.set(token, arg1);
480
+ return token;
481
+ }
482
+ function childInstruction(type, arg2) {
483
+ return (key2, subject) => {
484
+ function set2(next) {
485
+ if (next ? !(next instanceof type) : arg2 !== false)
486
+ throw new Error(
487
+ `${subject}.${key2} expected State of type ${type} but got ${next && next.constructor}.`
488
+ );
489
+ update(subject, key2, next);
490
+ if (next && typeof arg2 == "function") arg2(next);
491
+ return false;
492
+ }
493
+ const value = new type();
494
+ set2(value);
495
+ PARENT.set(value, subject);
496
+ value.set();
497
+ return { set: set2 };
498
+ };
499
+ }
500
+ function init2() {
501
+ const state = STATE.get(this);
502
+ for (const key2 in this) {
503
+ const { value } = Object.getOwnPropertyDescriptor(this, key2);
504
+ const instruction = INSTRUCTION.get(value);
505
+ if (!instruction) continue;
506
+ INSTRUCTION.delete(value);
507
+ delete this[key2];
508
+ const output = instruction.call(this, key2, this, state);
509
+ if (!output) continue;
510
+ const desc = typeof output == "object" ? output : { get: output };
511
+ if ("value" in desc) state[key2] = desc.value;
512
+ const self = this;
513
+ Object.defineProperty(self, key2, {
514
+ enumerable: desc.enumerable !== false,
515
+ get() {
516
+ return follow(
517
+ this,
518
+ key2,
519
+ typeof desc.get == "function" ? desc.get(this) : access(self, key2, desc.get)
520
+ );
521
+ },
522
+ set(next) {
523
+ if (desc.set === false) {
524
+ throw new Error(`${self}.${key2} is read-only.`);
525
+ }
526
+ update(self, key2, next, desc.set);
527
+ }
528
+ });
529
+ }
530
+ return null;
531
+ }
532
+ State.on(init2);
533
+
486
534
  // src/context.ts
487
535
  var LOOKUP = /* @__PURE__ */ new WeakMap();
488
536
  var KEYS = /* @__PURE__ */ new Map();
489
537
  function key(T, upstream) {
490
538
  let K = KEYS.get(T);
491
- if (!K)
492
- KEYS.set(T, K = Symbol(
493
- typeof T == "symbol" ? "get " + T.description : String(T)
494
- ));
539
+ if (!K) {
540
+ K = Symbol(typeof T == "symbol" ? "get " + T.description : String(T));
541
+ KEYS.set(T, K);
542
+ }
495
543
  return upstream ? key(K) : K;
496
544
  }
497
545
  function keys(from, upstream) {
498
546
  const keys2 = /* @__PURE__ */ new Set();
499
547
  do {
500
548
  keys2.add(key(from, upstream));
501
- } while ((from = Object.getPrototypeOf(from)) !== Model);
549
+ from = Object.getPrototypeOf(from);
550
+ } while (from !== State);
502
551
  return keys2;
503
552
  }
504
553
  var Context = class _Context {
505
554
  constructor(inputs) {
506
- this.layer = /* @__PURE__ */ new Map();
555
+ this.id = uid();
556
+ this.inputs = {};
507
557
  this.cleanup = /* @__PURE__ */ new Set();
508
- if (inputs)
509
- this.include(inputs);
558
+ if (inputs) this.use(inputs);
510
559
  }
511
560
  static get({ is }, callback) {
512
- const waiting = LOOKUP.get(is);
513
- if (waiting instanceof _Context) {
514
- if (callback)
515
- callback(waiting);
516
- return waiting;
561
+ const context = LOOKUP.get(is);
562
+ if (context instanceof _Context) {
563
+ if (callback) callback(context);
564
+ return context;
517
565
  }
518
566
  if (callback)
519
- if (waiting)
520
- waiting.push(callback);
521
- else
522
- LOOKUP.set(is, [callback]);
523
- }
524
- /** Run callback when a specified type is registered to a **child** context. */
525
- has(Type, callback) {
526
- Object.defineProperty(this, key(Type, true), { value: callback, configurable: true });
527
- }
528
- get(Type, require2) {
567
+ if (context) context.push(callback);
568
+ else LOOKUP.set(is, [callback]);
569
+ }
570
+ get(Type, arg2) {
571
+ if (typeof arg2 == "function") {
572
+ const k = key(Type, true);
573
+ Object.defineProperty(this, k, {
574
+ value: arg2,
575
+ configurable: true
576
+ });
577
+ return () => {
578
+ delete this[k];
579
+ };
580
+ }
529
581
  const result = this[key(Type)];
530
582
  if (result === null)
531
- throw new Error(`Did find ${Type} in context, but multiple were defined.`);
532
- if (result)
533
- return result;
534
- if (require2)
535
- throw new Error(`Could not find ${Type} in context.`);
536
- }
537
- push(inputs) {
538
- const next = Object.create(this);
539
- this.cleanup = /* @__PURE__ */ new Set([() => next.pop(), ...this.cleanup]);
540
- next.layer = /* @__PURE__ */ new Map();
541
- next.cleanup = /* @__PURE__ */ new Set();
542
- if (inputs)
543
- next.include(inputs);
544
- return next;
545
- }
546
- pop() {
547
- for (const key2 of Object.getOwnPropertySymbols(this))
548
- delete this[key2];
549
- this.cleanup.forEach((cb) => cb());
550
- this.cleanup.clear();
551
- this.layer.clear();
552
- }
553
- include(inputs, forEach) {
554
- const init3 = /* @__PURE__ */ new Map();
555
- if (typeof inputs == "function" || inputs instanceof Model)
556
- inputs = { [forEach ? 0 : this.layer.size]: inputs };
557
- Object.entries(inputs).forEach(([K, V]) => {
558
- if (Model.is(V) || V instanceof Model) {
559
- const exists = this.layer.get(K);
560
- if (!exists) {
561
- const instance = this.add(V);
562
- this.layer.set(K, V);
563
- init3.set(instance, true);
564
- } else if (exists !== V) {
565
- this.pop();
566
- this.id = uid();
567
- this.include(inputs);
568
- }
569
- return;
570
- }
571
583
  throw new Error(
572
- `Context may only include instance or class \`extends Model\` but got ${K == "0" || K == V ? V : `${V} (as '${K}')`}.`
584
+ `Did find ${Type} in context, but multiple were defined.`
573
585
  );
574
- });
575
- for (const [model, explicit] of init3) {
576
- model.set();
577
- if (explicit && forEach)
578
- forEach(model);
579
- for (const [_key, value] of model)
580
- if (PARENT.get(value) === model) {
581
- this.add(value, true);
582
- init3.set(value, false);
583
- }
584
- }
586
+ if (result) return result;
587
+ if (arg2) throw new Error(`Could not find ${Type} in context.`);
585
588
  }
589
+ /**
590
+ * Adds a State to this context.
591
+ */
586
592
  add(input, implicit) {
587
593
  const cleanup = /* @__PURE__ */ new Set();
588
594
  let T;
@@ -596,16 +602,14 @@ var Context = class _Context {
596
602
  }
597
603
  keys(T, true).forEach((K) => {
598
604
  const expects = this[K];
599
- if (!expects)
600
- return;
601
- addListener(I, (event2) => {
602
- if (event2 === true) {
603
- const callback = expects(I);
604
- if (callback)
605
- cleanup.add(callback);
606
- }
607
- return null;
608
- });
605
+ if (expects)
606
+ addListener(I, (event2) => {
607
+ if (event2 === true) {
608
+ const cb = expects(I);
609
+ if (cb) cleanup.add(cb);
610
+ }
611
+ return null;
612
+ });
609
613
  });
610
614
  keys(T).forEach((K) => {
611
615
  const value = this.hasOwnProperty(K) ? null : I;
@@ -617,272 +621,261 @@ var Context = class _Context {
617
621
  });
618
622
  this.cleanup.add(() => {
619
623
  cleanup.forEach((cb) => cb());
620
- if (I !== input)
621
- event(I, null);
624
+ if (I !== input) event(I, null);
622
625
  });
623
626
  const waiting = LOOKUP.get(I);
624
- if (waiting instanceof Array)
625
- waiting.forEach((cb) => cb(this));
627
+ if (waiting instanceof Array) waiting.forEach((cb) => cb(this));
626
628
  LOOKUP.set(I, this);
627
629
  return I;
628
630
  }
629
- };
630
-
631
- // src/instruction/use.ts
632
- var INSTRUCTION = /* @__PURE__ */ new Map();
633
- function use(arg1, arg2) {
634
- if (Model.is(arg1))
635
- arg1 = childInstruction(arg1, arg2);
636
- const token = Symbol("instruction-" + uid());
637
- INSTRUCTION.set(token, arg1);
638
- return token;
639
- }
640
- function childInstruction(type, arg2) {
641
- return (key2, subject) => {
642
- function set2(next) {
643
- if (next ? !(next instanceof type) : arg2 !== false)
644
- throw new Error(`${subject}.${key2} expected Model of type ${type} but got ${next && next.constructor}.`);
645
- update(subject, key2, next);
646
- if (next && typeof arg2 == "function")
647
- arg2(next);
648
- return false;
649
- }
650
- const value = new type();
651
- set2(value);
652
- PARENT.set(value, subject);
653
- value.set();
654
- return { set: set2 };
655
- };
656
- }
657
- function init2() {
658
- const state = STATE.get(this);
659
- for (const key2 in this) {
660
- const { value } = Object.getOwnPropertyDescriptor(this, key2);
661
- const instruction = INSTRUCTION.get(value);
662
- if (!instruction)
663
- continue;
664
- INSTRUCTION.delete(value);
665
- delete this[key2];
666
- const output = instruction.call(this, key2, this, state);
667
- if (!output)
668
- continue;
669
- const desc = typeof output == "object" ? output : { get: output };
670
- if ("value" in desc)
671
- state[key2] = desc.value;
672
- const model = this;
673
- Object.defineProperty(model, key2, {
674
- enumerable: desc.enumerable !== false,
675
- get() {
676
- return watch(
677
- this,
678
- key2,
679
- typeof desc.get == "function" ? desc.get(this) : fetch(model, key2, desc.get)
631
+ /**
632
+ * Register one or more States to this context.
633
+ *
634
+ * Context will add or remove States as needed to keep with provided input.
635
+ *
636
+ * @param inputs State, State class, or map of States / State classes to register.
637
+ * @param forEach Optional callback to run for each State registered.
638
+ */
639
+ use(inputs, forEach) {
640
+ const init3 = /* @__PURE__ */ new Map();
641
+ if (typeof inputs == "function" || inputs instanceof State)
642
+ inputs = { [0]: inputs };
643
+ for (const [K, V] of Object.entries(inputs)) {
644
+ if (!(State.is(V) || V instanceof State))
645
+ throw new Error(
646
+ `Context may only include instance or class \`extends State\` but got ${K == "0" || K == String(V) ? V : `${V} (as '${K}')`}.`
680
647
  );
681
- },
682
- set(next) {
683
- if (desc.set === false)
684
- throw new Error(`${model}.${key2} is read-only.`);
685
- update(model, key2, next, desc.set);
648
+ const exists = this.inputs[K];
649
+ if (!exists) {
650
+ init3.set(this.add(V), true);
651
+ } else if (exists !== V) {
652
+ this.pop();
653
+ this.use(inputs);
654
+ this.id = uid();
655
+ return;
686
656
  }
687
- });
657
+ }
658
+ for (const [state, explicit] of init3) {
659
+ state.set();
660
+ if (explicit && forEach) forEach(state);
661
+ for (const [_key, value] of state)
662
+ if (PARENT.get(value) === state) {
663
+ this.add(value, true);
664
+ init3.set(value, false);
665
+ }
666
+ }
667
+ this.inputs = inputs;
688
668
  }
689
- return null;
690
- }
691
- Model.on(init2);
669
+ /**
670
+ * Create a child context, optionally registering one or more States to it.
671
+ *
672
+ * @param inputs State, State class, or map of States / State classes to register.
673
+ */
674
+ push(inputs) {
675
+ const next = Object.create(this);
676
+ this.cleanup = /* @__PURE__ */ new Set([() => next.pop(), ...this.cleanup]);
677
+ next.inputs = {};
678
+ next.cleanup = /* @__PURE__ */ new Set();
679
+ if (inputs) next.use(inputs);
680
+ return next;
681
+ }
682
+ /**
683
+ * Remove all States from this context.
684
+ *
685
+ * Will also run any cleanup callbacks registered when States were added.
686
+ */
687
+ pop() {
688
+ for (const key2 of Object.getOwnPropertySymbols(this)) delete this[key2];
689
+ this.cleanup.forEach((cb) => cb());
690
+ this.cleanup.clear();
691
+ this.inputs = {};
692
+ }
693
+ };
694
+ Object.defineProperty(Context.prototype, "toString", {
695
+ value() {
696
+ return `Context-${this.id}`;
697
+ }
698
+ });
692
699
 
693
700
  // src/instruction/get.ts
694
- var STALE = /* @__PURE__ */ new WeakSet();
695
- function get(arg0, arg1) {
696
- return use((key2, subject, state) => {
697
- if (typeof arg0 == "symbol")
698
- throw new Error(`Attempted to use an instruction result (probably use or get) as computed source for ${subject}.${key2}. This is not allowed.`);
699
- if (Model.is(arg0)) {
700
- let assign3 = function(value) {
701
- if (typeof arg1 == "function")
702
- value.get((x) => arg1(x, key2));
703
- update(subject, key2, value);
701
+ function get(Type, arg1, arg2) {
702
+ const isDownstream = arg1 === true;
703
+ const isOptional = arg1 === false;
704
+ return use((key2, subject) => {
705
+ if (isDownstream) {
706
+ const callback = typeof arg2 === "function" ? arg2 : void 0;
707
+ const applied = /* @__PURE__ */ new Set();
708
+ const reset = () => {
709
+ update(subject, key2, Object.freeze(Array.from(applied)));
704
710
  };
705
- var assign2 = assign3;
706
- const hasParent = PARENT.get(subject);
707
- if (!hasParent && arg1 === true)
708
- throw new Error(`${subject} may only exist as a child of type ${arg0}.`);
709
- else if (hasParent) {
710
- if (hasParent instanceof arg0) {
711
- assign3(hasParent);
712
- return {};
713
- } else if (arg1 === true)
714
- throw new Error(`New ${subject} created as child of ${hasParent}, but must be instanceof ${arg0}.`);
715
- }
716
711
  Context.get(subject, (context) => {
717
- const model = context.get(arg0);
718
- if (model)
719
- assign3(model);
720
- else if (arg1 !== false)
721
- throw new Error(`Required ${arg0} not found in context for ${subject}.`);
712
+ context.get(Type, (state) => {
713
+ let remove;
714
+ let flush;
715
+ if (applied.has(state)) return;
716
+ if (callback) {
717
+ const exit = enter();
718
+ try {
719
+ const done2 = callback(state, subject);
720
+ if (done2 === false) return false;
721
+ if (typeof done2 == "function") remove = done2;
722
+ } finally {
723
+ flush = exit();
724
+ }
725
+ }
726
+ applied.add(state);
727
+ reset();
728
+ const done = () => {
729
+ if (flush) flush();
730
+ ignore();
731
+ applied.delete(state);
732
+ reset();
733
+ if (typeof remove == "function") remove();
734
+ remove = void 0;
735
+ };
736
+ const ignore = state.set(done, null);
737
+ return done;
738
+ });
722
739
  });
723
740
  return {
724
- get: arg1 !== false,
741
+ value: [],
725
742
  enumerable: false
726
743
  };
727
744
  }
728
- let from = subject;
729
- if (arg0 instanceof Model) {
730
- from = arg0;
731
- } else {
732
- const fn = METHOD.get(arg0) || arg0;
733
- arg1 = (p, k) => fn.call(p, k, p);
734
- }
735
- const source = (resolve) => resolve(from);
736
- const getter = arg1;
737
- let reset;
738
- let isAsync;
739
- let proxy;
740
- function connect(model) {
741
- reset = createEffect(model, (current) => {
742
- proxy = current;
743
- if (!(key2 in state) || STALE.delete(compute))
744
- compute(!reset);
745
- return (didUpdate) => {
746
- if (didUpdate) {
747
- STALE.add(compute);
748
- event(subject, key2, true);
749
- }
750
- };
751
- }, false);
752
- }
753
- function compute(initial) {
754
- let next;
755
- try {
756
- next = getter.call(proxy, proxy, key2);
757
- } catch (err) {
758
- console.warn(`An exception was thrown while ${initial ? "initializing" : "refreshing"} ${subject}.${key2}.`);
759
- if (initial)
760
- throw err;
761
- console.error(err);
745
+ const hasParent = PARENT.get(subject);
746
+ function assign2(value) {
747
+ if (typeof arg1 === "function") {
748
+ const callback = arg1;
749
+ const result = callback(value, subject);
750
+ if (typeof result === "function") {
751
+ subject.set(result, null);
752
+ }
762
753
  }
763
- update(subject, key2, next, !isAsync);
754
+ update(subject, key2, value);
764
755
  }
765
- return () => {
766
- if (!proxy) {
767
- source(connect);
768
- isAsync = true;
769
- }
770
- if (STALE.delete(compute))
771
- compute();
772
- return fetch(subject, key2, !proxy);
756
+ if (hasParent && hasParent instanceof Type) {
757
+ assign2(hasParent);
758
+ return {};
759
+ }
760
+ Context.get(subject, (context) => {
761
+ const self = context.get(Type);
762
+ if (self) assign2(self);
763
+ else if (!isOptional)
764
+ throw new Error(
765
+ `Required ${Type} not found in context for ${subject}.`
766
+ );
767
+ });
768
+ return {
769
+ get: !isOptional,
770
+ enumerable: false
773
771
  };
774
772
  });
775
773
  }
776
774
 
777
- // src/instruction/ref.ts
778
- var { defineProperty, defineProperties } = Object;
779
- function ref(arg, arg2) {
775
+ // src/instruction/set.ts
776
+ var STALE = /* @__PURE__ */ new WeakSet();
777
+ function set(value, argument) {
780
778
  return use((key2, subject, state) => {
781
- let value = {};
782
- const method = (key3, from) => (callback) => callback ? addListener(subject, () => callback(from[key3]), key3) : from[key3];
783
- if (arg === subject)
784
- addListener(subject, () => {
785
- for (const key3 in subject)
786
- if (typeof arg2 == "function")
787
- defineProperty(value, key3, {
788
- configurable: true,
789
- get() {
790
- const out = arg2(key3);
791
- defineProperty(value, key3, { value: out });
792
- return out;
779
+ if (typeof value == "symbol")
780
+ throw new Error(
781
+ `Attempted to use an instruction result (probably use or get) as computed source for ${subject}.${key2}. This is not allowed.`
782
+ );
783
+ const property = {};
784
+ if (value instanceof State || value === true) {
785
+ let connect2 = function(self) {
786
+ reset = watch(
787
+ self,
788
+ (current) => {
789
+ proxy = current;
790
+ if (!(key2 in state) || STALE.delete(compute2)) compute2(!reset);
791
+ return (didUpdate) => {
792
+ if (didUpdate) {
793
+ STALE.add(compute2);
794
+ event(subject, key2, true);
793
795
  }
794
- });
795
- else {
796
- const get2 = method(key3, subject);
797
- const set2 = (x) => subject[key3] = x;
798
- defineProperties(set2, {
799
- current: { get: get2, set: set2 },
800
- get: { value: get2 },
801
- is: { value: subject },
802
- key: { value: key3 }
803
- });
804
- defineProperty(value, key3, { value: set2 });
805
- }
806
- return null;
807
- }, true);
808
- else if (typeof arg == "object")
809
- throw new Error("ref instruction does not support object which is not 'this'");
810
- else {
811
- let unset;
812
- const get2 = method(key2, state);
813
- const set2 = (value2) => {
814
- if (!update(subject, key2, value2) || !arg)
815
- return;
816
- if (unset)
817
- unset = void unset(value2);
818
- if (value2 === null && arg2 !== false)
819
- return;
820
- const exit = enter();
821
- const out = arg.call(subject, value2);
822
- const flush = exit();
823
- unset = (key3) => {
824
- if (typeof out == "function")
825
- out(key3);
826
- flush();
827
- };
796
+ };
797
+ },
798
+ false
799
+ );
800
+ }, compute2 = function(initial) {
801
+ let next;
802
+ try {
803
+ next = getter.call(proxy, proxy, key2);
804
+ } catch (err) {
805
+ console.warn(
806
+ `An exception was thrown while ${initial ? "initializing" : "refreshing"} ${subject}.${key2}.`
807
+ );
808
+ if (initial) throw err;
809
+ console.error(err);
810
+ }
811
+ update(subject, key2, next, !isAsync);
812
+ };
813
+ var connect = connect2, compute = compute2;
814
+ let from = subject;
815
+ let getter;
816
+ if (value instanceof State) {
817
+ from = value;
818
+ getter = argument;
819
+ } else {
820
+ const fn = METHOD.get(argument) || argument;
821
+ getter = (p, k) => fn.call(p, k, p);
822
+ }
823
+ const source = (resolve) => resolve(from);
824
+ let reset;
825
+ let isAsync;
826
+ let proxy;
827
+ return () => {
828
+ if (!proxy) {
829
+ source(connect2);
830
+ isAsync = true;
831
+ }
832
+ if (STALE.delete(compute2)) compute2();
833
+ return access(subject, key2, !proxy);
828
834
  };
829
- state[key2] = null;
830
- value = defineProperties({ get: get2, key: key2, is: subject }, {
831
- current: { get: get2, set: set2 }
832
- });
833
835
  }
834
- defineProperty(subject, key2, { value });
835
- });
836
- }
837
-
838
- // src/instruction/set.ts
839
- function set(value, argument) {
840
- return use((key2, subject) => {
841
- const property = {};
842
- if (typeof value == "function" || isThenable(value)) {
836
+ if (typeof value == "function" || value instanceof Promise) {
843
837
  let init4 = function() {
844
838
  if (typeof value == "function")
845
839
  try {
846
840
  value = attempt(value.bind(subject, key2));
847
841
  } catch (err) {
848
- console.warn(`Generating initial value for ${subject}.${key2} failed.`);
842
+ console.warn(
843
+ `Generating initial value for ${subject}.${key2} failed.`
844
+ );
849
845
  throw err;
850
846
  }
851
847
  property.get = argument !== false;
852
848
  const set2 = (value2) => subject[key2] = value2;
853
- if (isThenable(value))
849
+ if (value instanceof Promise)
854
850
  value.then(set2, (error) => {
855
851
  event(subject, key2);
856
852
  property.get = () => {
857
853
  throw error;
858
854
  };
859
855
  });
860
- else
861
- set2(value);
862
- if (argument)
863
- return null;
856
+ else set2(value);
857
+ if (argument) return null;
864
858
  return subject[key2];
865
859
  };
866
860
  var init3 = init4;
867
- if (argument)
861
+ if (argument) {
868
862
  addListener(subject, init4, true);
869
- else
863
+ } else {
870
864
  property.get = init4;
871
- } else if (value !== void 0)
865
+ }
866
+ } else if (value !== void 0) {
872
867
  property.value = value;
868
+ }
873
869
  if (typeof argument == "function") {
874
870
  let unset;
875
871
  property.set = function(value2, previous) {
876
872
  const exit = enter();
877
873
  const returns = argument.call(this, value2, previous);
878
874
  const flush = exit();
879
- if (returns === false)
880
- return false;
881
- if (typeof unset == "function")
882
- unset(value2);
875
+ if (returns === false) return false;
876
+ if (typeof unset == "function") unset(value2);
883
877
  unset = (next) => {
884
- if (typeof returns == "function")
885
- returns(next);
878
+ if (typeof returns == "function") returns(next);
886
879
  flush();
887
880
  };
888
881
  };
@@ -896,10 +889,8 @@ function set(value, argument) {
896
889
  }
897
890
  function attempt(fn) {
898
891
  function retry(err) {
899
- if (err instanceof Promise)
900
- return err.then(compute);
901
- else
902
- throw err;
892
+ if (err instanceof Promise) return err.then(compute);
893
+ else throw err;
903
894
  }
904
895
  function compute() {
905
896
  try {
@@ -911,102 +902,82 @@ function attempt(fn) {
911
902
  }
912
903
  return compute();
913
904
  }
914
- function isThenable(value) {
915
- return value && typeof value == "object" && typeof value.then == "function";
916
- }
917
905
 
918
- // src/instruction/has.ts
919
- var APPLY = /* @__PURE__ */ new WeakMap();
920
- function has(arg1, arg2) {
921
- return use((key2, subject) => {
922
- const applied = /* @__PURE__ */ new Set();
923
- const reset = () => {
924
- update(subject, key2, Object.freeze(Array.from(applied)));
925
- };
926
- if (Model.is(arg1))
927
- Context.get(subject, (ctx) => {
928
- ctx.has(arg1, (model) => {
929
- let remove;
930
- let disconnect;
931
- let flush;
932
- if (applied.has(model))
933
- return;
934
- const exit = enter();
935
- try {
936
- const notify = APPLY.get(model);
937
- if (notify) {
938
- const after = notify(subject);
939
- if (after === false)
940
- return;
941
- if (typeof after == "function")
942
- disconnect = after;
943
- }
944
- if (typeof arg2 == "function") {
945
- const done2 = arg2(model, subject);
946
- if (done2 === false)
947
- return false;
948
- if (typeof done2 == "function")
949
- remove = done2;
906
+ // src/instruction/ref.ts
907
+ var { defineProperty, defineProperties } = Object;
908
+ function ref(arg, arg2) {
909
+ return use((key2, subject, state) => {
910
+ let value = {};
911
+ const method = (key3, from) => (callback) => callback ? addListener(subject, () => callback(from[key3]), key3) : from[key3];
912
+ if (arg === subject)
913
+ addListener(
914
+ subject,
915
+ () => {
916
+ for (const key3 in subject)
917
+ if (typeof arg2 == "function")
918
+ defineProperty(value, key3, {
919
+ configurable: true,
920
+ get() {
921
+ const out = arg2(key3);
922
+ defineProperty(value, key3, { value: out });
923
+ return out;
924
+ }
925
+ });
926
+ else {
927
+ const get2 = method(key3, subject);
928
+ const set2 = (x) => subject[key3] = x;
929
+ defineProperties(set2, {
930
+ current: { get: get2, set: set2 },
931
+ get: { value: get2 },
932
+ is: { value: subject },
933
+ key: { value: key3 }
934
+ });
935
+ defineProperty(value, key3, { value: set2 });
950
936
  }
951
- } finally {
952
- flush = exit();
953
- }
954
- applied.add(model);
955
- reset();
956
- const done = () => {
957
- flush();
958
- ignore();
959
- applied.delete(model);
960
- reset();
961
- if (disconnect)
962
- disconnect();
963
- if (typeof remove == "function")
964
- remove();
965
- remove = void 0;
966
- };
967
- const ignore = model.set(done, null);
968
- return done;
969
- });
970
- });
937
+ return null;
938
+ },
939
+ true
940
+ );
941
+ else if (typeof arg == "object")
942
+ throw new Error(
943
+ "ref instruction does not support object which is not 'this'"
944
+ );
971
945
  else {
972
- if (APPLY.has(subject))
973
- throw new Error(`'has' callback can only be used once per model.`);
974
- APPLY.set(subject, (recipient) => {
975
- let remove;
976
- if (arg1) {
977
- remove = arg1(recipient, subject);
978
- if (remove === false)
979
- return false;
980
- }
981
- applied.add(recipient);
982
- reset();
983
- return () => {
984
- applied.delete(recipient);
985
- reset();
986
- if (typeof remove == "function")
987
- remove();
946
+ let unset;
947
+ const get2 = method(key2, state);
948
+ const set2 = (value2) => {
949
+ if (!update(subject, key2, value2) || !arg) return;
950
+ if (unset) unset = void unset(value2);
951
+ if (value2 === null && arg2 !== false) return;
952
+ const exit = enter();
953
+ const out = arg.call(subject, value2);
954
+ const flush = exit();
955
+ unset = (key3) => {
956
+ if (typeof out == "function") out(key3);
957
+ flush();
988
958
  };
959
+ };
960
+ state[key2] = null;
961
+ value = defineProperty({ get: get2, key: key2, is: subject }, "current", {
962
+ get: get2,
963
+ set: set2
989
964
  });
990
965
  }
991
- return {
992
- value: [],
993
- enumerable: false
994
- };
966
+ defineProperty(subject, key2, { value });
995
967
  });
996
968
  }
997
969
  // Annotate the CommonJS export names for ESM import in node:
998
970
  0 && (module.exports = {
999
971
  Context,
1000
972
  METHOD,
1001
- Model,
1002
973
  Observable,
974
+ State,
1003
975
  addListener,
1004
- createEffect,
1005
976
  event,
1006
977
  get,
1007
- has,
1008
978
  ref,
1009
979
  set,
1010
- use
980
+ use,
981
+ watch
1011
982
  });
1012
983
  //# sourceMappingURL=index.js.map