@expressive/mvc 0.2.6 → 0.3.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
@@ -851,65 +851,60 @@ const Oops$7 = issues({
851
851
  NotReady: (model, key) => `Value ${model}.${key} value is not yet available.`,
852
852
  Failed: (model, key) => `Generating initial value for ${model}.${key} failed.`
853
853
  });
854
- function set(factory, argument) {
854
+ function put(factory, argument) {
855
855
  return apply(function set(key) {
856
856
  const { subject, state } = this;
857
857
  const required = argument === true || argument === undefined;
858
858
  let set;
859
859
  let get;
860
- let suspense;
861
- if (factory === undefined)
862
- suspense = true;
863
- else {
864
- let pending;
865
- let error;
866
- const init = () => {
867
- const output = typeof factory == "function" ?
868
- mayRetry(() => factory.call(subject, key, subject)) :
869
- factory;
870
- if (output instanceof Promise) {
871
- pending = output
872
- .catch(err => error = err)
873
- .then(val => state[key] = val)
874
- .finally(() => {
875
- pending = undefined;
876
- this.update(key);
877
- });
878
- return;
879
- }
880
- return state[key] = output;
881
- };
882
- const suspend = () => {
883
- if (required === false)
884
- return undefined;
885
- const issue = Oops$7.NotReady(subject, key);
886
- Object.assign(pending, {
887
- message: issue.message,
888
- stack: issue.stack
860
+ let pending;
861
+ let error;
862
+ const init = () => {
863
+ const output = typeof factory == "function" ?
864
+ mayRetry(() => factory.call(subject, key, subject)) :
865
+ factory;
866
+ if (output instanceof Promise) {
867
+ pending = output
868
+ .catch(err => error = err)
869
+ .then(val => state[key] = val)
870
+ .finally(() => {
871
+ pending = undefined;
872
+ this.update(key);
889
873
  });
890
- throw pending;
891
- };
892
- if (required)
893
- try {
894
- init();
895
- }
896
- catch (err) {
897
- Oops$7.Failed(subject, key).warn();
898
- throw err;
899
- }
900
- get = () => {
901
- if (pending)
902
- return suspend();
903
- if (error)
904
- throw error;
905
- if (key in state)
906
- return state[key];
907
- let output = init();
908
- return pending
909
- ? suspend()
910
- : output;
911
- };
912
- }
874
+ return;
875
+ }
876
+ return state[key] = output;
877
+ };
878
+ const suspend = () => {
879
+ if (required === false)
880
+ return undefined;
881
+ const issue = Oops$7.NotReady(subject, key);
882
+ Object.assign(pending, {
883
+ message: issue.message,
884
+ stack: issue.stack
885
+ });
886
+ throw pending;
887
+ };
888
+ if (required)
889
+ try {
890
+ init();
891
+ }
892
+ catch (err) {
893
+ Oops$7.Failed(subject, key).warn();
894
+ throw err;
895
+ }
896
+ get = () => {
897
+ if (pending)
898
+ return suspend();
899
+ if (error)
900
+ throw error;
901
+ if (key in state)
902
+ return state[key];
903
+ let output = init();
904
+ return pending
905
+ ? suspend()
906
+ : output;
907
+ };
913
908
  if (typeof argument == "function")
914
909
  set = createValueEffect(argument);
915
910
  else
@@ -919,8 +914,24 @@ function set(factory, argument) {
919
914
  };
920
915
  return {
921
916
  set,
922
- get,
923
- suspense
917
+ get
918
+ };
919
+ });
920
+ }
921
+
922
+ function set(value, argument) {
923
+ if (!(1 in arguments)) {
924
+ argument = value;
925
+ value = undefined;
926
+ }
927
+ return apply(function set(key) {
928
+ if (value !== undefined)
929
+ this.state[key] = value;
930
+ return {
931
+ suspense: true,
932
+ set: typeof argument == "function"
933
+ ? createValueEffect(argument)
934
+ : undefined
924
935
  };
925
936
  });
926
937
  }
@@ -1426,6 +1437,7 @@ exports.array = array;
1426
1437
  exports["default"] = MVC;
1427
1438
  exports.from = from;
1428
1439
  exports.parent = parent;
1440
+ exports.put = put;
1429
1441
  exports.ref = ref;
1430
1442
  exports.set = set;
1431
1443
  exports.tap = tap;