@openmrs/esm-context 6.3.1-pre.2961 → 6.3.1-pre.2986
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/.swcrc +16 -0
- package/.turbo/turbo-build.log +3 -7
- package/dist/context.d.ts +37 -0
- package/dist/context.js +80 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/public.d.ts +1 -0
- package/dist/public.js +1 -0
- package/package.json +25 -14
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +3 -23
- package/dist/openmrs-esm-context.js +0 -2
- package/dist/openmrs-esm-context.js.map +0 -1
- package/jest.config.js +0 -10
- package/webpack.config.js +0 -42
package/.swcrc
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://swc.rs/schema.json",
|
|
3
|
+
"exclude": [".*\\.test\\..*", "setup-tests\\..*"],
|
|
4
|
+
"module": {
|
|
5
|
+
"type": "es6",
|
|
6
|
+
"resolveFully": true
|
|
7
|
+
},
|
|
8
|
+
"jsc": {
|
|
9
|
+
"parser": {
|
|
10
|
+
"syntax": "typescript",
|
|
11
|
+
"tsx": false
|
|
12
|
+
},
|
|
13
|
+
"target": "es2020",
|
|
14
|
+
"baseUrl": "src"
|
|
15
|
+
}
|
|
16
|
+
}
|
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
built modules 5.44 KiB [built]
|
|
5
|
-
./src/index.ts + 2 modules 5.4 KiB [built] [code generated]
|
|
6
|
-
external "@openmrs/esm-state" 42 bytes [built] [code generated]
|
|
7
|
-
webpack 5.88.0 compiled successfully in 11010 ms
|
|
1
|
+
[0] Successfully compiled: 3 files with swc (203.62ms)
|
|
2
|
+
[0] swc --strip-leading-paths src -d dist exited with code 0
|
|
3
|
+
[1] tsc --project tsconfig.build.json exited with code 0
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
interface OpenmrsAppContext {
|
|
2
|
+
[namespace: string]: unknown;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*
|
|
7
|
+
* The application context store, using immer to potentially simplify updates
|
|
8
|
+
*/
|
|
9
|
+
export declare const contextStore: import("zustand/vanilla").StoreApi<OpenmrsAppContext>;
|
|
10
|
+
/**
|
|
11
|
+
* Used by callers to register a new namespace in the application context. Attempting to register
|
|
12
|
+
* an already-registered namespace will display a warning and make no modifications to the state.
|
|
13
|
+
*
|
|
14
|
+
* @param namespace the namespace to register
|
|
15
|
+
* @param initialValue the initial value of the namespace
|
|
16
|
+
*/
|
|
17
|
+
export declare function registerContext<T extends {} = {}>(namespace: string, initialValue?: T): void;
|
|
18
|
+
/**
|
|
19
|
+
* Used by caller to unregister a namespace in the application context. Unregistering a namespace
|
|
20
|
+
* will remove the namespace and all associated data.
|
|
21
|
+
*/
|
|
22
|
+
export declare function unregisterContext(namespace: string): void;
|
|
23
|
+
export declare function getContext<T extends {} = {}>(namespace: string): Readonly<T> | null;
|
|
24
|
+
/**
|
|
25
|
+
* Updates a namespace in the global context. If the namespace does not exist, it is registered.
|
|
26
|
+
*/
|
|
27
|
+
export declare function updateContext<T extends {} = {}>(namespace: string, update: (state: T) => T): void;
|
|
28
|
+
export type ContextCallback<T extends {} = {}> = (state: Readonly<T> | null | undefined) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Subscribes to updates of a given namespace. Note that the returned object is immutable.
|
|
31
|
+
*
|
|
32
|
+
* @param namespace the namespace to subscribe to
|
|
33
|
+
* @param callback a function invoked with the current context whenever
|
|
34
|
+
* @returns A function to unsubscribe from the context
|
|
35
|
+
*/
|
|
36
|
+
export declare function subscribeToContext<T extends {} = {}>(namespace: string, callback: ContextCallback<T>): () => void;
|
|
37
|
+
export {};
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** @module @category Context */ 'use strict';
|
|
2
|
+
import { createStore } from "zustand/vanilla";
|
|
3
|
+
import { registerGlobalStore } from "@openmrs/esm-state";
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
*
|
|
7
|
+
* The application context store, using immer to potentially simplify updates
|
|
8
|
+
*/ export const contextStore = createStore()(()=>({}));
|
|
9
|
+
registerGlobalStore('openmrs-app-context', contextStore);
|
|
10
|
+
const nothing = Object();
|
|
11
|
+
/**
|
|
12
|
+
* Used by callers to register a new namespace in the application context. Attempting to register
|
|
13
|
+
* an already-registered namespace will display a warning and make no modifications to the state.
|
|
14
|
+
*
|
|
15
|
+
* @param namespace the namespace to register
|
|
16
|
+
* @param initialValue the initial value of the namespace
|
|
17
|
+
*/ export function registerContext(namespace, initialValue = nothing) {
|
|
18
|
+
contextStore.setState((state)=>{
|
|
19
|
+
if (namespace in state) {
|
|
20
|
+
throw new Error(`Attempted to re-register namespace ${namespace} in the app context. Each namespace must be unregistered before the name can be registered again.`);
|
|
21
|
+
}
|
|
22
|
+
return Object.assign({}, state, {
|
|
23
|
+
[namespace]: initialValue === nothing ? {} : initialValue
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Used by caller to unregister a namespace in the application context. Unregistering a namespace
|
|
29
|
+
* will remove the namespace and all associated data.
|
|
30
|
+
*/ export function unregisterContext(namespace) {
|
|
31
|
+
contextStore.setState((state)=>{
|
|
32
|
+
if (namespace in state) {
|
|
33
|
+
delete state[namespace];
|
|
34
|
+
}
|
|
35
|
+
return state;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns an _immutable_ version of the state of the namespace as it is currently
|
|
40
|
+
*
|
|
41
|
+
* @typeParam T The type of the value stored in the namespace
|
|
42
|
+
* @typeParam U The return type of this hook which is mostly relevant when using a selector
|
|
43
|
+
* @param namespace The namespace to load properties from
|
|
44
|
+
* @param selector An optional function which extracts the relevant part of the state
|
|
45
|
+
*/ export function getContext(namespace, selector = (state)=>state) {
|
|
46
|
+
const state = contextStore.getState();
|
|
47
|
+
if (namespace in state) {
|
|
48
|
+
return Object.freeze(Object.assign({}, selector ? selector(state[namespace]) : state[namespace]));
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Updates a namespace in the global context. If the namespace does not exist, it is registered.
|
|
54
|
+
*/ export function updateContext(namespace, update) {
|
|
55
|
+
contextStore.setState((state)=>{
|
|
56
|
+
if (!(namespace in state)) {
|
|
57
|
+
state[namespace] = {};
|
|
58
|
+
}
|
|
59
|
+
state[namespace] = update(state[namespace]);
|
|
60
|
+
return Object.assign({}, state);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Subscribes to updates of a given namespace. Note that the returned object is immutable.
|
|
65
|
+
*
|
|
66
|
+
* @param namespace the namespace to subscribe to
|
|
67
|
+
* @param callback a function invoked with the current context whenever
|
|
68
|
+
* @returns A function to unsubscribe from the context
|
|
69
|
+
*/ export function subscribeToContext(namespace, callback) {
|
|
70
|
+
let previous = getContext(namespace);
|
|
71
|
+
// set initial value
|
|
72
|
+
callback(Object.freeze(Object.assign({}, previous)));
|
|
73
|
+
return contextStore.subscribe((state)=>{
|
|
74
|
+
let current = namespace in state ? state[namespace] : null;
|
|
75
|
+
if (current !== previous) {
|
|
76
|
+
previous = current;
|
|
77
|
+
callback(Object.freeze(Object.assign({}, current)));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './context';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./context.js";
|
package/dist/public.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './context';
|
package/dist/public.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./context.js";
|
package/package.json
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-context",
|
|
3
|
-
"version": "6.3.1-pre.
|
|
3
|
+
"version": "6.3.1-pre.2986",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "Utilities for managing the current execution context",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"type": "module",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./src/index.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./src/public": {
|
|
15
|
+
"types": "./src/public.ts",
|
|
16
|
+
"default": "./dist/public.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
8
19
|
"source": true,
|
|
9
20
|
"sideEffects": false,
|
|
10
21
|
"scripts": {
|
|
11
|
-
"test": "cross-env TZ=UTC jest --
|
|
12
|
-
"test:watch": "cross-env TZ=UTC jest --watch --
|
|
13
|
-
"build": "
|
|
14
|
-
"build:development": "
|
|
15
|
-
"
|
|
16
|
-
"typescript": "tsc",
|
|
22
|
+
"test": "cross-env TZ=UTC jest --verbose false --passWithNoTests --color",
|
|
23
|
+
"test:watch": "cross-env TZ=UTC jest --watch --color",
|
|
24
|
+
"build": "rimraf dist && concurrently \"swc --strip-leading-paths src -d dist\" \"tsc --project tsconfig.build.json\"",
|
|
25
|
+
"build:development": "rimraf dist && concurrently \"swc --strip-leading-paths src -d dist\" \"tsc --project tsconfig.build.json\"",
|
|
26
|
+
"typescript": "tsc --project tsconfig.build.json",
|
|
17
27
|
"lint": "eslint src --ext ts,tsx"
|
|
18
28
|
},
|
|
19
29
|
"keywords": [
|
|
@@ -43,11 +53,12 @@
|
|
|
43
53
|
"@openmrs/esm-state": "6.x"
|
|
44
54
|
},
|
|
45
55
|
"devDependencies": {
|
|
46
|
-
"@openmrs/esm-globals": "6.3.1-pre.
|
|
47
|
-
"@openmrs/esm-state": "6.3.1-pre.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
56
|
+
"@openmrs/esm-globals": "6.3.1-pre.2986",
|
|
57
|
+
"@openmrs/esm-state": "6.3.1-pre.2986",
|
|
58
|
+
"@swc/cli": "^0.7.7",
|
|
59
|
+
"@swc/core": "^1.11.29",
|
|
60
|
+
"concurrently": "^9.1.2",
|
|
61
|
+
"rimraf": "^6.0.1"
|
|
51
62
|
},
|
|
52
63
|
"stableVersion": "6.3.0"
|
|
53
64
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,25 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"target": "es2015",
|
|
6
|
-
"allowSyntheticDefaultImports": true,
|
|
7
|
-
"jsx": "react",
|
|
8
|
-
"strictNullChecks": true,
|
|
9
|
-
"moduleResolution": "node",
|
|
10
|
-
"declaration": true,
|
|
11
|
-
"declarationDir": "dist",
|
|
12
|
-
"emitDeclarationOnly": true,
|
|
13
|
-
"lib": [
|
|
14
|
-
"dom",
|
|
15
|
-
"es5",
|
|
16
|
-
"scripthost",
|
|
17
|
-
"es2015",
|
|
18
|
-
"es2015.promise",
|
|
19
|
-
"es2016.array.include",
|
|
20
|
-
"es2018",
|
|
21
|
-
"esnext"
|
|
22
|
-
]
|
|
23
|
-
},
|
|
24
|
-
"include": ["src/**/*"]
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig.json",
|
|
3
|
+
"extends": "../tsconfig.json",
|
|
4
|
+
"include": ["src/**/*.ts*"]
|
|
25
5
|
}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
System.register(["@openmrs/esm-state"],(function(e,t){var r={};return{setters:[function(e){r.registerGlobalStore=e.registerGlobalStore}],execute:function(){e((()=>{"use strict";var e={685:e=>{e.exports=r}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{n.r(o),n.d(o,{contextStore:()=>i,getContext:()=>u,registerContext:()=>a,subscribeToContext:()=>l,unregisterContext:()=>c,updateContext:()=>b});const e=e=>{let t;const r=new Set,n=(e,n)=>{const o="function"==typeof e?e(t):e;if(!Object.is(o,t)){const e=t;t=(null!=n?n:"object"!=typeof o||null===o)?o:Object.assign({},t,o),r.forEach((r=>r(t,e)))}},o=()=>t,i={setState:n,getState:o,getInitialState:()=>s,subscribe:e=>(r.add(e),()=>r.delete(e)),destroy:()=>{console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),r.clear()}},s=t=e(n,o,i);return i};var t,r=n(685),i=(t?e(t):e)((function(){return{}}));(0,r.registerGlobalStore)("openmrs-app-context",i);var s=Object();function a(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;i.setState((function(r){if(e in r)throw new Error("Attempted to re-register namespace ".concat(e," in the app context. Each namespace must be unregistered before the name can be registered again."));return Object.assign({},r,(i=t===s?{}:t,(o=e)in(n={})?Object.defineProperty(n,o,{value:i,enumerable:!0,configurable:!0,writable:!0}):n[o]=i,n));var n,o,i}))}function c(e){i.setState((function(t){return e in t&&delete t[e],t}))}function u(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(e){return e},r=i.getState();return e in r?Object.freeze(Object.assign({},t?t(r[e]):r[e])):null}function b(e,t){i.setState((function(r){return e in r||(r[e]={}),r[e]=t(r[e]),Object.assign({},r)}))}function l(e,t){var r=u(e);return t(Object.freeze(Object.assign({},r))),i.subscribe((function(n){var o=e in n?n[e]:null;o!==r&&(r=o,t(Object.freeze(Object.assign({},o))))}))}})(),o})())}}}));
|
|
2
|
-
//# sourceMappingURL=openmrs-esm-context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openmrs-esm-context.js","mappings":"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","sources":["webpack://@openmrs/esm-context/external system \"@openmrs/esm-state\"","webpack://@openmrs/esm-context/webpack/bootstrap","webpack://@openmrs/esm-context/webpack/runtime/define property getters","webpack://@openmrs/esm-context/webpack/runtime/hasOwnProperty shorthand","webpack://@openmrs/esm-context/webpack/runtime/make namespace object","webpack://@openmrs/esm-context/../../../node_modules/zustand/esm/vanilla.mjs","webpack://@openmrs/esm-context/./src/context.ts"],"sourcesContent":["module.exports = __WEBPACK_EXTERNAL_MODULE__685__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","const createStoreImpl = (createState) => {\n let state;\n const listeners = /* @__PURE__ */ new Set();\n const setState = (partial, replace) => {\n const nextState = typeof partial === \"function\" ? partial(state) : partial;\n if (!Object.is(nextState, state)) {\n const previousState = state;\n state = (replace != null ? replace : typeof nextState !== \"object\" || nextState === null) ? nextState : Object.assign({}, state, nextState);\n listeners.forEach((listener) => listener(state, previousState));\n }\n };\n const getState = () => state;\n const getInitialState = () => initialState;\n const subscribe = (listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n };\n const destroy = () => {\n if ((import.meta.env ? import.meta.env.MODE : void 0) !== \"production\") {\n console.warn(\n \"[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected.\"\n );\n }\n listeners.clear();\n };\n const api = { setState, getState, getInitialState, subscribe, destroy };\n const initialState = state = createState(setState, getState, api);\n return api;\n};\nconst createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;\nvar vanilla = (createState) => {\n if ((import.meta.env ? import.meta.env.MODE : void 0) !== \"production\") {\n console.warn(\n \"[DEPRECATED] Default export is deprecated. Instead use import { createStore } from 'zustand/vanilla'.\"\n );\n }\n return createStore(createState);\n};\n\nexport { createStore, vanilla as default };\n","/** @module @category Context */\n'use strict';\n\nimport { createStore } from 'zustand/vanilla';\nimport { registerGlobalStore } from '@openmrs/esm-state';\n\ninterface OpenmrsAppContext {\n [namespace: string]: unknown;\n}\n\n/**\n * @internal\n *\n * The application context store, using immer to potentially simplify updates\n */\nexport const contextStore = createStore<OpenmrsAppContext>()(() => ({}));\n\nregisterGlobalStore<OpenmrsAppContext>('openmrs-app-context', contextStore);\n\nconst nothing = Object();\n\n/**\n * Used by callers to register a new namespace in the application context. Attempting to register\n * an already-registered namespace will display a warning and make no modifications to the state.\n *\n * @param namespace the namespace to register\n * @param initialValue the initial value of the namespace\n */\nexport function registerContext<T extends {} = {}>(namespace: string, initialValue: T = nothing) {\n contextStore.setState((state) => {\n if (namespace in state) {\n throw new Error(\n `Attempted to re-register namespace ${namespace} in the app context. Each namespace must be unregistered before the name can be registered again.`,\n );\n }\n\n return Object.assign({}, state, { [namespace]: initialValue === nothing ? {} : initialValue });\n });\n}\n\n/**\n * Used by caller to unregister a namespace in the application context. Unregistering a namespace\n * will remove the namespace and all associated data.\n */\nexport function unregisterContext(namespace: string) {\n contextStore.setState((state) => {\n if (namespace in state) {\n delete state[namespace];\n }\n return state;\n });\n}\n\nexport function getContext<T extends {} = {}>(namespace: string): Readonly<T> | null;\n/**\n * Returns an _immutable_ version of the state of the namespace as it is currently\n *\n * @typeParam T The type of the value stored in the namespace\n * @typeParam U The return type of this hook which is mostly relevant when using a selector\n * @param namespace The namespace to load properties from\n * @param selector An optional function which extracts the relevant part of the state\n */\nexport function getContext<T extends {} = {}, U extends {} = T>(\n namespace: string,\n selector: (state: Readonly<T>) => U = (state) => state as unknown as U,\n): Readonly<U> | null {\n const state = contextStore.getState();\n if (namespace in state) {\n return Object.freeze(Object.assign({}, (selector ? selector(state[namespace] as T) : state[namespace]) as U));\n }\n\n return null;\n}\n\n/**\n * Updates a namespace in the global context. If the namespace does not exist, it is registered.\n */\nexport function updateContext<T extends {} = {}>(namespace: string, update: (state: T) => T) {\n contextStore.setState((state) => {\n if (!(namespace in state)) {\n state[namespace] = {};\n }\n\n state[namespace] = update(state[namespace] as T);\n return Object.assign({}, state);\n });\n}\n\nexport type ContextCallback<T extends {} = {}> = (state: Readonly<T> | null | undefined) => void;\n\n/**\n * Subscribes to updates of a given namespace. Note that the returned object is immutable.\n *\n * @param namespace the namespace to subscribe to\n * @param callback a function invoked with the current context whenever\n * @returns A function to unsubscribe from the context\n */\nexport function subscribeToContext<T extends {} = {}>(namespace: string, callback: ContextCallback<T>) {\n let previous = getContext<T>(namespace);\n\n // set initial value\n callback(Object.freeze(Object.assign({}, previous)));\n\n return contextStore.subscribe((state) => {\n let current: Readonly<T> | null | undefined = namespace in state ? (state[namespace] as T) : null;\n\n if (current !== previous) {\n previous = current;\n callback(Object.freeze(Object.assign({}, current)));\n }\n });\n}\n"],"names":["module","exports","__WEBPACK_EXTERNAL_MODULE__685__","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","d","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","value","createStoreImpl","createState","state","listeners","Set","setState","partial","replace","nextState","is","previousState","assign","forEach","listener","getState","api","getInitialState","initialState","subscribe","add","delete","destroy","console","warn","clear","contextStore","registerGlobalStore","nothing","registerContext","namespace","initialValue","Error","unregisterContext","getContext","selector","freeze","updateContext","update","subscribeToContext","callback","previous","current"],"sourceRoot":""}
|
package/jest.config.js
DELETED
package/webpack.config.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
|
2
|
-
const { resolve, basename } = require('path');
|
|
3
|
-
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
|
4
|
-
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
|
5
|
-
|
|
6
|
-
const { browser, peerDependencies } = require('./package.json');
|
|
7
|
-
|
|
8
|
-
module.exports = (env) => ({
|
|
9
|
-
entry: [resolve(__dirname, 'src/index.ts')],
|
|
10
|
-
output: {
|
|
11
|
-
filename: basename(browser),
|
|
12
|
-
path: resolve(__dirname, 'dist'),
|
|
13
|
-
library: { type: 'system' },
|
|
14
|
-
},
|
|
15
|
-
devtool: 'source-map',
|
|
16
|
-
module: {
|
|
17
|
-
rules: [
|
|
18
|
-
{
|
|
19
|
-
test: /\.m?(js|ts|tsx)$/,
|
|
20
|
-
exclude: /node_modules/,
|
|
21
|
-
use: 'swc-loader',
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
externals: Object.keys(peerDependencies || {}),
|
|
26
|
-
resolve: {
|
|
27
|
-
extensions: ['.ts', '.js', '.tsx', '.jsx'],
|
|
28
|
-
},
|
|
29
|
-
plugins: [
|
|
30
|
-
new CleanWebpackPlugin(),
|
|
31
|
-
new ForkTsCheckerWebpackPlugin(),
|
|
32
|
-
new BundleAnalyzerPlugin({
|
|
33
|
-
analyzerMode: env && env.analyze ? 'static' : 'disabled',
|
|
34
|
-
}),
|
|
35
|
-
],
|
|
36
|
-
devServer: {
|
|
37
|
-
disableHostCheck: true,
|
|
38
|
-
headers: {
|
|
39
|
-
'Access-Control-Allow-Origin': '*',
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
});
|