context 2.0.6 → 2.0.7-dev-ae93bf

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.
@@ -2,38 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var assign = Object.assign;
6
-
7
- function isFunction(value) {
8
- return typeof value === 'function';
9
- }
10
-
11
- function optionalFunctionValue(value) {
12
- var args = [];
13
- for (var _i = 1; _i < arguments.length; _i++) {
14
- args[_i - 1] = arguments[_i];
15
- }
16
- return isFunction(value) ? value.apply(void 0, args) : value;
17
- }
18
-
19
- function defaultTo(callback, defaultValue) {
20
- var _a;
21
- return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
22
- }
23
-
24
- function invariant(condition,
25
- // eslint-disable-next-line @typescript-eslint/ban-types
26
- message) {
27
- if (condition) {
28
- return;
29
- }
30
- // If message is a string object (rather than string literal)
31
- // Throw the value directly as a string
32
- // Alternatively, throw an error with the message
33
- throw message instanceof String
34
- ? message.valueOf()
35
- : new Error(message ? optionalFunctionValue(message) : message);
36
- }
5
+ var vestUtils = require('vest-utils');
37
6
 
38
7
  // eslint-disable-next-line max-lines-per-function
39
8
  function createContext(init) {
@@ -45,13 +14,14 @@ function createContext(init) {
45
14
  useX: useX
46
15
  };
47
16
  function useX(errorMessage) {
48
- invariant(storage.ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
49
- return storage.ctx;
17
+ var ctx = use();
18
+ vestUtils.invariant(ctx, vestUtils.defaultTo(errorMessage, 'Context was used after it was closed'));
19
+ return ctx;
50
20
  }
51
21
  function run(ctxRef, fn) {
52
22
  var _a;
53
23
  var parentContext = use();
54
- var out = assign({}, parentContext ? parentContext : {}, (_a = optionalFunctionValue(init, ctxRef, parentContext)) !== null && _a !== void 0 ? _a : ctxRef);
24
+ var out = vestUtils.assign({}, parentContext ? parentContext : {}, (_a = vestUtils.optionalFunctionValue(init, ctxRef, parentContext)) !== null && _a !== void 0 ? _a : ctxRef);
55
25
  var ctx = set(Object.freeze(out));
56
26
  storage.ancestry.unshift(ctx);
57
27
  var res = fn(ctx);
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=Object.assign;function t(n){return"function"==typeof n}function r(n){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return t(n)?n.apply(void 0,r):n}exports.createContext=function(t){function e(e,c){var i,f,a=u();return e=n({},a||{},null!==(i=r(t,e,a))&&void 0!==i?i:e),i=o.ctx=Object.freeze(e),o.ancestry.unshift(i),c=c(i),o.ancestry.shift(),o.ctx=null!==(f=o.ancestry[0])&&void 0!==f?f:null,c}function u(){return o.ctx}var o={ancestry:[]};return{bind:function(n,t){return function(){for(var r=[],u=0;u<arguments.length;u++)r[u]=arguments[u];return e(n,(function(){return t.apply(void 0,r)}))}},run:e,use:u,useX:function(n){return function(n,t){if(!n)throw t instanceof String?t.valueOf():Error(t?r(t):t)}(o.ctx,function(n,t){var e;return null!==(e=r(n))&&void 0!==e?e:t}(n,"Context was used after it was closed")),o.ctx}}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("vest-utils");exports.createContext=function(n){function e(e,i){var o,a,s=r();return e=t.assign({},s||{},null!==(o=t.optionalFunctionValue(n,e,s))&&void 0!==o?o:e),o=u.ctx=Object.freeze(e),u.ancestry.unshift(o),i=i(o),u.ancestry.shift(),u.ctx=null!==(a=u.ancestry[0])&&void 0!==a?a:null,i}function r(){return u.ctx}var u={ancestry:[]};return{bind:function(t,n){return function(){for(var r=[],u=0;u<arguments.length;u++)r[u]=arguments[u];return e(t,(function(){return n.apply(void 0,r)}))}},run:e,use:r,useX:function(n){var e=r();return t.invariant(e,t.defaultTo(n,"Context was used after it was closed")),e}}};
@@ -1,35 +1,4 @@
1
- var assign = Object.assign;
2
-
3
- function isFunction(value) {
4
- return typeof value === 'function';
5
- }
6
-
7
- function optionalFunctionValue(value) {
8
- var args = [];
9
- for (var _i = 1; _i < arguments.length; _i++) {
10
- args[_i - 1] = arguments[_i];
11
- }
12
- return isFunction(value) ? value.apply(void 0, args) : value;
13
- }
14
-
15
- function defaultTo(callback, defaultValue) {
16
- var _a;
17
- return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
18
- }
19
-
20
- function invariant(condition,
21
- // eslint-disable-next-line @typescript-eslint/ban-types
22
- message) {
23
- if (condition) {
24
- return;
25
- }
26
- // If message is a string object (rather than string literal)
27
- // Throw the value directly as a string
28
- // Alternatively, throw an error with the message
29
- throw message instanceof String
30
- ? message.valueOf()
31
- : new Error(message ? optionalFunctionValue(message) : message);
32
- }
1
+ import { invariant, defaultTo, assign, optionalFunctionValue } from 'vest-utils';
33
2
 
34
3
  // eslint-disable-next-line max-lines-per-function
35
4
  function createContext(init) {
@@ -41,8 +10,9 @@ function createContext(init) {
41
10
  useX: useX
42
11
  };
43
12
  function useX(errorMessage) {
44
- invariant(storage.ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
45
- return storage.ctx;
13
+ var ctx = use();
14
+ invariant(ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
15
+ return ctx;
46
16
  }
47
17
  function run(ctxRef, fn) {
48
18
  var _a;
@@ -1 +1 @@
1
- var n=Object.assign;function t(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return"function"==typeof n?n.apply(void 0,t):n}export function createContext(r){function e(e,c){var i,a,f=u();return e=n({},f||{},null!==(i=t(r,e,f))&&void 0!==i?i:e),i=o.ctx=Object.freeze(e),o.ancestry.unshift(i),c=c(i),o.ancestry.shift(),o.ctx=null!==(a=o.ancestry[0])&&void 0!==a?a:null,c}function u(){return o.ctx}var o={ancestry:[]};return{bind:function(n,t){return function(){for(var r=[],u=0;u<arguments.length;u++)r[u]=arguments[u];return e(n,(function(){return t.apply(void 0,r)}))}},run:e,use:u,useX:function(n){var r,e=o.ctx;if(n=null!==(r=t(n))&&void 0!==r?r:"Context was used after it was closed",!e)throw n instanceof String?n.valueOf():Error(n?t(n):n);return o.ctx}}}
1
+ import{invariant as t,defaultTo as n,assign as r,optionalFunctionValue as e}from"vest-utils";export function createContext(u){function c(t,n){var c,s,a=o();return t=r({},a||{},null!==(c=e(u,t,a))&&void 0!==c?c:t),c=i.ctx=Object.freeze(t),i.ancestry.unshift(c),n=n(c),i.ancestry.shift(),i.ctx=null!==(s=i.ancestry[0])&&void 0!==s?s:null,n}function o(){return i.ctx}var i={ancestry:[]};return{bind:function(t,n){return function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return c(t,(function(){return n.apply(void 0,r)}))}},run:c,use:o,useX:function(r){var e=o();return t(e,n(r,"Context was used after it was closed")),e}}}
@@ -4,8 +4,6 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.context = {}));
5
5
  }(this, (function (exports) { 'use strict';
6
6
 
7
- var assign = Object.assign;
8
-
9
7
  function isFunction(value) {
10
8
  return typeof value === 'function';
11
9
  }
@@ -18,11 +16,13 @@
18
16
  return isFunction(value) ? value.apply(void 0, args) : value;
19
17
  }
20
18
 
21
- function defaultTo(callback, defaultValue) {
19
+ function defaultTo(value, defaultValue) {
22
20
  var _a;
23
- return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
21
+ return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
24
22
  }
25
23
 
24
+ var assign = Object.assign;
25
+
26
26
  function invariant(condition,
27
27
  // eslint-disable-next-line @typescript-eslint/ban-types
28
28
  message) {
@@ -47,8 +47,9 @@
47
47
  useX: useX
48
48
  };
49
49
  function useX(errorMessage) {
50
- invariant(storage.ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
51
- return storage.ctx;
50
+ var ctx = use();
51
+ invariant(ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
52
+ return ctx;
52
53
  }
53
54
  function run(ctxRef, fn) {
54
55
  var _a;
@@ -1 +1 @@
1
- "use strict";!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).context={})}(this,(function(t){function e(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];return"function"==typeof t?t.apply(void 0,e):t}var n=Object.assign;t.createContext=function(t){function r(r,i){var f,c,s=o();return r=n({},s||{},null!==(f=e(t,r,s))&&void 0!==f?f:r),f=u.ctx=Object.freeze(r),u.ancestry.unshift(f),i=i(f),u.ancestry.shift(),u.ctx=null!==(c=u.ancestry[0])&&void 0!==c?c:null,i}function o(){return u.ctx}var u={ancestry:[]};return{bind:function(t,e){return function(){for(var n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];return r(t,(function(){return e.apply(void 0,n)}))}},run:r,use:o,useX:function(t){var n,r=u.ctx;if(t=null!==(n=e(t))&&void 0!==n?n:"Context was used after it was closed",!r)throw t instanceof String?t.valueOf():Error(t?e(t):t);return u.ctx}}},Object.defineProperty(t,"__esModule",{value:!0})}));
1
+ "use strict";!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).context={})}(this,(function(e){function n(e){for(var n=[],t=1;t<arguments.length;t++)n[t-1]=arguments[t];return"function"==typeof e?e.apply(void 0,n):e}var t=Object.assign;e.createContext=function(e){function r(r,i){var f,c,s=o();return r=t({},s||{},null!==(f=n(e,r,s))&&void 0!==f?f:r),f=u.ctx=Object.freeze(r),u.ancestry.unshift(f),i=i(f),u.ancestry.shift(),u.ctx=null!==(c=u.ancestry[0])&&void 0!==c?c:null,i}function o(){return u.ctx}var u={ancestry:[]};return{bind:function(e,n){return function(){for(var t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return r(e,(function(){return n.apply(void 0,t)}))}},run:r,use:o,useX:function(e){var t,r=o();if(e=null!==(t=n(e))&&void 0!==t?t:n("Context was used after it was closed"),!r)throw e instanceof String?e.valueOf():Error(e?n(e):e);return r}}},Object.defineProperty(e,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.0.6",
2
+ "version": "2.0.7-dev-ae93bf",
3
3
  "license": "MIT",
4
4
  "main": "./dist/cjs/context.js",
5
5
  "types": "./types/context.d.ts",
@@ -10,6 +10,9 @@
10
10
  "build": "vx build",
11
11
  "release": "vx release"
12
12
  },
13
+ "dependencies": {
14
+ "vest-utils": "^0.0.4-dev-ae93bf"
15
+ },
13
16
  "module": "./dist/es/context.production.js",
14
17
  "exports": {
15
18
  ".": {