context 4.0.0 → 4.0.1

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.
@@ -1,69 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var vestUtils = require('vest-utils');
6
-
7
- var USEX_DEFAULT_ERROR_MESSAGE = 'Not inside of a running context.';
8
- var EMPTY_CONTEXT = Symbol();
9
- /**
10
- * Base context interface.
11
- */
12
- function createContext(defaultContextValue) {
13
- var contextValue = EMPTY_CONTEXT;
14
- return {
15
- run: run,
16
- use: use,
17
- useX: useX
18
- };
19
- function use() {
20
- return (isInsideContext() ? contextValue : defaultContextValue);
21
- }
22
- function useX(errorMessage) {
23
- vestUtils.invariant(isInsideContext(), vestUtils.defaultTo(errorMessage, USEX_DEFAULT_ERROR_MESSAGE));
24
- return contextValue;
25
- }
26
- function run(value, cb) {
27
- var parentContext = isInsideContext() ? use() : EMPTY_CONTEXT;
28
- contextValue = value;
29
- var res = cb();
30
- contextValue = parentContext;
31
- return res;
32
- }
33
- function isInsideContext() {
34
- return contextValue !== EMPTY_CONTEXT;
35
- }
36
- }
37
- /**
38
- * Cascading context - another implementation of context, that assumes the context value is an object.
39
- * When nesting context runs, the the values of the current layer merges with the layers above it.
40
- */
41
- function createCascade(init) {
42
- var ctx = createContext();
43
- return {
44
- bind: bind,
45
- run: run,
46
- use: ctx.use,
47
- useX: ctx.useX
48
- };
49
- function run(value, fn) {
50
- var _a;
51
- var parentContext = ctx.use();
52
- var out = vestUtils.assign({}, parentContext ? parentContext : {}, (_a = vestUtils.optionalFunctionValue(init, value, parentContext)) !== null && _a !== void 0 ? _a : value);
53
- return ctx.run(Object.freeze(out), fn);
54
- }
55
- function bind(value, fn) {
56
- return function () {
57
- var runTimeArgs = [];
58
- for (var _i = 0; _i < arguments.length; _i++) {
59
- runTimeArgs[_i] = arguments[_i];
60
- }
61
- return run(value, function () {
62
- return fn.apply(void 0, runTimeArgs);
63
- });
64
- };
65
- }
66
- }
67
-
68
- exports.createCascade = createCascade;
69
- exports.createContext = createContext;
@@ -1,7 +0,0 @@
1
- 'use strict'
2
-
3
- if (process.env.NODE_ENV === 'production') {
4
- module.exports = require('./context.production.js');
5
- } else {
6
- module.exports = require('./context.development.js');
7
- }
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("vest-utils"),e=Symbol();function r(r){var t=e;return{run:function(n,r){var i=o()?u():e;t=n;var a=r();return t=i,a},use:u,useX:function(e){return n.invariant(o(),n.defaultTo(e,"Not inside of a running context.")),t}};function u(){return o()?t:r}function o(){return t!==e}}exports.createCascade=function(e){var t=r();return{bind:function(n,e){return function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];return u(n,(function(){return e.apply(void 0,r)}))}},run:u,use:t.use,useX:t.useX};function u(r,u){var o,i=t.use(),a=n.assign({},i||{},null!==(o=n.optionalFunctionValue(e,r,i))&&void 0!==o?o:r);return t.run(Object.freeze(a),u)}},exports.createContext=r;
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1,64 +0,0 @@
1
- import { invariant, defaultTo, assign, optionalFunctionValue } from 'vest-utils';
2
-
3
- var USEX_DEFAULT_ERROR_MESSAGE = 'Not inside of a running context.';
4
- var EMPTY_CONTEXT = Symbol();
5
- /**
6
- * Base context interface.
7
- */
8
- function createContext(defaultContextValue) {
9
- var contextValue = EMPTY_CONTEXT;
10
- return {
11
- run: run,
12
- use: use,
13
- useX: useX
14
- };
15
- function use() {
16
- return (isInsideContext() ? contextValue : defaultContextValue);
17
- }
18
- function useX(errorMessage) {
19
- invariant(isInsideContext(), defaultTo(errorMessage, USEX_DEFAULT_ERROR_MESSAGE));
20
- return contextValue;
21
- }
22
- function run(value, cb) {
23
- var parentContext = isInsideContext() ? use() : EMPTY_CONTEXT;
24
- contextValue = value;
25
- var res = cb();
26
- contextValue = parentContext;
27
- return res;
28
- }
29
- function isInsideContext() {
30
- return contextValue !== EMPTY_CONTEXT;
31
- }
32
- }
33
- /**
34
- * Cascading context - another implementation of context, that assumes the context value is an object.
35
- * When nesting context runs, the the values of the current layer merges with the layers above it.
36
- */
37
- function createCascade(init) {
38
- var ctx = createContext();
39
- return {
40
- bind: bind,
41
- run: run,
42
- use: ctx.use,
43
- useX: ctx.useX
44
- };
45
- function run(value, fn) {
46
- var _a;
47
- var parentContext = ctx.use();
48
- var out = assign({}, parentContext ? parentContext : {}, (_a = optionalFunctionValue(init, value, parentContext)) !== null && _a !== void 0 ? _a : value);
49
- return ctx.run(Object.freeze(out), fn);
50
- }
51
- function bind(value, fn) {
52
- return function () {
53
- var runTimeArgs = [];
54
- for (var _i = 0; _i < arguments.length; _i++) {
55
- runTimeArgs[_i] = arguments[_i];
56
- }
57
- return run(value, function () {
58
- return fn.apply(void 0, runTimeArgs);
59
- });
60
- };
61
- }
62
- }
63
-
64
- export { createCascade, createContext };
@@ -1 +0,0 @@
1
- import{invariant as n,defaultTo as r,assign as u,optionalFunctionValue as t}from"vest-utils";var e=Symbol();function o(u){var t=e;return{run:function(n,r){var u=i()?o():e;t=n;var f=r();return t=u,f},use:o,useX:function(u){return n(i(),r(u,"Not inside of a running context.")),t}};function o(){return i()?t:u}function i(){return t!==e}}function i(n){var r=o();return{bind:function(n,r){return function(){for(var u=[],t=0;t<arguments.length;t++)u[t]=arguments[t];return e(n,(function(){return r.apply(void 0,u)}))}},run:e,use:r.use,useX:r.useX};function e(e,o){var i,f=r.use(),c=u({},f||{},null!==(i=t(n,e,f))&&void 0!==i?i:e);return r.run(Object.freeze(c),o)}}export{i as createCascade,o as createContext};
@@ -1 +0,0 @@
1
- {"type":"module"}
@@ -1,73 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vest-utils')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'vest-utils'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.context = {}, global["vest-utils"]));
5
- })(this, (function (exports, vestUtils) { 'use strict';
6
-
7
- var USEX_DEFAULT_ERROR_MESSAGE = 'Not inside of a running context.';
8
- var EMPTY_CONTEXT = Symbol();
9
- /**
10
- * Base context interface.
11
- */
12
- function createContext(defaultContextValue) {
13
- var contextValue = EMPTY_CONTEXT;
14
- return {
15
- run: run,
16
- use: use,
17
- useX: useX
18
- };
19
- function use() {
20
- return (isInsideContext() ? contextValue : defaultContextValue);
21
- }
22
- function useX(errorMessage) {
23
- vestUtils.invariant(isInsideContext(), vestUtils.defaultTo(errorMessage, USEX_DEFAULT_ERROR_MESSAGE));
24
- return contextValue;
25
- }
26
- function run(value, cb) {
27
- var parentContext = isInsideContext() ? use() : EMPTY_CONTEXT;
28
- contextValue = value;
29
- var res = cb();
30
- contextValue = parentContext;
31
- return res;
32
- }
33
- function isInsideContext() {
34
- return contextValue !== EMPTY_CONTEXT;
35
- }
36
- }
37
- /**
38
- * Cascading context - another implementation of context, that assumes the context value is an object.
39
- * When nesting context runs, the the values of the current layer merges with the layers above it.
40
- */
41
- function createCascade(init) {
42
- var ctx = createContext();
43
- return {
44
- bind: bind,
45
- run: run,
46
- use: ctx.use,
47
- useX: ctx.useX
48
- };
49
- function run(value, fn) {
50
- var _a;
51
- var parentContext = ctx.use();
52
- var out = vestUtils.assign({}, parentContext ? parentContext : {}, (_a = vestUtils.optionalFunctionValue(init, value, parentContext)) !== null && _a !== void 0 ? _a : value);
53
- return ctx.run(Object.freeze(out), fn);
54
- }
55
- function bind(value, fn) {
56
- return function () {
57
- var runTimeArgs = [];
58
- for (var _i = 0; _i < arguments.length; _i++) {
59
- runTimeArgs[_i] = arguments[_i];
60
- }
61
- return run(value, function () {
62
- return fn.apply(void 0, runTimeArgs);
63
- });
64
- };
65
- }
66
- }
67
-
68
- exports.createCascade = createCascade;
69
- exports.createContext = createContext;
70
-
71
- Object.defineProperty(exports, '__esModule', { value: true });
72
-
73
- }));
@@ -1 +0,0 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("vest-utils")):"function"==typeof define&&define.amd?define(["exports","vest-utils"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).context={},e["vest-utils"])}(this,(function(e,n){"use strict";var t=Symbol();function u(e){var u=t;return{run:function(e,n){var i=o()?r():t;u=e;var f=n();return u=i,f},use:r,useX:function(e){return n.invariant(o(),n.defaultTo(e,"Not inside of a running context.")),u}};function r(){return o()?u:e}function o(){return u!==t}}e.createCascade=function(e){var t=u();return{bind:function(e,n){return function(){for(var t=[],u=0;u<arguments.length;u++)t[u]=arguments[u];return r(e,(function(){return n.apply(void 0,t)}))}},run:r,use:t.use,useX:t.useX};function r(u,r){var o,i=t.use(),f=n.assign({},i||{},null!==(o=n.optionalFunctionValue(e,u,i))&&void 0!==o?o:u);return t.run(Object.freeze(f),r)}},e.createContext=u,Object.defineProperty(e,"__esModule",{value:!0})}));
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "rootDir": ".",
4
- "compilerOptions": {
5
- "baseUrl": ".",
6
- "declarationDir": "./types",
7
- "declarationMap": true,
8
- "outDir": "./dist",
9
- "paths": {
10
- "context": ["src/context.ts"]
11
- }
12
- }
13
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,MAAW,MAAM,YAAY,CAAC;AAWrC;;GAEG;AACH,iBAAgB,aAAa,CAAC,CAAC,SAAS,OAAO,EAC7C,mBAAmB,CAAC,EAAE,CAAC,GACtB,MAAM,CAAC,CAAC,CAAC,CAmCX;AAED;;;GAGG;AACH,iBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7D,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,GAAG,IAAI,KAAK,CAAC,GAAG,IAAI,GAC9D,aAAa,CAAC,CAAC,CAAC,CA6BlB;AAED,KAAK,qBAAqB,CAAC,CAAC,IAAI;IAC9B,GAAG,EAAE,MAAM,CAAC,CAAC;IACb,IAAI,EAAE,CAAC,YAAY,CAAC,EAAE,MAAM,KAAK,CAAC,CAAC;CACpC,CAAC;AAEF,KAAY,MAAM,CAAC,CAAC,IAAI,qBAAqB,CAAC,CAAC,CAAC,GAAG;IACjD,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;CACtC,CAAC;AAEF,KAAY,aAAa,CAAC,CAAC,IAAI,qBAAqB,CAAC,CAAC,CAAC,GAAG;IACxD,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9C,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;CACxD,CAAC"}