context 3.0.7 → 3.0.8-dev-9c596e
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/dist/cjs/context.development.js +16 -20
- package/dist/cjs/context.production.js +1 -1
- package/dist/es/context.development.js +16 -20
- package/dist/es/context.production.js +1 -1
- package/dist/umd/context.development.js +16 -20
- package/dist/umd/context.production.js +1 -1
- package/package.json +2 -2
- package/types/context.d.ts +1 -1
- package/types/context.d.ts.map +1 -1
|
@@ -4,17 +4,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var vestUtils = require('vest-utils');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const USEX_DEFAULT_ERROR_MESSAGE = 'Not inside of a running context.';
|
|
8
|
+
const EMPTY_CONTEXT = Symbol();
|
|
9
9
|
/**
|
|
10
10
|
* Base context interface.
|
|
11
11
|
*/
|
|
12
12
|
function createContext(defaultContextValue) {
|
|
13
|
-
|
|
13
|
+
let contextValue = EMPTY_CONTEXT;
|
|
14
14
|
return {
|
|
15
|
-
run
|
|
16
|
-
use
|
|
17
|
-
useX
|
|
15
|
+
run,
|
|
16
|
+
use,
|
|
17
|
+
useX,
|
|
18
18
|
};
|
|
19
19
|
function use() {
|
|
20
20
|
return (isInsideContext() ? contextValue : defaultContextValue);
|
|
@@ -24,9 +24,9 @@ function createContext(defaultContextValue) {
|
|
|
24
24
|
return contextValue;
|
|
25
25
|
}
|
|
26
26
|
function run(value, cb) {
|
|
27
|
-
|
|
27
|
+
const parentContext = isInsideContext() ? use() : EMPTY_CONTEXT;
|
|
28
28
|
contextValue = value;
|
|
29
|
-
|
|
29
|
+
const res = cb();
|
|
30
30
|
contextValue = parentContext;
|
|
31
31
|
return res;
|
|
32
32
|
}
|
|
@@ -39,27 +39,23 @@ function createContext(defaultContextValue) {
|
|
|
39
39
|
* When nesting context runs, the the values of the current layer merges with the layers above it.
|
|
40
40
|
*/
|
|
41
41
|
function createCascade(init) {
|
|
42
|
-
|
|
42
|
+
const ctx = createContext();
|
|
43
43
|
return {
|
|
44
|
-
bind
|
|
45
|
-
run
|
|
44
|
+
bind,
|
|
45
|
+
run,
|
|
46
46
|
use: ctx.use,
|
|
47
|
-
useX: ctx.useX
|
|
47
|
+
useX: ctx.useX,
|
|
48
48
|
};
|
|
49
49
|
function run(value, fn) {
|
|
50
50
|
var _a;
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
const parentContext = ctx.use();
|
|
52
|
+
const out = vestUtils.assign({}, parentContext ? parentContext : {}, (_a = vestUtils.optionalFunctionValue(init, value, parentContext)) !== null && _a !== void 0 ? _a : value);
|
|
53
53
|
return ctx.run(Object.freeze(out), fn);
|
|
54
54
|
}
|
|
55
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
|
-
}
|
|
56
|
+
return function (...runTimeArgs) {
|
|
61
57
|
return run(value, function () {
|
|
62
|
-
return fn
|
|
58
|
+
return fn(...runTimeArgs);
|
|
63
59
|
});
|
|
64
60
|
};
|
|
65
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("vest-utils"),e=Symbol();function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("vest-utils");const t="Not inside of a running context.",e=Symbol();function u(u){let r=e;return{run:function(n,t){const u=i()?o():e;r=n;const s=t();return r=u,s},use:o,useX:function(e){return n.invariant(i(),n.defaultTo(e,t)),r}};function o(){return i()?r:u}function i(){return r!==e}}exports.createCascade=function(t){const e=u();return{bind:function(n,t){return function(...e){return r(n,(function(){return t(...e)}))}},run:r,use:e.use,useX:e.useX};function r(u,r){var o;const i=e.use(),s=n.assign({},i||{},null!==(o=n.optionalFunctionValue(t,u,i))&&void 0!==o?o:u);return e.run(Object.freeze(s),r)}},exports.createContext=u;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { invariant, defaultTo, assign, optionalFunctionValue } from 'vest-utils';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const USEX_DEFAULT_ERROR_MESSAGE = 'Not inside of a running context.';
|
|
4
|
+
const EMPTY_CONTEXT = Symbol();
|
|
5
5
|
/**
|
|
6
6
|
* Base context interface.
|
|
7
7
|
*/
|
|
8
8
|
function createContext(defaultContextValue) {
|
|
9
|
-
|
|
9
|
+
let contextValue = EMPTY_CONTEXT;
|
|
10
10
|
return {
|
|
11
|
-
run
|
|
12
|
-
use
|
|
13
|
-
useX
|
|
11
|
+
run,
|
|
12
|
+
use,
|
|
13
|
+
useX,
|
|
14
14
|
};
|
|
15
15
|
function use() {
|
|
16
16
|
return (isInsideContext() ? contextValue : defaultContextValue);
|
|
@@ -20,9 +20,9 @@ function createContext(defaultContextValue) {
|
|
|
20
20
|
return contextValue;
|
|
21
21
|
}
|
|
22
22
|
function run(value, cb) {
|
|
23
|
-
|
|
23
|
+
const parentContext = isInsideContext() ? use() : EMPTY_CONTEXT;
|
|
24
24
|
contextValue = value;
|
|
25
|
-
|
|
25
|
+
const res = cb();
|
|
26
26
|
contextValue = parentContext;
|
|
27
27
|
return res;
|
|
28
28
|
}
|
|
@@ -35,27 +35,23 @@ function createContext(defaultContextValue) {
|
|
|
35
35
|
* When nesting context runs, the the values of the current layer merges with the layers above it.
|
|
36
36
|
*/
|
|
37
37
|
function createCascade(init) {
|
|
38
|
-
|
|
38
|
+
const ctx = createContext();
|
|
39
39
|
return {
|
|
40
|
-
bind
|
|
41
|
-
run
|
|
40
|
+
bind,
|
|
41
|
+
run,
|
|
42
42
|
use: ctx.use,
|
|
43
|
-
useX: ctx.useX
|
|
43
|
+
useX: ctx.useX,
|
|
44
44
|
};
|
|
45
45
|
function run(value, fn) {
|
|
46
46
|
var _a;
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
const parentContext = ctx.use();
|
|
48
|
+
const out = assign({}, parentContext ? parentContext : {}, (_a = optionalFunctionValue(init, value, parentContext)) !== null && _a !== void 0 ? _a : value);
|
|
49
49
|
return ctx.run(Object.freeze(out), fn);
|
|
50
50
|
}
|
|
51
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
|
-
}
|
|
52
|
+
return function (...runTimeArgs) {
|
|
57
53
|
return run(value, function () {
|
|
58
|
-
return fn
|
|
54
|
+
return fn(...runTimeArgs);
|
|
59
55
|
});
|
|
60
56
|
};
|
|
61
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{invariant as n,defaultTo as
|
|
1
|
+
import{invariant as n,defaultTo as t,assign as u,optionalFunctionValue as r}from"vest-utils";const e="Not inside of a running context.",o=Symbol();function c(u){let r=o;return{run:function(n,t){const u=i()?c():o;r=n;const e=t();return r=u,e},use:c,useX:function(u){return n(i(),t(u,e)),r}};function c(){return i()?r:u}function i(){return r!==o}}function i(n){const t=c();return{bind:function(n,t){return function(...u){return e(n,(function(){return t(...u)}))}},run:e,use:t.use,useX:t.useX};function e(e,o){var c;const i=t.use(),s=u({},i||{},null!==(c=r(n,e,i))&&void 0!==c?c:e);return t.run(Object.freeze(s),o)}}export{i as createCascade,c as createContext};
|
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.context = {}, global["vest-utils"]));
|
|
5
5
|
})(this, (function (exports, vestUtils) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const USEX_DEFAULT_ERROR_MESSAGE = 'Not inside of a running context.';
|
|
8
|
+
const EMPTY_CONTEXT = Symbol();
|
|
9
9
|
/**
|
|
10
10
|
* Base context interface.
|
|
11
11
|
*/
|
|
12
12
|
function createContext(defaultContextValue) {
|
|
13
|
-
|
|
13
|
+
let contextValue = EMPTY_CONTEXT;
|
|
14
14
|
return {
|
|
15
|
-
run
|
|
16
|
-
use
|
|
17
|
-
useX
|
|
15
|
+
run,
|
|
16
|
+
use,
|
|
17
|
+
useX,
|
|
18
18
|
};
|
|
19
19
|
function use() {
|
|
20
20
|
return (isInsideContext() ? contextValue : defaultContextValue);
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
return contextValue;
|
|
25
25
|
}
|
|
26
26
|
function run(value, cb) {
|
|
27
|
-
|
|
27
|
+
const parentContext = isInsideContext() ? use() : EMPTY_CONTEXT;
|
|
28
28
|
contextValue = value;
|
|
29
|
-
|
|
29
|
+
const res = cb();
|
|
30
30
|
contextValue = parentContext;
|
|
31
31
|
return res;
|
|
32
32
|
}
|
|
@@ -39,27 +39,23 @@
|
|
|
39
39
|
* When nesting context runs, the the values of the current layer merges with the layers above it.
|
|
40
40
|
*/
|
|
41
41
|
function createCascade(init) {
|
|
42
|
-
|
|
42
|
+
const ctx = createContext();
|
|
43
43
|
return {
|
|
44
|
-
bind
|
|
45
|
-
run
|
|
44
|
+
bind,
|
|
45
|
+
run,
|
|
46
46
|
use: ctx.use,
|
|
47
|
-
useX: ctx.useX
|
|
47
|
+
useX: ctx.useX,
|
|
48
48
|
};
|
|
49
49
|
function run(value, fn) {
|
|
50
50
|
var _a;
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
const parentContext = ctx.use();
|
|
52
|
+
const out = vestUtils.assign({}, parentContext ? parentContext : {}, (_a = vestUtils.optionalFunctionValue(init, value, parentContext)) !== null && _a !== void 0 ? _a : value);
|
|
53
53
|
return ctx.run(Object.freeze(out), fn);
|
|
54
54
|
}
|
|
55
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
|
-
}
|
|
56
|
+
return function (...runTimeArgs) {
|
|
61
57
|
return run(value, function () {
|
|
62
|
-
return fn
|
|
58
|
+
return fn(...runTimeArgs);
|
|
63
59
|
});
|
|
64
60
|
};
|
|
65
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e
|
|
1
|
+
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("vest-utils")):"function"==typeof define&&define.amd?define(["exports","vest-utils"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).context={},n["vest-utils"])}(this,(function(n,e){"use strict";const t="Not inside of a running context.",u=Symbol();function o(n){let o=u;return{run:function(n,e){const t=r()?i():u;o=n;const s=e();return o=t,s},use:i,useX:function(n){return e.invariant(r(),e.defaultTo(n,t)),o}};function i(){return r()?o:n}function r(){return o!==u}}n.createCascade=function(n){const t=o();return{bind:function(n,e){return function(...t){return u(n,(function(){return e(...t)}))}},run:u,use:t.use,useX:t.useX};function u(u,o){var i;const r=t.use(),s=e.assign({},r||{},null!==(i=e.optionalFunctionValue(n,u,r))&&void 0!==i?i:u);return t.run(Object.freeze(s),o)}},n.createContext=o,Object.defineProperty(n,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.0.
|
|
2
|
+
"version": "3.0.8-dev-9c596e",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "./dist/cjs/context.js",
|
|
5
5
|
"types": "./types/context.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"release": "vx release"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"vest-utils": "
|
|
14
|
+
"vest-utils": "1.0.0-dev-9c596e"
|
|
15
15
|
},
|
|
16
16
|
"module": "./dist/es/context.production.js",
|
|
17
17
|
"exports": {
|
package/types/context.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { CB } from 'vest-utils';
|
|
|
2
2
|
/**
|
|
3
3
|
* Base context interface.
|
|
4
4
|
*/
|
|
5
|
-
declare function createContext<T
|
|
5
|
+
declare function createContext<T>(defaultContextValue?: T): CtxApi<T>;
|
|
6
6
|
/**
|
|
7
7
|
* Cascading context - another implementation of context, that assumes the context value is an object.
|
|
8
8
|
* When nesting context runs, the the values of the current layer merges with the layers above it.
|
package/types/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,EAAE,mBAAmB,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAmCnE;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"}
|