@expressive/mvc 0.6.2 → 0.7.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/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,34 @@ function get(arg0, arg1, arg2) {
821
806
  });
822
807
  }
823
808
 
824
- function ref(callback) {
809
+ function ref(arg, mapper) {
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
+ value = createRef(this, key, arg);
814
+ else
815
+ ensure(arg).state.forEach((_val, key) => {
816
+ defineProperty(value, key, mapper ? {
817
+ configurable: true,
818
+ get() {
819
+ const out = mapper(key);
820
+ defineProperty(value, key, { value: out });
821
+ return out;
822
+ }
823
+ } : {
824
+ value: createRef(this, key)
825
+ });
826
+ });
827
+ return { value, explicit: true };
835
828
  });
829
+ }
830
+ function createRef(src, key, cb) {
831
+ const refObjectFunction = src.ref(key, cb && createValueEffect(cb));
832
+ defineProperty(refObjectFunction, "current", {
833
+ set: refObjectFunction,
834
+ get: () => src.state.get(key)
835
+ });
836
+ return refObjectFunction;
836
837
  }
837
838
 
838
839
  function set(value, argument) {
@@ -1007,9 +1008,11 @@ function use$1(input, argument) {
1007
1008
  let pending;
1008
1009
  let error;
1009
1010
  let get = (_local) => state.get(key);
1010
- if (typeof input === "function")
1011
- input = /^[A-Z]/.test(input.name)
1012
- ? new input() : input;
1011
+ if (typeof input === "function") {
1012
+ if ("prototype" in input &&
1013
+ input === input.prototype.constructor)
1014
+ input = new input();
1015
+ }
1013
1016
  else if (input && typeof input !== "object")
1014
1017
  throw Oops$6.BadArgument(typeof input);
1015
1018
  if (input instanceof Map || input instanceof Set)
@@ -1478,11 +1481,11 @@ const Oops = issues({
1478
1481
  const Active = new WeakMap();
1479
1482
  class Global extends MVC {
1480
1483
  static create(...args) {
1481
- const Type = this;
1482
- if (Active.has(Type))
1484
+ if (Active.has(this))
1483
1485
  throw Oops.AlreadyExists(this.name);
1484
- const instance = super.create(...args);
1485
- Active.set(Type, instance);
1486
+ const instance = new this(...args);
1487
+ ensure(instance);
1488
+ Active.set(this, instance);
1486
1489
  return instance;
1487
1490
  }
1488
1491
  /**