react-hooks-global-states 15.0.16 → 15.0.17
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/createContext.js +1 -1
- package/package.json +4 -4
- package/types.d.ts +12 -13
- package/uniqueId.d.ts +2 -2
package/createContext.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t;e=this,t=(e,t,
|
|
1
|
+
var e,t;e=this,t=(e,t,o,r)=>(()=>{"use strict";var a={12:t=>{t.exports=e},78:e=>{e.exports=t},506:e=>{e.exports=o},695:function(e,t,o){var r=this&&this.__rest||function(e,t){var o={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var a=0;for(r=Object.getOwnPropertySymbols(e);a<r.length;a++)t.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(e,r[a])&&(o[r[a]]=e[r[a]])}return o},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.createContext=void 0;const n=o(12),s=o(778),l=a(o(506)),u=a(o(78));function i(e,t){var o;const r=null!==(o=null==t?void 0:t.name)&&void 0!==o?o:(0,u.default)("sh:"),a=(...o)=>{const a=this.api();return(0,n.useDebugValue)(`${this.displayName}:selector`),(0,n.useDebugValue)(`${r}:use`),(0,n.useMemo)((()=>a.createSelectorHook(e,t)),[a])(...o)},l={displayName:this.displayName,createSelectorHook:i.bind(a),api:()=>{(0,n.useDebugValue)(`${this.displayName}:selector`),(0,n.useDebugValue)(`${r}:api`);const o=this.api();return(0,n.useMemo)((()=>{const r=o.createObservable(e,t);return Object.assign(Object.assign({},o),{getState:()=>r.getState(),subscribe:r.subscribe.bind(r),createSelectorHook:s.createSelectorHook.bind(r),createObservable:s.createObservable.bind(r)})}),[o])}};return Object.assign(a,l),a}t.createContext=(e,t={})=>{var o;const a=(0,n.createContext)(null),c=null!==(o=t.name)&&void 0!==o?o:(0,u.default)("ctx:"),d=()=>(0,l.default)(e)?e():e,v=e=>Object.prototype.hasOwnProperty.call(e,"value"),b=e=>{const o=(e=>{(0,n.useDebugValue)(`${c}:Provider`);const[o]=(0,n.useState)((()=>{var o,r,a,n;const u=v(e)?(0,l.default)(e.value)?e.value(d()):e.value:d(),i=new s.GlobalStore(u,Object.assign(Object.assign({},t),{metadata:null!==(o=(0,l.default)(t.metadata)?t.metadata():t.metadata)&&void 0!==o?o:{}})),c={use:f};return Object.assign(i.storeTools,c),null===(a=null===(r=t.callbacks)||void 0===r?void 0:r.onCreated)||void 0===a||a.call(r,i.storeTools,i),null===(n=e.onCreated)||void 0===n||n.call(e,i.storeTools,i),i}));return(0,n.useLayoutEffect)((()=>{v(e)&&!(0,l.default)(e.value)&&o.setState(e.value)}),[o,e.value]),(0,n.useEffect)((()=>{var r,a,n;const s=[null===(a=null===(r=t.callbacks)||void 0===r?void 0:r.onMounted)||void 0===a?void 0:a.call(r,o.storeTools,o),null===(n=e.onMounted)||void 0===n?void 0:n.call(e,o.storeTools,o)].filter(Boolean);return()=>{var e,t,r,a;null===(t=null===(e=o.callbacks)||void 0===e?void 0:e.onUnMount)||void 0===t||t.call(e,o),s.forEach((e=>null==e?void 0:e())),null===(a=(r=o).__onUnMountContext)||void 0===a||a.call(r,o)}}),[o]),o})(e);return(0,n.createElement)(a.Provider,{value:o.use},e.children)};b.displayName=`${c}:Provider`,a.displayName=`${c}`;const p={makeProviderWrapper:e=>{const t={current:void 0,instance:void 0};return{wrapper:o=>{var{children:a}=o,s=r(o,["children"]);return(0,n.createElement)(b,Object.assign(Object.assign(Object.assign({},e),s),{onCreated:(o,r)=>{var a;t.current=o,t.instance=r,null===(a=null==e?void 0:e.onCreated)||void 0===a||a.call(e,o,r)}}),a)},context:t}}},f=(...e)=>{(0,n.useDebugValue)(`${c}:use`);const t=(0,n.useContext)(a);if(!t)throw new Error("use hook must be used within a ContextProvider");return t(...e)},m=()=>{(0,n.useDebugValue)(`${c}:api`);const e=(0,n.useContext)(a);if(!e)throw new Error("api hook must be used within a ContextProvider");return e},j={displayName:a.displayName,createSelectorHook:i.bind(f),api:m,select:(...e)=>f(...e)[0],observable:(...e)=>{(0,n.useDebugValue)(`${c}:observable`);const t=m(),o=(0,n.useRef)(e);return o.current=e,(0,n.useMemo)((()=>{var e,r,a;return t.createObservable((e=>(0,o.current[0])(e)),{isEqualRoot:(null===(e=o.current[1])||void 0===e?void 0:e.isEqualRoot)?(e,t)=>{const r=o.current[1].isEqualRoot;return Boolean(r(e,t))}:void 0,isEqual:(null===(r=o.current[1])||void 0===r?void 0:r.isEqual)?(e,t)=>{const r=o.current[1].isEqual;return Boolean(r(e,t))}:void 0,name:null===(a=o.current[1])||void 0===a?void 0:a.name})}),[t])},actions:()=>m().actions};return Object.assign(b,p),Object.assign(f,j),{use:f,Provider:b,Context:a}},t.default=t.createContext},778:e=>{e.exports=r}},n={};return function e(t){var o=n[t];if(void 0!==o)return o.exports;var r=n[t]={exports:{}};return a[t].call(r.exports,r,r.exports,e),r.exports}(695)})(),"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("./uniqueId.js"),require("json-storage-formatter/isFunction"),require("./GlobalStore.js")):"function"==typeof define&&define.amd?define(["react","./uniqueId.js","json-storage-formatter/isFunction","./GlobalStore.js"],t):"object"==typeof exports?exports["react-hooks-global-states"]=t(require("react"),require("./uniqueId.js"),require("json-storage-formatter/isFunction"),require("./GlobalStore.js")):e["react-hooks-global-states"]=t(e.React,e["./uniqueId.js"],e["json-storage-formatter/isFunction"],e["./GlobalStore.js"]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-hooks-global-states",
|
|
3
|
-
"version": "15.0.
|
|
3
|
+
"version": "15.0.17",
|
|
4
4
|
"description": "A package to easily handle global state across your React components using hooks.",
|
|
5
5
|
"main": "./bundle.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -68,13 +68,13 @@
|
|
|
68
68
|
],
|
|
69
69
|
"scripts": {
|
|
70
70
|
"format": "prettier --write . --log-level silent && yarn lint:fix",
|
|
71
|
-
"test": "yarn build && yarn jest",
|
|
71
|
+
"test": "yarn build && yarn ts-check:tests && yarn jest",
|
|
72
72
|
"test:logs": "sh -c 'yarn build && yarn jest \"$@\" 2>&1 | grep -i \"console\" -A 2' --",
|
|
73
73
|
"test:debug:no-watch": "node --inspect-brk node_modules/.bin/jest --no-watchman --runInBand",
|
|
74
74
|
"test:debug": "node --inspect-brk node_modules/.bin/jest --watch --runInBand",
|
|
75
|
-
"test:quick": "yarn test --no-coverage --maxWorkers=4 -c --no-watchman -u",
|
|
75
|
+
"test:quick": "yarn ts-check:tests && yarn test --no-coverage --maxWorkers=4 -c --no-watchman -u",
|
|
76
76
|
"test:coverage": "yarn test --maxWorkers=4 -c --colors --no-watchman --verbose --coverage",
|
|
77
|
-
"build": "yarn ts-check && yarn clean && webpack --config webpack.config.js
|
|
77
|
+
"build": "yarn ts-check && yarn clean && webpack --config webpack.config.js",
|
|
78
78
|
"prepare": "yarn format && npm run build && yarn test:quick",
|
|
79
79
|
"version": "npm run format && yarn build && yarn jest && git add -A",
|
|
80
80
|
"postversion": "git push && git push --tags",
|
package/types.d.ts
CHANGED
|
@@ -1139,12 +1139,11 @@ export type InferActionsType<Hook extends StateHook<Any, Any, Any>> = ReturnType
|
|
|
1139
1139
|
* ```
|
|
1140
1140
|
*/
|
|
1141
1141
|
export type InferStateApi<Hook extends StateHook<Any, Any, Any>> = Hook extends StateHook<infer State, infer PublicStateMutator, infer Metadata> ? StoreTools<State, PublicStateMutator, Metadata> : never;
|
|
1142
|
-
export declare const __uniqueIdBrand: unique symbol;
|
|
1143
1142
|
/**
|
|
1144
1143
|
* Branded unique identifier
|
|
1145
1144
|
*/
|
|
1146
1145
|
export type BrandedId<T extends string | undefined> = `${T extends string ? T : ''}${string}` & {
|
|
1147
|
-
|
|
1146
|
+
__brand: T;
|
|
1148
1147
|
};
|
|
1149
1148
|
export interface UniqueId {
|
|
1150
1149
|
/**
|
|
@@ -1152,10 +1151,10 @@ export interface UniqueId {
|
|
|
1152
1151
|
*
|
|
1153
1152
|
* @example
|
|
1154
1153
|
* uniqueId(); // "k9j3n5x8q2"
|
|
1155
|
-
* type Id1 = `${string}` & {
|
|
1154
|
+
* type Id1 = `${string}` & { __brand: undefined };
|
|
1156
1155
|
*
|
|
1157
1156
|
* uniqueId('user:'); // "user:k9j3n5x8q2"
|
|
1158
|
-
* type Id2 = `user:${string}` & {
|
|
1157
|
+
* type Id2 = `user:${string}` & { __brand: 'user:' };
|
|
1159
1158
|
*/
|
|
1160
1159
|
<T extends string | undefined>(prefix?: T): BrandedId<T>;
|
|
1161
1160
|
/**
|
|
@@ -1164,36 +1163,36 @@ export interface UniqueId {
|
|
|
1164
1163
|
* @example
|
|
1165
1164
|
* const makeOrderId = uniqueId.for('order:');
|
|
1166
1165
|
* const id = makeOrderId(); // "order:k9j3n5x8q2"
|
|
1167
|
-
* type OrderId = `order:${string}` & {
|
|
1166
|
+
* type OrderId = `order:${string}` & { __brand: 'order:' };
|
|
1168
1167
|
*/
|
|
1169
1168
|
for<T extends string>(prefix: T): {
|
|
1170
1169
|
(): `${T}${string}` & {
|
|
1171
|
-
|
|
1170
|
+
__brand: T;
|
|
1172
1171
|
};
|
|
1173
1172
|
/**
|
|
1174
1173
|
* Checks if the given value matches the branded ID for this prefix.
|
|
1175
1174
|
*/
|
|
1176
1175
|
is(value: unknown): value is `${T}${string}` & {
|
|
1177
|
-
|
|
1176
|
+
__brand: T;
|
|
1178
1177
|
};
|
|
1179
1178
|
/**
|
|
1180
1179
|
* Asserts that the value matches this branded ID, throws otherwise.
|
|
1181
1180
|
*/
|
|
1182
1181
|
assert(value: unknown): asserts value is `${T}${string}` & {
|
|
1183
|
-
|
|
1182
|
+
__brand: T;
|
|
1184
1183
|
};
|
|
1185
1184
|
/**
|
|
1186
1185
|
* Returns a strictly branded generator using a custom symbol brand.
|
|
1187
1186
|
*/
|
|
1188
1187
|
strict<Brand extends symbol>(): {
|
|
1189
1188
|
(): `${T}${string}` & {
|
|
1190
|
-
|
|
1189
|
+
__brand: Brand;
|
|
1191
1190
|
};
|
|
1192
1191
|
is(value: unknown): value is `${T}${string}` & {
|
|
1193
|
-
|
|
1192
|
+
__brand: Brand;
|
|
1194
1193
|
};
|
|
1195
1194
|
assert(value: unknown): asserts value is `${T}${string}` & {
|
|
1196
|
-
|
|
1195
|
+
__brand: Brand;
|
|
1197
1196
|
};
|
|
1198
1197
|
};
|
|
1199
1198
|
};
|
|
@@ -1201,13 +1200,13 @@ export interface UniqueId {
|
|
|
1201
1200
|
* Creates a reusable unique ID generator without a prefix.
|
|
1202
1201
|
*/
|
|
1203
1202
|
of<T extends string>(): () => string & {
|
|
1204
|
-
|
|
1203
|
+
__brand: T;
|
|
1205
1204
|
};
|
|
1206
1205
|
/**
|
|
1207
1206
|
* Creates a strictly branded unique ID generator without a prefix.
|
|
1208
1207
|
*/
|
|
1209
1208
|
strict<Brand extends symbol>(): () => string & {
|
|
1210
|
-
|
|
1209
|
+
__brand: Brand;
|
|
1211
1210
|
};
|
|
1212
1211
|
}
|
|
1213
1212
|
/**
|
package/uniqueId.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { UniqueId, BrandedId
|
|
1
|
+
import type { UniqueId, BrandedId } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Generates a unique identifier string, optionally prefixed.
|
|
4
4
|
*/
|
|
5
5
|
export declare const uniqueId: UniqueId;
|
|
6
6
|
export default uniqueId;
|
|
7
|
-
export type { UniqueId, BrandedId
|
|
7
|
+
export type { UniqueId, BrandedId };
|