context 2.0.6 → 2.0.7

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.
@@ -16,9 +16,9 @@ function optionalFunctionValue(value) {
16
16
  return isFunction(value) ? value.apply(void 0, args) : value;
17
17
  }
18
18
 
19
- function defaultTo(callback, defaultValue) {
19
+ function defaultTo(value, defaultValue) {
20
20
  var _a;
21
- return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
21
+ return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
22
22
  }
23
23
 
24
24
  function invariant(condition,
@@ -45,8 +45,9 @@ function createContext(init) {
45
45
  useX: useX
46
46
  };
47
47
  function useX(errorMessage) {
48
- invariant(storage.ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
49
- return storage.ctx;
48
+ var ctx = use();
49
+ invariant(ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
50
+ return ctx;
50
51
  }
51
52
  function run(ctxRef, fn) {
52
53
  var _a;
@@ -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 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,i){var c,f,a=u();return e=n({},a||{},null!==(c=r(t,e,a))&&void 0!==c?c:e),c=o.ctx=Object.freeze(e),o.ancestry.unshift(c),i=i(c),o.ancestry.shift(),o.ctx=null!==(f=o.ancestry[0])&&void 0!==f?f:null,i}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 t=u();return function(n,t){if(!n)throw t instanceof String?t.valueOf():Error(t?r(t):t)}(t,function(n,t){var e;return null!==(e=r(n))&&void 0!==e?e:r(t)}(n,"Context was used after it was closed")),t}}};
@@ -12,9 +12,9 @@ function optionalFunctionValue(value) {
12
12
  return isFunction(value) ? value.apply(void 0, args) : value;
13
13
  }
14
14
 
15
- function defaultTo(callback, defaultValue) {
15
+ function defaultTo(value, defaultValue) {
16
16
  var _a;
17
- return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
17
+ return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
18
18
  }
19
19
 
20
20
  function invariant(condition,
@@ -41,8 +41,9 @@ function createContext(init) {
41
41
  useX: useX
42
42
  };
43
43
  function useX(errorMessage) {
44
- invariant(storage.ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
45
- return storage.ctx;
44
+ var ctx = use();
45
+ invariant(ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
46
+ return ctx;
46
47
  }
47
48
  function run(ctxRef, fn) {
48
49
  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
+ 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,i){var c,a,f=u();return e=n({},f||{},null!==(c=t(r,e,f))&&void 0!==c?c:e),c=o.ctx=Object.freeze(e),o.ancestry.unshift(c),i=i(c),o.ancestry.shift(),o.ctx=null!==(a=o.ancestry[0])&&void 0!==a?a:null,i}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=u();if(n=null!==(r=t(n))&&void 0!==r?r:t("Context was used after it was closed"),!e)throw n instanceof String?n.valueOf():Error(n?t(n):n);return e}}}
@@ -18,9 +18,9 @@
18
18
  return isFunction(value) ? value.apply(void 0, args) : value;
19
19
  }
20
20
 
21
- function defaultTo(callback, defaultValue) {
21
+ function defaultTo(value, defaultValue) {
22
22
  var _a;
23
- return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
23
+ return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
24
24
  }
25
25
 
26
26
  function invariant(condition,
@@ -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",
3
3
  "license": "MIT",
4
4
  "main": "./dist/cjs/context.js",
5
5
  "types": "./types/context.d.ts",