react-hooks-global-states 16.0.0 → 16.0.1-beta
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/GlobalStore.cjs +1 -525
- package/GlobalStore.debugProps.cjs +1 -28
- package/GlobalStore.debugProps.js +1 -28
- package/GlobalStore.debugProps.mjs +1 -7
- package/GlobalStore.js +1 -525
- package/GlobalStore.mjs +1 -497
- package/actions.cjs +1 -61
- package/actions.d.ts +3 -3
- package/actions.js +1 -61
- package/actions.mjs +1 -30
- package/bundle.cjs +1 -40
- package/bundle.js +1 -40
- package/bundle.mjs +1 -19
- package/createContext.cjs +1 -253
- package/createContext.js +1 -253
- package/createContext.mjs +1 -235
- package/createGlobalState.cjs +1 -29
- package/createGlobalState.js +1 -29
- package/createGlobalState.mjs +1 -8
- package/isRecord.cjs +1 -46
- package/isRecord.js +1 -46
- package/isRecord.mjs +1 -15
- package/package.json +1 -1
- package/shallowCompare.cjs +1 -115
- package/shallowCompare.js +1 -115
- package/shallowCompare.mjs +1 -84
- package/throwWrongKeyOnActionCollectionConfig.cjs +4 -33
- package/throwWrongKeyOnActionCollectionConfig.js +4 -33
- package/throwWrongKeyOnActionCollectionConfig.mjs +4 -12
- package/types.cjs +1 -18
- package/types.d.ts +21 -3
- package/types.js +1 -18
- package/uniqueId.cjs +1 -72
- package/uniqueId.js +1 -72
- package/uniqueId.mjs +1 -51
package/actions.mjs
CHANGED
|
@@ -1,30 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import GlobalStore from "./GlobalStore.mjs";
|
|
3
|
-
function actions(api, actions2) {
|
|
4
|
-
const getStoreActionsMap = (api$, actions$) => {
|
|
5
|
-
const newApi = {
|
|
6
|
-
// prevents overriding api context
|
|
7
|
-
setMetadata: (...args) => api$.setMetadata(...args),
|
|
8
|
-
getMetadata: () => api$.getMetadata(),
|
|
9
|
-
getState: () => api$.getState(),
|
|
10
|
-
setState: (...args) => api$.setState(...args),
|
|
11
|
-
subscribe: (...args) => api$.subscribe(...args),
|
|
12
|
-
actionsConfig: actions$,
|
|
13
|
-
actions: null
|
|
14
|
-
};
|
|
15
|
-
const { storeTools, actions: newActions } = GlobalStore.prototype.getStoreActionsMap.call(newApi);
|
|
16
|
-
storeTools.actions = api$.actions;
|
|
17
|
-
return newActions;
|
|
18
|
-
};
|
|
19
|
-
if (api && actions2) {
|
|
20
|
-
return getStoreActionsMap(api, actions2);
|
|
21
|
-
}
|
|
22
|
-
return (actions$) => {
|
|
23
|
-
return (api$) => getStoreActionsMap(api$, actions$);
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
var actions_default = actions;
|
|
27
|
-
export {
|
|
28
|
-
actions,
|
|
29
|
-
actions_default as default
|
|
30
|
-
};
|
|
1
|
+
import c from"./GlobalStore.mjs";function p(o,i){let s=(t,n)=>{let A={setMetadata:(...e)=>t.setMetadata(...e),get metadata(){return t.getMetadata()},getMetadata:()=>t.getMetadata(),getState:()=>t.getState(),setState:(...e)=>t.setState(...e),subscribe:(...e)=>t.subscribe(...e),actionsConfig:n,actions:null},{storeTools:a,actions:r}=c.prototype.getStoreActionsMap.call(A);return a.actions=t.actions,r};return o&&i?s(o,i):t=>n=>s(n,t)}var d=p;export{p as actions,d as default};
|
package/bundle.cjs
CHANGED
|
@@ -1,40 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
GlobalStore: () => import_GlobalStore.GlobalStore,
|
|
24
|
-
actions: () => import_actions.actions,
|
|
25
|
-
createContext: () => import_createContext.createContext,
|
|
26
|
-
createGlobalState: () => import_createGlobalState.createGlobalState,
|
|
27
|
-
isRecord: () => import_isRecord.isRecord,
|
|
28
|
-
shallowCompare: () => import_shallowCompare.shallowCompare,
|
|
29
|
-
throwWrongKeyOnActionCollectionConfig: () => import_throwWrongKeyOnActionCollectionConfig.throwWrongKeyOnActionCollectionConfig,
|
|
30
|
-
uniqueId: () => import_uniqueId.uniqueId
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(src_exports);
|
|
33
|
-
var import_GlobalStore = require("./GlobalStore.cjs");
|
|
34
|
-
var import_createGlobalState = require("./createGlobalState.cjs");
|
|
35
|
-
var import_shallowCompare = require("./shallowCompare.cjs");
|
|
36
|
-
var import_uniqueId = require("./uniqueId.cjs");
|
|
37
|
-
var import_throwWrongKeyOnActionCollectionConfig = require("./throwWrongKeyOnActionCollectionConfig.cjs");
|
|
38
|
-
var import_isRecord = require("./isRecord.cjs");
|
|
39
|
-
var import_actions = require("./actions.cjs");
|
|
40
|
-
var import_createContext = require("./createContext.cjs");
|
|
1
|
+
"use strict";var n=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var u=(t,o)=>{for(var a in o)n(t,a,{get:o[a],enumerable:!0})},d=(t,o,a,l)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of f(o))!A.call(t,e)&&e!==a&&n(t,e,{get:()=>o[e],enumerable:!(l=p(o,e))||l.enumerable});return t};var k=t=>d(n({},"__esModule",{value:!0}),t);var m={};u(m,{GlobalStore:()=>r.GlobalStore,actions:()=>x.actions,createContext:()=>S.createContext,createGlobalState:()=>i.createGlobalState,isRecord:()=>b.isRecord,shallowCompare:()=>C.shallowCompare,throwWrongKeyOnActionCollectionConfig:()=>s.throwWrongKeyOnActionCollectionConfig,uniqueId:()=>c.uniqueId});module.exports=k(m);var r=require("./GlobalStore.cjs"),i=require("./createGlobalState.cjs"),C=require("./shallowCompare.cjs"),c=require("./uniqueId.cjs"),s=require("./throwWrongKeyOnActionCollectionConfig.cjs"),b=require("./isRecord.cjs"),x=require("./actions.cjs"),S=require("./createContext.cjs");
|
package/bundle.js
CHANGED
|
@@ -1,40 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
GlobalStore: () => import_GlobalStore.GlobalStore,
|
|
24
|
-
actions: () => import_actions.actions,
|
|
25
|
-
createContext: () => import_createContext.createContext,
|
|
26
|
-
createGlobalState: () => import_createGlobalState.createGlobalState,
|
|
27
|
-
isRecord: () => import_isRecord.isRecord,
|
|
28
|
-
shallowCompare: () => import_shallowCompare.shallowCompare,
|
|
29
|
-
throwWrongKeyOnActionCollectionConfig: () => import_throwWrongKeyOnActionCollectionConfig.throwWrongKeyOnActionCollectionConfig,
|
|
30
|
-
uniqueId: () => import_uniqueId.uniqueId
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(src_exports);
|
|
33
|
-
var import_GlobalStore = require("./GlobalStore.js");
|
|
34
|
-
var import_createGlobalState = require("./createGlobalState.js");
|
|
35
|
-
var import_shallowCompare = require("./shallowCompare.js");
|
|
36
|
-
var import_uniqueId = require("./uniqueId.js");
|
|
37
|
-
var import_throwWrongKeyOnActionCollectionConfig = require("./throwWrongKeyOnActionCollectionConfig.js");
|
|
38
|
-
var import_isRecord = require("./isRecord.js");
|
|
39
|
-
var import_actions = require("./actions.js");
|
|
40
|
-
var import_createContext = require("./createContext.js");
|
|
1
|
+
"use strict";var n=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var u=(t,o)=>{for(var a in o)n(t,a,{get:o[a],enumerable:!0})},d=(t,o,a,l)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of f(o))!A.call(t,e)&&e!==a&&n(t,e,{get:()=>o[e],enumerable:!(l=p(o,e))||l.enumerable});return t};var k=t=>d(n({},"__esModule",{value:!0}),t);var m={};u(m,{GlobalStore:()=>r.GlobalStore,actions:()=>x.actions,createContext:()=>S.createContext,createGlobalState:()=>i.createGlobalState,isRecord:()=>b.isRecord,shallowCompare:()=>C.shallowCompare,throwWrongKeyOnActionCollectionConfig:()=>s.throwWrongKeyOnActionCollectionConfig,uniqueId:()=>c.uniqueId});module.exports=k(m);var r=require("./GlobalStore.js"),i=require("./createGlobalState.js"),C=require("./shallowCompare.js"),c=require("./uniqueId.js"),s=require("./throwWrongKeyOnActionCollectionConfig.js"),b=require("./isRecord.js"),x=require("./actions.js"),S=require("./createContext.js");
|
package/bundle.mjs
CHANGED
|
@@ -1,19 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { GlobalStore } from "./GlobalStore.mjs";
|
|
3
|
-
import { createGlobalState } from "./createGlobalState.mjs";
|
|
4
|
-
import { shallowCompare } from "./shallowCompare.mjs";
|
|
5
|
-
import { uniqueId } from "./uniqueId.mjs";
|
|
6
|
-
import { throwWrongKeyOnActionCollectionConfig } from "./throwWrongKeyOnActionCollectionConfig.mjs";
|
|
7
|
-
import { isRecord } from "./isRecord.mjs";
|
|
8
|
-
import { actions } from "./actions.mjs";
|
|
9
|
-
import { createContext } from "./createContext.mjs";
|
|
10
|
-
export {
|
|
11
|
-
GlobalStore,
|
|
12
|
-
actions,
|
|
13
|
-
createContext,
|
|
14
|
-
createGlobalState,
|
|
15
|
-
isRecord,
|
|
16
|
-
shallowCompare,
|
|
17
|
-
throwWrongKeyOnActionCollectionConfig,
|
|
18
|
-
uniqueId
|
|
19
|
-
};
|
|
1
|
+
import{GlobalStore as e}from"./GlobalStore.mjs";import{createGlobalState as n}from"./createGlobalState.mjs";import{shallowCompare as r}from"./shallowCompare.mjs";import{uniqueId as C}from"./uniqueId.mjs";import{throwWrongKeyOnActionCollectionConfig as s}from"./throwWrongKeyOnActionCollectionConfig.mjs";import{isRecord as x}from"./isRecord.mjs";import{actions as p}from"./actions.mjs";import{createContext as A}from"./createContext.mjs";export{e as GlobalStore,p as actions,A as createContext,n as createGlobalState,x as isRecord,r as shallowCompare,s as throwWrongKeyOnActionCollectionConfig,C as uniqueId};
|
package/createContext.cjs
CHANGED
|
@@ -1,253 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __objRest = (source, exclude) => {
|
|
26
|
-
var target = {};
|
|
27
|
-
for (var prop in source)
|
|
28
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
if (source != null && __getOwnPropSymbols)
|
|
31
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
|
-
var __export = (target, all) => {
|
|
38
|
-
for (var name in all)
|
|
39
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
-
};
|
|
41
|
-
var __copyProps = (to, from, except, desc) => {
|
|
42
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
-
for (let key of __getOwnPropNames(from))
|
|
44
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
-
}
|
|
47
|
-
return to;
|
|
48
|
-
};
|
|
49
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
-
mod
|
|
56
|
-
));
|
|
57
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
-
|
|
59
|
-
// src/createContext.ts
|
|
60
|
-
var createContext_exports = {};
|
|
61
|
-
__export(createContext_exports, {
|
|
62
|
-
createContext: () => createContext,
|
|
63
|
-
default: () => createContext_default
|
|
64
|
-
});
|
|
65
|
-
module.exports = __toCommonJS(createContext_exports);
|
|
66
|
-
var import_react = require("react");
|
|
67
|
-
var import_GlobalStore = require("./GlobalStore.cjs");
|
|
68
|
-
var import_isFunction = __toESM(require("json-storage-formatter/isFunction"));
|
|
69
|
-
var import_uniqueId = __toESM(require("./uniqueId.cjs"));
|
|
70
|
-
var createContext = (valueArg, contextArgs = {}) => {
|
|
71
|
-
var _a;
|
|
72
|
-
const Context = (0, import_react.createContext)(null);
|
|
73
|
-
const contextIdentifier = (_a = contextArgs.name) != null ? _a : (0, import_uniqueId.default)("ctx:");
|
|
74
|
-
const getInheritedState = () => (0, import_isFunction.default)(valueArg) ? valueArg() : valueArg;
|
|
75
|
-
const hasValueProp = (props) => {
|
|
76
|
-
return Object.prototype.hasOwnProperty.call(props, "value");
|
|
77
|
-
};
|
|
78
|
-
const useProviderValue = (props) => {
|
|
79
|
-
var _a2;
|
|
80
|
-
(0, import_react.useDebugValue)(`${contextIdentifier}:Provider`);
|
|
81
|
-
const [store] = (0, import_react.useState)(() => {
|
|
82
|
-
var _a3, _b, _c, _d;
|
|
83
|
-
const initialValue = (() => {
|
|
84
|
-
if (hasValueProp(props))
|
|
85
|
-
return (0, import_isFunction.default)(props.value) ? props.value(getInheritedState()) : props.value;
|
|
86
|
-
return getInheritedState();
|
|
87
|
-
})();
|
|
88
|
-
const store2 = new import_GlobalStore.GlobalStore(initialValue, __spreadProps(__spreadValues({}, contextArgs), {
|
|
89
|
-
metadata: (_a3 = (0, import_isFunction.default)(contextArgs.metadata) ? contextArgs.metadata() : contextArgs.metadata) != null ? _a3 : {}
|
|
90
|
-
}));
|
|
91
|
-
const storeToolsExtensions = {
|
|
92
|
-
use
|
|
93
|
-
};
|
|
94
|
-
Object.assign(store2.storeTools, storeToolsExtensions);
|
|
95
|
-
(_c = (_b = contextArgs.callbacks) == null ? void 0 : _b.onCreated) == null ? void 0 : _c.call(
|
|
96
|
-
_b,
|
|
97
|
-
store2.storeTools,
|
|
98
|
-
store2
|
|
99
|
-
);
|
|
100
|
-
(_d = props.onCreated) == null ? void 0 : _d.call(props, store2.storeTools, store2);
|
|
101
|
-
return store2;
|
|
102
|
-
});
|
|
103
|
-
(0, import_react.useLayoutEffect)(() => {
|
|
104
|
-
const shouldUpdateState = hasValueProp(props) && !(0, import_isFunction.default)(props.value);
|
|
105
|
-
if (!shouldUpdateState) return;
|
|
106
|
-
store.setState(props.value);
|
|
107
|
-
}, [store, props.value]);
|
|
108
|
-
(0, import_react.useEffect)(() => {
|
|
109
|
-
var _a3, _b, _c;
|
|
110
|
-
const unsubscribes = [
|
|
111
|
-
(_b = (_a3 = contextArgs.callbacks) == null ? void 0 : _a3.onMounted) == null ? void 0 : _b.call(
|
|
112
|
-
_a3,
|
|
113
|
-
store.storeTools,
|
|
114
|
-
store
|
|
115
|
-
),
|
|
116
|
-
(_c = props.onMounted) == null ? void 0 : _c.call(props, store.storeTools, store)
|
|
117
|
-
].filter(Boolean);
|
|
118
|
-
return () => {
|
|
119
|
-
var _a4, _b2, _c2;
|
|
120
|
-
(_b2 = (_a4 = store.callbacks) == null ? void 0 : _a4.onUnMount) == null ? void 0 : _b2.call(_a4, store);
|
|
121
|
-
unsubscribes.forEach((unsubscribe) => unsubscribe == null ? void 0 : unsubscribe());
|
|
122
|
-
(_c2 = store.__onUnMountContext) == null ? void 0 : _c2.call(
|
|
123
|
-
store,
|
|
124
|
-
store
|
|
125
|
-
);
|
|
126
|
-
};
|
|
127
|
-
}, [store]);
|
|
128
|
-
(_a2 = props.onRender) == null ? void 0 : _a2.call(props, store.storeTools, store);
|
|
129
|
-
return store;
|
|
130
|
-
};
|
|
131
|
-
const Provider = (args) => {
|
|
132
|
-
const store = useProviderValue(args);
|
|
133
|
-
return (0, import_react.createElement)(Context.Provider, { value: store.use }, args.children);
|
|
134
|
-
};
|
|
135
|
-
Provider.displayName = `${contextIdentifier}:Provider`;
|
|
136
|
-
Context.displayName = `${contextIdentifier}`;
|
|
137
|
-
const providerExtensions = {
|
|
138
|
-
makeProviderWrapper: (parentOptions) => {
|
|
139
|
-
const context = {
|
|
140
|
-
current: void 0,
|
|
141
|
-
instance: void 0
|
|
142
|
-
};
|
|
143
|
-
const wrapper = (_a2) => {
|
|
144
|
-
var _b = _a2, { children } = _b, options = __objRest(_b, ["children"]);
|
|
145
|
-
return (0, import_react.createElement)(
|
|
146
|
-
Provider,
|
|
147
|
-
__spreadProps(__spreadValues(__spreadValues({}, parentOptions), options), {
|
|
148
|
-
onCreated: (ctx, store) => {
|
|
149
|
-
var _a3;
|
|
150
|
-
context.current = ctx;
|
|
151
|
-
context.instance = store;
|
|
152
|
-
(_a3 = parentOptions == null ? void 0 : parentOptions.onCreated) == null ? void 0 : _a3.call(parentOptions, ctx, store);
|
|
153
|
-
}
|
|
154
|
-
}),
|
|
155
|
-
children
|
|
156
|
-
);
|
|
157
|
-
};
|
|
158
|
-
return { wrapper, context };
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
const use = (...args) => {
|
|
162
|
-
(0, import_react.useDebugValue)(`${contextIdentifier}:use`);
|
|
163
|
-
const hook = (0, import_react.useContext)(Context);
|
|
164
|
-
if (!hook) throw new Error("use hook must be used within a ContextProvider");
|
|
165
|
-
return hook(...args);
|
|
166
|
-
};
|
|
167
|
-
const api = () => {
|
|
168
|
-
(0, import_react.useDebugValue)(`${contextIdentifier}:api`);
|
|
169
|
-
const hook = (0, import_react.useContext)(Context);
|
|
170
|
-
if (!hook) throw new Error("api hook must be used within a ContextProvider");
|
|
171
|
-
return hook;
|
|
172
|
-
};
|
|
173
|
-
const observable = (...args) => {
|
|
174
|
-
(0, import_react.useDebugValue)(`${contextIdentifier}:observable`);
|
|
175
|
-
const context = api();
|
|
176
|
-
const props = (0, import_react.useRef)(args);
|
|
177
|
-
props.current = args;
|
|
178
|
-
return (0, import_react.useMemo)(() => {
|
|
179
|
-
var _a2, _b, _c;
|
|
180
|
-
return context.createObservable(
|
|
181
|
-
(state) => {
|
|
182
|
-
const selector = props.current[0];
|
|
183
|
-
return selector(state);
|
|
184
|
-
},
|
|
185
|
-
{
|
|
186
|
-
// we call the equality in this way to execute always the latest version of the functions
|
|
187
|
-
// check if the root state changed
|
|
188
|
-
isEqualRoot: !((_a2 = props.current[1]) == null ? void 0 : _a2.isEqualRoot) ? void 0 : (current, next) => {
|
|
189
|
-
const isEqualRoot = props.current[1].isEqualRoot;
|
|
190
|
-
return Boolean(isEqualRoot(current, next));
|
|
191
|
-
},
|
|
192
|
-
// check if the selection changed
|
|
193
|
-
isEqual: !((_b = props.current[1]) == null ? void 0 : _b.isEqual) ? void 0 : (current, next) => {
|
|
194
|
-
const isEqual = props.current[1].isEqual;
|
|
195
|
-
return Boolean(isEqual(current, next));
|
|
196
|
-
},
|
|
197
|
-
name: (_c = props.current[1]) == null ? void 0 : _c.name
|
|
198
|
-
}
|
|
199
|
-
);
|
|
200
|
-
}, [context]);
|
|
201
|
-
};
|
|
202
|
-
const useExtensions = {
|
|
203
|
-
displayName: Context.displayName,
|
|
204
|
-
createSelectorHook: createSelectorHook.bind(use),
|
|
205
|
-
api,
|
|
206
|
-
select: (...args) => use(...args)[0],
|
|
207
|
-
observable,
|
|
208
|
-
actions: () => {
|
|
209
|
-
return api().actions;
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
Object.assign(Provider, providerExtensions);
|
|
213
|
-
Object.assign(use, useExtensions);
|
|
214
|
-
return {
|
|
215
|
-
use,
|
|
216
|
-
Provider,
|
|
217
|
-
Context
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
function createSelectorHook(selector, hookConfig) {
|
|
221
|
-
var _a;
|
|
222
|
-
const selectorIdentifier = (_a = hookConfig == null ? void 0 : hookConfig.name) != null ? _a : (0, import_uniqueId.default)("sh:");
|
|
223
|
-
const use = (...selectorArgs) => {
|
|
224
|
-
const context = this.api();
|
|
225
|
-
(0, import_react.useDebugValue)(`${this.displayName}:selector`);
|
|
226
|
-
(0, import_react.useDebugValue)(`${selectorIdentifier}:use`);
|
|
227
|
-
return (0, import_react.useMemo)(() => {
|
|
228
|
-
return context.createSelectorHook(selector, hookConfig);
|
|
229
|
-
}, [context])(...selectorArgs);
|
|
230
|
-
};
|
|
231
|
-
const api = () => {
|
|
232
|
-
(0, import_react.useDebugValue)(`${this.displayName}:selector`);
|
|
233
|
-
(0, import_react.useDebugValue)(`${selectorIdentifier}:api`);
|
|
234
|
-
const context = this.api();
|
|
235
|
-
return (0, import_react.useMemo)(() => {
|
|
236
|
-
const observable = context.createObservable(selector, hookConfig);
|
|
237
|
-
return __spreadProps(__spreadValues({}, context), {
|
|
238
|
-
getState: () => observable.getState(),
|
|
239
|
-
subscribe: observable.subscribe.bind(observable),
|
|
240
|
-
createSelectorHook: import_GlobalStore.createSelectorHook.bind(observable),
|
|
241
|
-
createObservable: import_GlobalStore.createObservable.bind(observable)
|
|
242
|
-
});
|
|
243
|
-
}, [context]);
|
|
244
|
-
};
|
|
245
|
-
const publicExtensions = {
|
|
246
|
-
displayName: this.displayName,
|
|
247
|
-
createSelectorHook: createSelectorHook.bind(use),
|
|
248
|
-
api
|
|
249
|
-
};
|
|
250
|
-
Object.assign(use, publicExtensions);
|
|
251
|
-
return use;
|
|
252
|
-
}
|
|
253
|
-
var createContext_default = createContext;
|
|
1
|
+
"use strict";var G=Object.create;var M=Object.defineProperty,O=Object.defineProperties,F=Object.getOwnPropertyDescriptor,D=Object.getOwnPropertyDescriptors,L=Object.getOwnPropertyNames,H=Object.getOwnPropertySymbols,g=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var _=(t,e,o)=>e in t?M(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,P=(t,e)=>{for(var o in e||(e={}))h.call(e,o)&&_(t,o,e[o]);if(H)for(var o of H(e))$.call(e,o)&&_(t,o,e[o]);return t},p=(t,e)=>O(t,D(e));var q=(t,e)=>{var o={};for(var s in t)h.call(t,s)&&e.indexOf(s)<0&&(o[s]=t[s]);if(t!=null&&H)for(var s of H(t))e.indexOf(s)<0&&$.call(t,s)&&(o[s]=t[s]);return o};var z=(t,e)=>{for(var o in e)M(t,o,{get:e[o],enumerable:!0})},N=(t,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let C of L(e))!h.call(t,C)&&C!==o&&M(t,C,{get:()=>e[C],enumerable:!(s=F(e,C))||s.enumerable});return t};var U=(t,e,o)=>(o=t!=null?G(g(t)):{},N(e||!t||!t.__esModule?M(o,"default",{value:t,enumerable:!0}):o,t)),J=t=>N(M({},"__esModule",{value:!0}),t);var Q={};z(Q,{createContext:()=>I,default:()=>K});module.exports=J(Q);var a=require("react"),v=require("./GlobalStore.cjs"),B=U(require("json-storage-formatter/isFunction")),T=U(require("./uniqueId.cjs"));var I=(t,e={})=>{var A;let o=(0,a.createContext)(null),s=(A=e.name)!=null?A:(0,T.default)("ctx:"),C=()=>(0,B.default)(t)?t():t,f=n=>Object.prototype.hasOwnProperty.call(n,"value"),E=n=>{var d;(0,a.useDebugValue)(`${s}:Provider`);let[r]=(0,a.useState)(()=>{var u,l,S,m;let b=f(n)?(0,B.default)(n.value)?n.value(C()):n.value:C(),k={__devtools_isContextStore:!0},i=new v.GlobalStore(b,P(p(P({},e),{metadata:(u=(0,B.default)(e.metadata)?e.metadata():e.metadata)!=null?u:{}}),k)),c={use:y};return Object.assign(i.storeTools,c),(S=(l=e.callbacks)==null?void 0:l.onCreated)==null||S.call(l,i.storeTools,i),(m=n.onCreated)==null||m.call(n,i.storeTools,i),i});return(0,a.useLayoutEffect)(()=>{f(n)&&!(0,B.default)(n.value)&&r.setState(n.value)},[r,n.value]),(0,a.useEffect)(()=>{var k,i,c;let b=[(i=(k=e.callbacks)==null?void 0:k.onMounted)==null?void 0:i.call(k,r.storeTools,r),(c=n.onMounted)==null?void 0:c.call(n,r.storeTools,r)].filter(Boolean);return()=>{var u,l,S;(l=(u=r.callbacks)==null?void 0:u.onUnMount)==null||l.call(u,r),b.forEach(m=>m==null?void 0:m()),(S=r.__onUnMountContext)==null||S.call(r,r)}},[r]),(d=n.onRender)==null||d.call(n,r.storeTools,r),r},w=n=>{let r=E(n);return(0,a.createElement)(o.Provider,{value:r.use},n.children)};w.displayName=`${s}:Provider`,o.displayName=`${s}`;let x={makeProviderWrapper:n=>{let r={current:void 0,instance:void 0};return{wrapper:i=>{var c=i,{children:b}=c,k=q(c,["children"]);return(0,a.createElement)(w,p(P(P({},n),k),{onCreated:(u,l)=>{var S;r.current=u,r.instance=l,(S=n==null?void 0:n.onCreated)==null||S.call(n,u,l)}}),b)},context:r}}},y=(...n)=>{(0,a.useDebugValue)(`${s}:use`);let r=(0,a.useContext)(o);if(!r)throw new Error("use hook must be used within a ContextProvider");return r(...n)},R=()=>{(0,a.useDebugValue)(`${s}:api`);let n=(0,a.useContext)(o);if(!n)throw new Error("api hook must be used within a ContextProvider");return n},V=(...n)=>{(0,a.useDebugValue)(`${s}:observable`);let r=R(),d=(0,a.useRef)(n);return d.current=n,(0,a.useMemo)(()=>{var b,k,i;return r.createObservable(c=>{let u=d.current[0];return u(c)},{isEqualRoot:(b=d.current[1])!=null&&b.isEqualRoot?(c,u)=>{let l=d.current[1].isEqualRoot;return!!l(c,u)}:void 0,isEqual:(k=d.current[1])!=null&&k.isEqual?(c,u)=>{let l=d.current[1].isEqual;return!!l(c,u)}:void 0,name:(i=d.current[1])==null?void 0:i.name})},[r])},W={displayName:o.displayName,createSelectorHook:j.bind(y),api:R,select:(...n)=>y(...n)[0],observable:V,actions:()=>R().actions};return Object.assign(w,x),Object.assign(y,W),{use:y,Provider:w,Context:o}};function j(t,e){var E;let o=(E=e==null?void 0:e.name)!=null?E:(0,T.default)("sh:"),s=(...w)=>{let x=this.api();return(0,a.useDebugValue)(`${this.displayName}:selector`),(0,a.useDebugValue)(`${o}:use`),(0,a.useMemo)(()=>x.createSelectorHook(t,e),[x])(...w)},C=()=>{(0,a.useDebugValue)(`${this.displayName}:selector`),(0,a.useDebugValue)(`${o}:api`);let w=this.api();return(0,a.useMemo)(()=>{let x=w.createObservable(t,e);return p(P({},w),{getState:()=>x.getState(),subscribe:x.subscribe.bind(x),createSelectorHook:v.createSelectorHook.bind(x),createObservable:v.createObservable.bind(x)})},[w])},f={displayName:this.displayName,createSelectorHook:j.bind(s),api:C};return Object.assign(s,f),s}var K=I;
|
package/createContext.js
CHANGED
|
@@ -1,253 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __objRest = (source, exclude) => {
|
|
26
|
-
var target = {};
|
|
27
|
-
for (var prop in source)
|
|
28
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
if (source != null && __getOwnPropSymbols)
|
|
31
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
|
-
var __export = (target, all) => {
|
|
38
|
-
for (var name in all)
|
|
39
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
-
};
|
|
41
|
-
var __copyProps = (to, from, except, desc) => {
|
|
42
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
-
for (let key of __getOwnPropNames(from))
|
|
44
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
-
}
|
|
47
|
-
return to;
|
|
48
|
-
};
|
|
49
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
-
mod
|
|
56
|
-
));
|
|
57
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
-
|
|
59
|
-
// src/createContext.ts
|
|
60
|
-
var createContext_exports = {};
|
|
61
|
-
__export(createContext_exports, {
|
|
62
|
-
createContext: () => createContext,
|
|
63
|
-
default: () => createContext_default
|
|
64
|
-
});
|
|
65
|
-
module.exports = __toCommonJS(createContext_exports);
|
|
66
|
-
var import_react = require("react");
|
|
67
|
-
var import_GlobalStore = require("./GlobalStore.js");
|
|
68
|
-
var import_isFunction = __toESM(require("json-storage-formatter/isFunction"));
|
|
69
|
-
var import_uniqueId = __toESM(require("./uniqueId.js"));
|
|
70
|
-
var createContext = (valueArg, contextArgs = {}) => {
|
|
71
|
-
var _a;
|
|
72
|
-
const Context = (0, import_react.createContext)(null);
|
|
73
|
-
const contextIdentifier = (_a = contextArgs.name) != null ? _a : (0, import_uniqueId.default)("ctx:");
|
|
74
|
-
const getInheritedState = () => (0, import_isFunction.default)(valueArg) ? valueArg() : valueArg;
|
|
75
|
-
const hasValueProp = (props) => {
|
|
76
|
-
return Object.prototype.hasOwnProperty.call(props, "value");
|
|
77
|
-
};
|
|
78
|
-
const useProviderValue = (props) => {
|
|
79
|
-
var _a2;
|
|
80
|
-
(0, import_react.useDebugValue)(`${contextIdentifier}:Provider`);
|
|
81
|
-
const [store] = (0, import_react.useState)(() => {
|
|
82
|
-
var _a3, _b, _c, _d;
|
|
83
|
-
const initialValue = (() => {
|
|
84
|
-
if (hasValueProp(props))
|
|
85
|
-
return (0, import_isFunction.default)(props.value) ? props.value(getInheritedState()) : props.value;
|
|
86
|
-
return getInheritedState();
|
|
87
|
-
})();
|
|
88
|
-
const store2 = new import_GlobalStore.GlobalStore(initialValue, __spreadProps(__spreadValues({}, contextArgs), {
|
|
89
|
-
metadata: (_a3 = (0, import_isFunction.default)(contextArgs.metadata) ? contextArgs.metadata() : contextArgs.metadata) != null ? _a3 : {}
|
|
90
|
-
}));
|
|
91
|
-
const storeToolsExtensions = {
|
|
92
|
-
use
|
|
93
|
-
};
|
|
94
|
-
Object.assign(store2.storeTools, storeToolsExtensions);
|
|
95
|
-
(_c = (_b = contextArgs.callbacks) == null ? void 0 : _b.onCreated) == null ? void 0 : _c.call(
|
|
96
|
-
_b,
|
|
97
|
-
store2.storeTools,
|
|
98
|
-
store2
|
|
99
|
-
);
|
|
100
|
-
(_d = props.onCreated) == null ? void 0 : _d.call(props, store2.storeTools, store2);
|
|
101
|
-
return store2;
|
|
102
|
-
});
|
|
103
|
-
(0, import_react.useLayoutEffect)(() => {
|
|
104
|
-
const shouldUpdateState = hasValueProp(props) && !(0, import_isFunction.default)(props.value);
|
|
105
|
-
if (!shouldUpdateState) return;
|
|
106
|
-
store.setState(props.value);
|
|
107
|
-
}, [store, props.value]);
|
|
108
|
-
(0, import_react.useEffect)(() => {
|
|
109
|
-
var _a3, _b, _c;
|
|
110
|
-
const unsubscribes = [
|
|
111
|
-
(_b = (_a3 = contextArgs.callbacks) == null ? void 0 : _a3.onMounted) == null ? void 0 : _b.call(
|
|
112
|
-
_a3,
|
|
113
|
-
store.storeTools,
|
|
114
|
-
store
|
|
115
|
-
),
|
|
116
|
-
(_c = props.onMounted) == null ? void 0 : _c.call(props, store.storeTools, store)
|
|
117
|
-
].filter(Boolean);
|
|
118
|
-
return () => {
|
|
119
|
-
var _a4, _b2, _c2;
|
|
120
|
-
(_b2 = (_a4 = store.callbacks) == null ? void 0 : _a4.onUnMount) == null ? void 0 : _b2.call(_a4, store);
|
|
121
|
-
unsubscribes.forEach((unsubscribe) => unsubscribe == null ? void 0 : unsubscribe());
|
|
122
|
-
(_c2 = store.__onUnMountContext) == null ? void 0 : _c2.call(
|
|
123
|
-
store,
|
|
124
|
-
store
|
|
125
|
-
);
|
|
126
|
-
};
|
|
127
|
-
}, [store]);
|
|
128
|
-
(_a2 = props.onRender) == null ? void 0 : _a2.call(props, store.storeTools, store);
|
|
129
|
-
return store;
|
|
130
|
-
};
|
|
131
|
-
const Provider = (args) => {
|
|
132
|
-
const store = useProviderValue(args);
|
|
133
|
-
return (0, import_react.createElement)(Context.Provider, { value: store.use }, args.children);
|
|
134
|
-
};
|
|
135
|
-
Provider.displayName = `${contextIdentifier}:Provider`;
|
|
136
|
-
Context.displayName = `${contextIdentifier}`;
|
|
137
|
-
const providerExtensions = {
|
|
138
|
-
makeProviderWrapper: (parentOptions) => {
|
|
139
|
-
const context = {
|
|
140
|
-
current: void 0,
|
|
141
|
-
instance: void 0
|
|
142
|
-
};
|
|
143
|
-
const wrapper = (_a2) => {
|
|
144
|
-
var _b = _a2, { children } = _b, options = __objRest(_b, ["children"]);
|
|
145
|
-
return (0, import_react.createElement)(
|
|
146
|
-
Provider,
|
|
147
|
-
__spreadProps(__spreadValues(__spreadValues({}, parentOptions), options), {
|
|
148
|
-
onCreated: (ctx, store) => {
|
|
149
|
-
var _a3;
|
|
150
|
-
context.current = ctx;
|
|
151
|
-
context.instance = store;
|
|
152
|
-
(_a3 = parentOptions == null ? void 0 : parentOptions.onCreated) == null ? void 0 : _a3.call(parentOptions, ctx, store);
|
|
153
|
-
}
|
|
154
|
-
}),
|
|
155
|
-
children
|
|
156
|
-
);
|
|
157
|
-
};
|
|
158
|
-
return { wrapper, context };
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
const use = (...args) => {
|
|
162
|
-
(0, import_react.useDebugValue)(`${contextIdentifier}:use`);
|
|
163
|
-
const hook = (0, import_react.useContext)(Context);
|
|
164
|
-
if (!hook) throw new Error("use hook must be used within a ContextProvider");
|
|
165
|
-
return hook(...args);
|
|
166
|
-
};
|
|
167
|
-
const api = () => {
|
|
168
|
-
(0, import_react.useDebugValue)(`${contextIdentifier}:api`);
|
|
169
|
-
const hook = (0, import_react.useContext)(Context);
|
|
170
|
-
if (!hook) throw new Error("api hook must be used within a ContextProvider");
|
|
171
|
-
return hook;
|
|
172
|
-
};
|
|
173
|
-
const observable = (...args) => {
|
|
174
|
-
(0, import_react.useDebugValue)(`${contextIdentifier}:observable`);
|
|
175
|
-
const context = api();
|
|
176
|
-
const props = (0, import_react.useRef)(args);
|
|
177
|
-
props.current = args;
|
|
178
|
-
return (0, import_react.useMemo)(() => {
|
|
179
|
-
var _a2, _b, _c;
|
|
180
|
-
return context.createObservable(
|
|
181
|
-
(state) => {
|
|
182
|
-
const selector = props.current[0];
|
|
183
|
-
return selector(state);
|
|
184
|
-
},
|
|
185
|
-
{
|
|
186
|
-
// we call the equality in this way to execute always the latest version of the functions
|
|
187
|
-
// check if the root state changed
|
|
188
|
-
isEqualRoot: !((_a2 = props.current[1]) == null ? void 0 : _a2.isEqualRoot) ? void 0 : (current, next) => {
|
|
189
|
-
const isEqualRoot = props.current[1].isEqualRoot;
|
|
190
|
-
return Boolean(isEqualRoot(current, next));
|
|
191
|
-
},
|
|
192
|
-
// check if the selection changed
|
|
193
|
-
isEqual: !((_b = props.current[1]) == null ? void 0 : _b.isEqual) ? void 0 : (current, next) => {
|
|
194
|
-
const isEqual = props.current[1].isEqual;
|
|
195
|
-
return Boolean(isEqual(current, next));
|
|
196
|
-
},
|
|
197
|
-
name: (_c = props.current[1]) == null ? void 0 : _c.name
|
|
198
|
-
}
|
|
199
|
-
);
|
|
200
|
-
}, [context]);
|
|
201
|
-
};
|
|
202
|
-
const useExtensions = {
|
|
203
|
-
displayName: Context.displayName,
|
|
204
|
-
createSelectorHook: createSelectorHook.bind(use),
|
|
205
|
-
api,
|
|
206
|
-
select: (...args) => use(...args)[0],
|
|
207
|
-
observable,
|
|
208
|
-
actions: () => {
|
|
209
|
-
return api().actions;
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
Object.assign(Provider, providerExtensions);
|
|
213
|
-
Object.assign(use, useExtensions);
|
|
214
|
-
return {
|
|
215
|
-
use,
|
|
216
|
-
Provider,
|
|
217
|
-
Context
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
function createSelectorHook(selector, hookConfig) {
|
|
221
|
-
var _a;
|
|
222
|
-
const selectorIdentifier = (_a = hookConfig == null ? void 0 : hookConfig.name) != null ? _a : (0, import_uniqueId.default)("sh:");
|
|
223
|
-
const use = (...selectorArgs) => {
|
|
224
|
-
const context = this.api();
|
|
225
|
-
(0, import_react.useDebugValue)(`${this.displayName}:selector`);
|
|
226
|
-
(0, import_react.useDebugValue)(`${selectorIdentifier}:use`);
|
|
227
|
-
return (0, import_react.useMemo)(() => {
|
|
228
|
-
return context.createSelectorHook(selector, hookConfig);
|
|
229
|
-
}, [context])(...selectorArgs);
|
|
230
|
-
};
|
|
231
|
-
const api = () => {
|
|
232
|
-
(0, import_react.useDebugValue)(`${this.displayName}:selector`);
|
|
233
|
-
(0, import_react.useDebugValue)(`${selectorIdentifier}:api`);
|
|
234
|
-
const context = this.api();
|
|
235
|
-
return (0, import_react.useMemo)(() => {
|
|
236
|
-
const observable = context.createObservable(selector, hookConfig);
|
|
237
|
-
return __spreadProps(__spreadValues({}, context), {
|
|
238
|
-
getState: () => observable.getState(),
|
|
239
|
-
subscribe: observable.subscribe.bind(observable),
|
|
240
|
-
createSelectorHook: import_GlobalStore.createSelectorHook.bind(observable),
|
|
241
|
-
createObservable: import_GlobalStore.createObservable.bind(observable)
|
|
242
|
-
});
|
|
243
|
-
}, [context]);
|
|
244
|
-
};
|
|
245
|
-
const publicExtensions = {
|
|
246
|
-
displayName: this.displayName,
|
|
247
|
-
createSelectorHook: createSelectorHook.bind(use),
|
|
248
|
-
api
|
|
249
|
-
};
|
|
250
|
-
Object.assign(use, publicExtensions);
|
|
251
|
-
return use;
|
|
252
|
-
}
|
|
253
|
-
var createContext_default = createContext;
|
|
1
|
+
"use strict";var G=Object.create;var M=Object.defineProperty,O=Object.defineProperties,F=Object.getOwnPropertyDescriptor,D=Object.getOwnPropertyDescriptors,L=Object.getOwnPropertyNames,H=Object.getOwnPropertySymbols,g=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var _=(t,e,o)=>e in t?M(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,P=(t,e)=>{for(var o in e||(e={}))h.call(e,o)&&_(t,o,e[o]);if(H)for(var o of H(e))$.call(e,o)&&_(t,o,e[o]);return t},p=(t,e)=>O(t,D(e));var q=(t,e)=>{var o={};for(var s in t)h.call(t,s)&&e.indexOf(s)<0&&(o[s]=t[s]);if(t!=null&&H)for(var s of H(t))e.indexOf(s)<0&&$.call(t,s)&&(o[s]=t[s]);return o};var z=(t,e)=>{for(var o in e)M(t,o,{get:e[o],enumerable:!0})},N=(t,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let C of L(e))!h.call(t,C)&&C!==o&&M(t,C,{get:()=>e[C],enumerable:!(s=F(e,C))||s.enumerable});return t};var U=(t,e,o)=>(o=t!=null?G(g(t)):{},N(e||!t||!t.__esModule?M(o,"default",{value:t,enumerable:!0}):o,t)),J=t=>N(M({},"__esModule",{value:!0}),t);var Q={};z(Q,{createContext:()=>I,default:()=>K});module.exports=J(Q);var a=require("react"),v=require("./GlobalStore.js"),B=U(require("json-storage-formatter/isFunction")),T=U(require("./uniqueId.js"));var I=(t,e={})=>{var A;let o=(0,a.createContext)(null),s=(A=e.name)!=null?A:(0,T.default)("ctx:"),C=()=>(0,B.default)(t)?t():t,f=n=>Object.prototype.hasOwnProperty.call(n,"value"),E=n=>{var d;(0,a.useDebugValue)(`${s}:Provider`);let[r]=(0,a.useState)(()=>{var u,l,S,m;let b=f(n)?(0,B.default)(n.value)?n.value(C()):n.value:C(),k={__devtools_isContextStore:!0},i=new v.GlobalStore(b,P(p(P({},e),{metadata:(u=(0,B.default)(e.metadata)?e.metadata():e.metadata)!=null?u:{}}),k)),c={use:y};return Object.assign(i.storeTools,c),(S=(l=e.callbacks)==null?void 0:l.onCreated)==null||S.call(l,i.storeTools,i),(m=n.onCreated)==null||m.call(n,i.storeTools,i),i});return(0,a.useLayoutEffect)(()=>{f(n)&&!(0,B.default)(n.value)&&r.setState(n.value)},[r,n.value]),(0,a.useEffect)(()=>{var k,i,c;let b=[(i=(k=e.callbacks)==null?void 0:k.onMounted)==null?void 0:i.call(k,r.storeTools,r),(c=n.onMounted)==null?void 0:c.call(n,r.storeTools,r)].filter(Boolean);return()=>{var u,l,S;(l=(u=r.callbacks)==null?void 0:u.onUnMount)==null||l.call(u,r),b.forEach(m=>m==null?void 0:m()),(S=r.__onUnMountContext)==null||S.call(r,r)}},[r]),(d=n.onRender)==null||d.call(n,r.storeTools,r),r},w=n=>{let r=E(n);return(0,a.createElement)(o.Provider,{value:r.use},n.children)};w.displayName=`${s}:Provider`,o.displayName=`${s}`;let x={makeProviderWrapper:n=>{let r={current:void 0,instance:void 0};return{wrapper:i=>{var c=i,{children:b}=c,k=q(c,["children"]);return(0,a.createElement)(w,p(P(P({},n),k),{onCreated:(u,l)=>{var S;r.current=u,r.instance=l,(S=n==null?void 0:n.onCreated)==null||S.call(n,u,l)}}),b)},context:r}}},y=(...n)=>{(0,a.useDebugValue)(`${s}:use`);let r=(0,a.useContext)(o);if(!r)throw new Error("use hook must be used within a ContextProvider");return r(...n)},R=()=>{(0,a.useDebugValue)(`${s}:api`);let n=(0,a.useContext)(o);if(!n)throw new Error("api hook must be used within a ContextProvider");return n},V=(...n)=>{(0,a.useDebugValue)(`${s}:observable`);let r=R(),d=(0,a.useRef)(n);return d.current=n,(0,a.useMemo)(()=>{var b,k,i;return r.createObservable(c=>{let u=d.current[0];return u(c)},{isEqualRoot:(b=d.current[1])!=null&&b.isEqualRoot?(c,u)=>{let l=d.current[1].isEqualRoot;return!!l(c,u)}:void 0,isEqual:(k=d.current[1])!=null&&k.isEqual?(c,u)=>{let l=d.current[1].isEqual;return!!l(c,u)}:void 0,name:(i=d.current[1])==null?void 0:i.name})},[r])},W={displayName:o.displayName,createSelectorHook:j.bind(y),api:R,select:(...n)=>y(...n)[0],observable:V,actions:()=>R().actions};return Object.assign(w,x),Object.assign(y,W),{use:y,Provider:w,Context:o}};function j(t,e){var E;let o=(E=e==null?void 0:e.name)!=null?E:(0,T.default)("sh:"),s=(...w)=>{let x=this.api();return(0,a.useDebugValue)(`${this.displayName}:selector`),(0,a.useDebugValue)(`${o}:use`),(0,a.useMemo)(()=>x.createSelectorHook(t,e),[x])(...w)},C=()=>{(0,a.useDebugValue)(`${this.displayName}:selector`),(0,a.useDebugValue)(`${o}:api`);let w=this.api();return(0,a.useMemo)(()=>{let x=w.createObservable(t,e);return p(P({},w),{getState:()=>x.getState(),subscribe:x.subscribe.bind(x),createSelectorHook:v.createSelectorHook.bind(x),createObservable:v.createObservable.bind(x)})},[w])},f={displayName:this.displayName,createSelectorHook:j.bind(s),api:C};return Object.assign(s,f),s}var K=I;
|