@expressive/mvc 0.6.1 → 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
@@ -760,7 +745,8 @@ function factoryMode(self, output, key, required) {
760
745
  }
761
746
 
762
747
  const Oops$7 = issues({
763
- BadSource: (model, property, got) => `Bad from-instruction provided to ${model}.${property}. Expects an arrow-function or a Model as source. Got ${got}.`,
748
+ // BadSource: (model, property, got) =>
749
+ // `Bad from-instruction provided to ${model}.${property}. Expects an arrow-function or a Model as source. Got ${got}.`,
764
750
  PeerNotAllowed: (model, property) => `Attempted to use an instruction result (probably use or tap) as computed source for ${model}.${property}. This is not possible.`,
765
751
  ComputeFailed: (model, key) => `Generating initial value for ${model}.${key} failed.`,
766
752
  NotReady: (model, key) => `Value ${model}.${key} value is not yet available.`,
@@ -776,8 +762,8 @@ function get(arg0, arg1, arg2) {
776
762
  // Easy mistake, using a peer, will always be unresolved.
777
763
  if (typeof arg0 == "symbol")
778
764
  throw Oops$7.PeerNotAllowed(subject, key);
779
- if (typeof arg0 == "function" && /^[A-Z]/.test(arg0.name))
780
- throw Oops$7.BadSource(subject, key, arg0);
765
+ // if(typeof arg0 == "function" && /^[A-Z]/.test(arg0.name))
766
+ // throw Oops.BadSource(subject, key, arg0);
781
767
  this.state.set(key, undefined);
782
768
  const init = () => {
783
769
  let source = this;
@@ -804,7 +790,7 @@ function get(arg0, arg1, arg2) {
804
790
  throw new Error(`Factory argument cannot be ${arg1}`);
805
791
  getter = computeMode(this, source, setter, key, computeRequired);
806
792
  };
807
- if (typeof arg0 == "function" && factoryRequired)
793
+ if (typeof arg0 == "function" && computeRequired)
808
794
  try {
809
795
  init();
810
796
  }
@@ -820,18 +806,28 @@ function get(arg0, arg1, arg2) {
820
806
  });
821
807
  }
822
808
 
823
- function ref(callback) {
809
+ function ref(arg) {
824
810
  return apply(function ref(key) {
825
- const value = this.ref(key, callback && createValueEffect(callback));
826
- defineProperty(value, "current", {
827
- set: value,
828
- get: () => this.state.get(key)
829
- });
830
- return {
831
- value,
832
- explicit: true
833
- };
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 };
834
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)
829
+ });
830
+ return refObjectFunction;
835
831
  }
836
832
 
837
833
  function set(value, argument) {
@@ -1006,9 +1002,11 @@ function use$1(input, argument) {
1006
1002
  let pending;
1007
1003
  let error;
1008
1004
  let get = (_local) => state.get(key);
1009
- if (typeof input === "function")
1010
- input = /^[A-Z]/.test(input.name)
1011
- ? new input() : input;
1005
+ if (typeof input === "function") {
1006
+ if ("prototype" in input &&
1007
+ input === input.prototype.constructor)
1008
+ input = new input();
1009
+ }
1012
1010
  else if (input && typeof input !== "object")
1013
1011
  throw Oops$6.BadArgument(typeof input);
1014
1012
  if (input instanceof Map || input instanceof Set)
@@ -1477,11 +1475,11 @@ const Oops = issues({
1477
1475
  const Active = new WeakMap();
1478
1476
  class Global extends MVC {
1479
1477
  static create(...args) {
1480
- const Type = this;
1481
- if (Active.has(Type))
1478
+ if (Active.has(this))
1482
1479
  throw Oops.AlreadyExists(this.name);
1483
- const instance = super.create(...args);
1484
- Active.set(Type, instance);
1480
+ const instance = new this(...args);
1481
+ ensure(instance);
1482
+ Active.set(this, instance);
1485
1483
  return instance;
1486
1484
  }
1487
1485
  /**