@expressive/mvc 0.6.3 → 0.7.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/lib/index.js CHANGED
@@ -204,22 +204,6 @@ class Model {
204
204
  defineProperty(this, "is", {
205
205
  value: this
206
206
  });
207
- defineProperty(this, "set", {
208
- configurable: true,
209
- get: () => {
210
- const controller = ensure(this);
211
- const value = (key, value) => {
212
- controller.state.set(key, value);
213
- controller.update(key);
214
- };
215
- for (const key of controller.state.keys())
216
- defineProperty(value, key, {
217
- value: controller.ref(key)
218
- });
219
- defineProperty(this, "set", { value });
220
- return value;
221
- }
222
- });
223
207
  }
224
208
  get [STATE]() {
225
209
  return this.export();
@@ -482,8 +466,11 @@ class Controller {
482
466
  return;
483
467
  if (typeof value == "symbol") {
484
468
  const instruction = PENDING.get(value);
485
- if (instruction)
469
+ if (instruction) {
470
+ delete subject[key];
471
+ PENDING.delete(value);
486
472
  instruction.call(this, key, this);
473
+ }
487
474
  return;
488
475
  }
489
476
  state.set(key, value);
@@ -587,9 +574,6 @@ function apply(fn, label) {
587
574
  const placeholder = Symbol(`${name} instruction`);
588
575
  function setup(key) {
589
576
  const { subject, state } = this;
590
- const control = this;
591
- PENDING.delete(placeholder);
592
- delete subject[key];
593
577
  let output = fn.call(this, key, this);
594
578
  if (typeof output == "function")
595
579
  output = { get: output };
@@ -612,6 +596,7 @@ function apply(fn, label) {
612
596
  destroy();
613
597
  });
614
598
  }
599
+ const control = this;
615
600
  defineProperty(subject, key, {
616
601
  enumerable: output.enumerable,
617
602
  set: onSet !== false
@@ -805,7 +790,7 @@ function get(arg0, arg1, arg2) {
805
790
  throw new Error(`Factory argument cannot be ${arg1}`);
806
791
  getter = computeMode(this, source, setter, key, computeRequired);
807
792
  };
808
- if (typeof arg0 == "function" && factoryRequired)
793
+ if (typeof arg0 == "function" && computeRequired)
809
794
  try {
810
795
  init();
811
796
  }
@@ -821,18 +806,28 @@ function get(arg0, arg1, arg2) {
821
806
  });
822
807
  }
823
808
 
824
- function ref(callback) {
809
+ function ref(arg) {
825
810
  return apply(function ref(key) {
826
- const value = this.ref(key, callback && createValueEffect(callback));
827
- defineProperty(value, "current", {
828
- set: value,
829
- get: () => this.state.get(key)
830
- });
831
- return {
832
- value,
833
- explicit: true
834
- };
811
+ let value = {};
812
+ if (typeof arg == "object") {
813
+ const source = ensure(arg);
814
+ for (const key of source.state.keys())
815
+ defineProperty(value, key, {
816
+ value: createRef(this, key)
817
+ });
818
+ }
819
+ else
820
+ value = createRef(this, key, arg);
821
+ return { value, explicit: true };
822
+ });
823
+ }
824
+ function createRef(src, key, cb) {
825
+ const refObjectFunction = src.ref(key, cb && createValueEffect(cb));
826
+ defineProperty(refObjectFunction, "current", {
827
+ set: refObjectFunction,
828
+ get: () => src.state.get(key)
835
829
  });
830
+ return refObjectFunction;
836
831
  }
837
832
 
838
833
  function set(value, argument) {
@@ -1480,11 +1475,11 @@ const Oops = issues({
1480
1475
  const Active = new WeakMap();
1481
1476
  class Global extends MVC {
1482
1477
  static create(...args) {
1483
- const Type = this;
1484
- if (Active.has(Type))
1478
+ if (Active.has(this))
1485
1479
  throw Oops.AlreadyExists(this.name);
1486
- const instance = super.create(...args);
1487
- Active.set(Type, instance);
1480
+ const instance = new this(...args);
1481
+ ensure(instance);
1482
+ Active.set(this, instance);
1488
1483
  return instance;
1489
1484
  }
1490
1485
  /**