context 3.0.5-dev-d315d9 → 3.0.5
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 +20 -16
- package/dist/cjs/context.production.js +1 -1
- package/dist/es/context.development.js +20 -16
- package/dist/es/context.production.js +1 -1
- package/dist/umd/context.development.js +20 -16
- package/dist/umd/context.production.js +1 -1
- package/package.json +2 -2
|
@@ -4,17 +4,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var vestUtils = require('vest-utils');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
var USEX_DEFAULT_ERROR_MESSAGE = 'Not inside of a running context.';
|
|
8
|
+
var EMPTY_CONTEXT = Symbol();
|
|
9
9
|
/**
|
|
10
10
|
* Base context interface.
|
|
11
11
|
*/
|
|
12
12
|
function createContext(defaultContextValue) {
|
|
13
|
-
|
|
13
|
+
var contextValue = EMPTY_CONTEXT;
|
|
14
14
|
return {
|
|
15
|
-
run,
|
|
16
|
-
use,
|
|
17
|
-
useX
|
|
15
|
+
run: run,
|
|
16
|
+
use: use,
|
|
17
|
+
useX: 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
|
+
var parentContext = isInsideContext() ? use() : EMPTY_CONTEXT;
|
|
28
28
|
contextValue = value;
|
|
29
|
-
|
|
29
|
+
var res = cb();
|
|
30
30
|
contextValue = parentContext;
|
|
31
31
|
return res;
|
|
32
32
|
}
|
|
@@ -39,23 +39,27 @@ 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
|
+
var ctx = createContext();
|
|
43
43
|
return {
|
|
44
|
-
bind,
|
|
45
|
-
run,
|
|
44
|
+
bind: bind,
|
|
45
|
+
run: 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
|
+
var parentContext = ctx.use();
|
|
52
|
+
var 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 (
|
|
56
|
+
return function () {
|
|
57
|
+
var runTimeArgs = [];
|
|
58
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
59
|
+
runTimeArgs[_i] = arguments[_i];
|
|
60
|
+
}
|
|
57
61
|
return run(value, function () {
|
|
58
|
-
return fn(
|
|
62
|
+
return fn.apply(void 0, runTimeArgs);
|
|
59
63
|
});
|
|
60
64
|
};
|
|
61
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n=require("vest-utils")
|
|
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,16 +1,16 @@
|
|
|
1
1
|
import { invariant, defaultTo, assign, optionalFunctionValue } from 'vest-utils';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
var USEX_DEFAULT_ERROR_MESSAGE = 'Not inside of a running context.';
|
|
4
|
+
var EMPTY_CONTEXT = Symbol();
|
|
5
5
|
/**
|
|
6
6
|
* Base context interface.
|
|
7
7
|
*/
|
|
8
8
|
function createContext(defaultContextValue) {
|
|
9
|
-
|
|
9
|
+
var contextValue = EMPTY_CONTEXT;
|
|
10
10
|
return {
|
|
11
|
-
run,
|
|
12
|
-
use,
|
|
13
|
-
useX
|
|
11
|
+
run: run,
|
|
12
|
+
use: use,
|
|
13
|
+
useX: 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
|
+
var parentContext = isInsideContext() ? use() : EMPTY_CONTEXT;
|
|
24
24
|
contextValue = value;
|
|
25
|
-
|
|
25
|
+
var res = cb();
|
|
26
26
|
contextValue = parentContext;
|
|
27
27
|
return res;
|
|
28
28
|
}
|
|
@@ -35,23 +35,27 @@ 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
|
+
var ctx = createContext();
|
|
39
39
|
return {
|
|
40
|
-
bind,
|
|
41
|
-
run,
|
|
40
|
+
bind: bind,
|
|
41
|
+
run: 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
|
+
var parentContext = ctx.use();
|
|
48
|
+
var 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 (
|
|
52
|
+
return function () {
|
|
53
|
+
var runTimeArgs = [];
|
|
54
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
55
|
+
runTimeArgs[_i] = arguments[_i];
|
|
56
|
+
}
|
|
53
57
|
return run(value, function () {
|
|
54
|
-
return fn(
|
|
58
|
+
return fn.apply(void 0, runTimeArgs);
|
|
55
59
|
});
|
|
56
60
|
};
|
|
57
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{invariant as n,defaultTo as
|
|
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};
|
|
@@ -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
|
+
var USEX_DEFAULT_ERROR_MESSAGE = 'Not inside of a running context.';
|
|
8
|
+
var EMPTY_CONTEXT = Symbol();
|
|
9
9
|
/**
|
|
10
10
|
* Base context interface.
|
|
11
11
|
*/
|
|
12
12
|
function createContext(defaultContextValue) {
|
|
13
|
-
|
|
13
|
+
var contextValue = EMPTY_CONTEXT;
|
|
14
14
|
return {
|
|
15
|
-
run,
|
|
16
|
-
use,
|
|
17
|
-
useX
|
|
15
|
+
run: run,
|
|
16
|
+
use: use,
|
|
17
|
+
useX: 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
|
+
var parentContext = isInsideContext() ? use() : EMPTY_CONTEXT;
|
|
28
28
|
contextValue = value;
|
|
29
|
-
|
|
29
|
+
var res = cb();
|
|
30
30
|
contextValue = parentContext;
|
|
31
31
|
return res;
|
|
32
32
|
}
|
|
@@ -39,23 +39,27 @@
|
|
|
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
|
+
var ctx = createContext();
|
|
43
43
|
return {
|
|
44
|
-
bind,
|
|
45
|
-
run,
|
|
44
|
+
bind: bind,
|
|
45
|
+
run: 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
|
+
var parentContext = ctx.use();
|
|
52
|
+
var 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 (
|
|
56
|
+
return function () {
|
|
57
|
+
var runTimeArgs = [];
|
|
58
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
59
|
+
runTimeArgs[_i] = arguments[_i];
|
|
60
|
+
}
|
|
57
61
|
return run(value, function () {
|
|
58
|
-
return fn(
|
|
62
|
+
return fn.apply(void 0, runTimeArgs);
|
|
59
63
|
});
|
|
60
64
|
};
|
|
61
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(n
|
|
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/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.0.5
|
|
2
|
+
"version": "3.0.5",
|
|
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": "^0.1.0
|
|
14
|
+
"vest-utils": "^0.1.0"
|
|
15
15
|
},
|
|
16
16
|
"module": "./dist/es/context.production.js",
|
|
17
17
|
"exports": {
|