context 2.0.1 → 2.0.2

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.
@@ -21,11 +21,18 @@ function defaultTo(callback, defaultValue) {
21
21
  return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
22
22
  }
23
23
 
24
- /**
25
- * Throws a timed out error.
26
- */
27
- function throwError(devMessage, productionMessage) {
28
- throw new Error(devMessage );
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);
29
36
  }
30
37
 
31
38
  // eslint-disable-next-line max-lines-per-function
@@ -38,8 +45,8 @@ function createContext(init) {
38
45
  useX: useX
39
46
  };
40
47
  function useX(errorMessage) {
41
- var _a;
42
- return ((_a = storage.ctx) !== null && _a !== void 0 ? _a : throwError(defaultTo(errorMessage, 'Context was used after it was closed')));
48
+ invariant(storage.ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
49
+ return storage.ctx;
43
50
  }
44
51
  function run(ctxRef, fn) {
45
52
  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}function e(n,t){var e;return null!==(e=r(n))&&void 0!==e?e:t}exports.createContext=function(t){function u(e,u){var i,f,a=o();return e=n({},a||{},null!==(i=r(t,e,a))&&void 0!==i?i:e),i=c.ctx=Object.freeze(e),c.ancestry.unshift(i),u=u(i),c.ancestry.shift(),c.ctx=null!==(f=c.ancestry[0])&&void 0!==f?f:null,u}function o(){return c.ctx}var c={ancestry:[]};return{bind:function(n,t){return function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return u(n,(function(){return t.apply(void 0,r)}))}},run:u,use:o,useX:function(n){var t;return null!==(t=c.ctx)&&void 0!==t?t:function(n,t){throw Error(e(t,n))}(e(n,"Context was used after it was closed"))}}};
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}}};
@@ -17,11 +17,18 @@ function defaultTo(callback, defaultValue) {
17
17
  return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
18
18
  }
19
19
 
20
- /**
21
- * Throws a timed out error.
22
- */
23
- function throwError(devMessage, productionMessage) {
24
- throw new Error(devMessage );
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);
25
32
  }
26
33
 
27
34
  // eslint-disable-next-line max-lines-per-function
@@ -34,8 +41,8 @@ function createContext(init) {
34
41
  useX: useX
35
42
  };
36
43
  function useX(errorMessage) {
37
- var _a;
38
- return ((_a = storage.ctx) !== null && _a !== void 0 ? _a : throwError(defaultTo(errorMessage, 'Context was used after it was closed')));
44
+ invariant(storage.ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
45
+ return storage.ctx;
39
46
  }
40
47
  function run(ctxRef, fn) {
41
48
  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}function r(n,r){var e;return null!==(e=t(n))&&void 0!==e?e:r}export function createContext(e){function u(r,u){var c,a,f=o();return r=n({},f||{},null!==(c=t(e,r,f))&&void 0!==c?c:r),c=i.ctx=Object.freeze(r),i.ancestry.unshift(c),u=u(c),i.ancestry.shift(),i.ctx=null!==(a=i.ancestry[0])&&void 0!==a?a:null,u}function o(){return i.ctx}var i={ancestry:[]};return{bind:function(n,t){return function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];return u(n,(function(){return t.apply(void 0,r)}))}},run:u,use:o,useX:function(n){var t;if(null===(t=i.ctx)||void 0===t)throw n=r(n,"Context was used after it was closed"),Error(r(void 0,n));return t}}}
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}}}
@@ -23,11 +23,18 @@
23
23
  return (_a = optionalFunctionValue(callback)) !== null && _a !== void 0 ? _a : defaultValue;
24
24
  }
25
25
 
26
- /**
27
- * Throws a timed out error.
28
- */
29
- function throwError(devMessage, productionMessage) {
30
- throw new Error(devMessage );
26
+ function invariant(condition,
27
+ // eslint-disable-next-line @typescript-eslint/ban-types
28
+ message) {
29
+ if (condition) {
30
+ return;
31
+ }
32
+ // If message is a string object (rather than string literal)
33
+ // Throw the value directly as a string
34
+ // Alternatively, throw an error with the message
35
+ throw message instanceof String
36
+ ? message.valueOf()
37
+ : new Error(message ? optionalFunctionValue(message) : message);
31
38
  }
32
39
 
33
40
  // eslint-disable-next-line max-lines-per-function
@@ -40,8 +47,8 @@
40
47
  useX: useX
41
48
  };
42
49
  function useX(errorMessage) {
43
- var _a;
44
- return ((_a = storage.ctx) !== null && _a !== void 0 ? _a : throwError(defaultTo(errorMessage, 'Context was used after it was closed')));
50
+ invariant(storage.ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
51
+ return storage.ctx;
45
52
  }
46
53
  function run(ctxRef, fn) {
47
54
  var _a;
@@ -1 +1 @@
1
- "use strict";!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).context={})}(this,(function(n){function t(n){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];return"function"==typeof n?n.apply(void 0,t):n}function e(n,e){var r;return null!==(r=t(n))&&void 0!==r?r:e}var r=Object.assign;n.createContext=function(n){function o(e,o){var f,c,s=u();return e=r({},s||{},null!==(f=t(n,e,s))&&void 0!==f?f:e),f=i.ctx=Object.freeze(e),i.ancestry.unshift(f),o=o(f),i.ancestry.shift(),i.ctx=null!==(c=i.ancestry[0])&&void 0!==c?c:null,o}function u(){return i.ctx}var i={ancestry:[]};return{bind:function(n,t){return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return o(n,(function(){return t.apply(void 0,e)}))}},run:o,use:u,useX:function(n){var t;if(null===(t=i.ctx)||void 0===t)throw n=e(n,"Context was used after it was closed"),Error(e(void 0,n));return t}}},Object.defineProperty(n,"__esModule",{value:!0})}));
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})}));
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.0.1",
2
+ "version": "2.0.2",
3
3
  "license": "MIT",
4
4
  "main": "./dist/cjs/context.js",
5
5
  "types": "./types/context.d.ts",
@@ -42,5 +42,7 @@
42
42
  },
43
43
  "bugs": {
44
44
  "url": "https://github.com/ealush/vest.git/issues"
45
- }
45
+ },
46
+ "unpkg": "./dist/umd/context.production.js",
47
+ "jsdelivr": "./dist/umd/context.production.js"
46
48
  }