context 3.1.0-dev-c4ba9b → 4.0.0
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/README.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
# Context
|
|
1
|
+
# Context 🪆
|
|
2
|
+
|
|
3
|
+
[](https://discord.gg/WmADZpJnSe) [](https://www.npmjs.com/package/context) [](https://www.npmjs.com/package/context) [](https://bundlephobia.com/package/context) [](https://github.com/ealush/vest/actions)
|
|
2
4
|
|
|
3
5
|
Simple utility for context propagation within Javascript applications and libraries. Loosely based on the ideas behind React's context, allows you to achieve the same goals (and more) without actually using react.
|
|
4
6
|
It allows you to keep reference for shared variables, and access them down in your function call even if not declared in the same scope.
|
|
@@ -6,6 +6,9 @@ var vestUtils = require('vest-utils');
|
|
|
6
6
|
|
|
7
7
|
var USEX_DEFAULT_ERROR_MESSAGE = 'Not inside of a running context.';
|
|
8
8
|
var EMPTY_CONTEXT = Symbol();
|
|
9
|
+
/**
|
|
10
|
+
* Base context interface.
|
|
11
|
+
*/
|
|
9
12
|
function createContext(defaultContextValue) {
|
|
10
13
|
var contextValue = EMPTY_CONTEXT;
|
|
11
14
|
return {
|
|
@@ -31,6 +34,10 @@ function createContext(defaultContextValue) {
|
|
|
31
34
|
return contextValue !== EMPTY_CONTEXT;
|
|
32
35
|
}
|
|
33
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
|
+
*/
|
|
34
41
|
function createCascade(init) {
|
|
35
42
|
var ctx = createContext();
|
|
36
43
|
return {
|
|
@@ -2,6 +2,9 @@ import { invariant, defaultTo, assign, optionalFunctionValue } from 'vest-utils'
|
|
|
2
2
|
|
|
3
3
|
var USEX_DEFAULT_ERROR_MESSAGE = 'Not inside of a running context.';
|
|
4
4
|
var EMPTY_CONTEXT = Symbol();
|
|
5
|
+
/**
|
|
6
|
+
* Base context interface.
|
|
7
|
+
*/
|
|
5
8
|
function createContext(defaultContextValue) {
|
|
6
9
|
var contextValue = EMPTY_CONTEXT;
|
|
7
10
|
return {
|
|
@@ -27,6 +30,10 @@ function createContext(defaultContextValue) {
|
|
|
27
30
|
return contextValue !== EMPTY_CONTEXT;
|
|
28
31
|
}
|
|
29
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
|
+
*/
|
|
30
37
|
function createCascade(init) {
|
|
31
38
|
var ctx = createContext();
|
|
32
39
|
return {
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
var USEX_DEFAULT_ERROR_MESSAGE = 'Not inside of a running context.';
|
|
8
8
|
var EMPTY_CONTEXT = Symbol();
|
|
9
|
+
/**
|
|
10
|
+
* Base context interface.
|
|
11
|
+
*/
|
|
9
12
|
function createContext(defaultContextValue) {
|
|
10
13
|
var contextValue = EMPTY_CONTEXT;
|
|
11
14
|
return {
|
|
@@ -31,6 +34,10 @@
|
|
|
31
34
|
return contextValue !== EMPTY_CONTEXT;
|
|
32
35
|
}
|
|
33
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
|
+
*/
|
|
34
41
|
function createCascade(init) {
|
|
35
42
|
var ctx = createContext();
|
|
36
43
|
return {
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "
|
|
2
|
+
"version": "4.0.0",
|
|
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.
|
|
14
|
+
"vest-utils": "^0.0.5"
|
|
15
15
|
},
|
|
16
16
|
"module": "./dist/es/context.production.js",
|
|
17
17
|
"exports": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"default": "./dist/cjs/context.production.js"
|
|
37
37
|
},
|
|
38
38
|
"./package.json": "./package.json",
|
|
39
|
-
"
|
|
39
|
+
"./*": "./*"
|
|
40
40
|
},
|
|
41
41
|
"repository": {
|
|
42
42
|
"type": "git",
|
package/tsconfig.json
CHANGED
package/types/context.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { CB } from 'vest-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Base context interface.
|
|
4
|
+
*/
|
|
2
5
|
declare function createContext<T extends unknown>(defaultContextValue?: T): CtxApi<T>;
|
|
6
|
+
/**
|
|
7
|
+
* Cascading context - another implementation of context, that assumes the context value is an object.
|
|
8
|
+
* When nesting context runs, the the values of the current layer merges with the layers above it.
|
|
9
|
+
*/
|
|
3
10
|
declare function createCascade<T extends Record<string, unknown>>(init?: (value: Partial<T>, parentContext: T | void) => T | null): CtxCascadeApi<T>;
|
|
4
11
|
type ContextConsumptionApi<T> = {
|
|
5
12
|
use: () => T;
|
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,iBAAgB,aAAa,CAAC,CAAC,SAAS,OAAO,EAC7C,mBAAmB,CAAC,EAAE,CAAC,GACtB,MAAM,CAAC,CAAC,CAAC,CAmCX;AAED,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,KA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