@zayne-labs/toolkit-react 0.8.45 → 0.8.46

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.
@@ -10,7 +10,7 @@ declare const createZustandContext: <TState extends Record<string, unknown>, TUs
10
10
  } | {
11
11
  children: React.ReactNode;
12
12
  value: TUseBoundStore;
13
- }) => react.FunctionComponentElement<react.ProviderProps<TUseBoundStore | null>>, useBoundStore: <TResult>(selector: SelectorFn<TState, TResult>) => TResult];
13
+ }) => react.FunctionComponentElement<react.ProviderProps<TUseBoundStore | null>>, useBoundStore: <TResult = TState>(selector?: SelectorFn<TState, TResult>) => unknown];
14
14
 
15
15
  type Combine = <TInitialState extends AnyObject, TExtraState extends AnyObject, Mps extends Array<[StoreMutatorIdentifier, unknown]> = [], Mcs extends Array<[StoreMutatorIdentifier, unknown]> = []>(initialState: TInitialState, additionalStateCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>) => StateCreator<TExtraState & TInitialState>;
16
16
  declare const combine: Combine;
@@ -11,7 +11,10 @@ var createZustandContext = (options) => {
11
11
  );
12
12
  return createElement(Provider, { value: useZustandStore }, children);
13
13
  }
14
- const useBoundStore = (selector) => useCustomContext()(selector);
14
+ const useBoundStore = (selector) => {
15
+ const useZustandStore = useCustomContext();
16
+ return useZustandStore(selector);
17
+ };
15
18
  return [ZustandProvider, useBoundStore];
16
19
  };
17
20
  var combine = (initialState, storeCreator) => (
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/zustand/createZustandContext.ts","../../../src/zustand/createZustandStoreWithCombine.ts"],"names":[],"mappings":";;;;AAKM,IAAA,oBAAA,GAAuB,CAI5B,OACI,KAAA;AACJ,EAAA,MAAM,CAAC,QAAA,EAAU,gBAAgB,CAAA,GAAI,oBAAoB,OAAO,CAAA;AAYhE,EAAA,SAAS,gBAAgB,KAA6B,EAAA;AACrD,IAAA,MAAM,EAAE,QAAA,EAAU,GAAG,WAAA,EAAgB,GAAA,KAAA;AAErC,IAAA,MAAM,eAAkB,GAAA,WAAA;AAAA,MAAY,MACnC,cAAkB,IAAA,WAAA,GAAc,WAAY,CAAA,YAAA,KAAiB,WAAY,CAAA;AAAA,KAC1E;AAEA,IAAA,OAAO,cAAc,QAAU,EAAA,EAAE,KAAO,EAAA,eAAA,IAAmB,QAAQ,CAAA;AAAA;AAGpE,EAAA,MAAM,aAAgB,GAAA,CAAU,QAA0C,KAAA,gBAAA,GAAmB,QAAQ,CAAA;AAErG,EAAO,OAAA,CAAC,iBAAiB,aAAa,CAAA;AAIvC;AC1Ba,IAAA,OAAA,GACZ,CAAC,YAAc,EAAA,YAAA;AAAA;AAAA,EAEf,IAAI,MAAY,MAAA;AAAA,IACf,GAAG,YAAA;AAAA,IACH,GAAI,YAA6B,CAAA,GAAG,MAAM;AAAA,GAC3C;AAAA;AAEM,IAAM,yBAAyB,CAClC,GAAA,MAAA,KACC,YAAY,OAAQ,CAAA,GAAG,MAAM,CAAC;AAE5B,IAAM,oBAAoB,CAC7B,GAAA,MAAA,KACC,OAAO,OAAQ,CAAA,GAAG,MAAM,CAAC","file":"index.js","sourcesContent":["import type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createElement } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport { type CustomContextOptions, createCustomContext, useConstant } from \"../hooks\";\n\nconst createZustandContext = <\n\tTState extends Record<string, unknown>,\n\tTUseBoundStore extends UseBoundStore<StoreApi<TState>> = UseBoundStore<StoreApi<TState>>,\n>(\n\toptions?: CustomContextOptions<TUseBoundStore, true>\n) => {\n\tconst [Provider, useCustomContext] = createCustomContext(options);\n\n\ttype ZustandProviderProps =\n\t\t| {\n\t\t\t\tchildren: React.ReactNode;\n\t\t\t\tstoreCreator: () => TUseBoundStore;\n\t\t }\n\t\t| {\n\t\t\t\tchildren: React.ReactNode;\n\t\t\t\tvalue: TUseBoundStore;\n\t\t };\n\n\tfunction ZustandProvider(props: ZustandProviderProps) {\n\t\tconst { children, ...restOfProps } = props;\n\n\t\tconst useZustandStore = useConstant(() =>\n\t\t\t\"storeCreator\" in restOfProps ? restOfProps.storeCreator() : restOfProps.value\n\t\t);\n\n\t\treturn createElement(Provider, { value: useZustandStore }, children);\n\t}\n\n\tconst useBoundStore = <TResult>(selector: SelectorFn<TState, TResult>) => useCustomContext()(selector);\n\n\treturn [ZustandProvider, useBoundStore] as [\n\t\tZustandProvider: typeof ZustandProvider,\n\t\tuseBoundStore: typeof useBoundStore,\n\t];\n};\n\nexport { createZustandContext };\n","import type { AnyFunction, AnyObject } from \"@zayne-labs/toolkit-type-helpers\";\nimport { type StateCreator, type StoreMutatorIdentifier, create, createStore } from \"zustand\";\n\nexport type Combine = <\n\tTInitialState extends AnyObject,\n\tTExtraState extends AnyObject,\n\tMps extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\tMcs extends Array<[StoreMutatorIdentifier, unknown]> = [],\n>(\n\tinitialState: TInitialState,\n\tadditionalStateCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>\n) => StateCreator<TExtraState & TInitialState>;\n\nexport const combine: Combine =\n\t(initialState, storeCreator) =>\n\t// eslint-disable-next-line ts-eslint/no-unsafe-return -- We don't know what the storeCreator will return\n\t(...params) => ({\n\t\t...initialState,\n\t\t...(storeCreator as AnyFunction)(...params),\n\t});\n\nexport const createStoreWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => createStore(combine(...params));\n\nexport const createWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => create(combine(...params));\n"]}
1
+ {"version":3,"sources":["../../../src/zustand/createZustandContext.ts","../../../src/zustand/createZustandStoreWithCombine.ts"],"names":[],"mappings":";;;;AAKM,IAAA,oBAAA,GAAuB,CAI5B,OACI,KAAA;AACJ,EAAA,MAAM,CAAC,QAAA,EAAU,gBAAgB,CAAA,GAAI,oBAAoB,OAAO,CAAA;AAYhE,EAAA,SAAS,gBAAgB,KAA6B,EAAA;AACrD,IAAA,MAAM,EAAE,QAAA,EAAU,GAAG,WAAA,EAAgB,GAAA,KAAA;AAErC,IAAA,MAAM,eAAkB,GAAA,WAAA;AAAA,MAAY,MACnC,cAAkB,IAAA,WAAA,GAAc,WAAY,CAAA,YAAA,KAAiB,WAAY,CAAA;AAAA,KAC1E;AAEA,IAAA,OAAO,cAAc,QAAU,EAAA,EAAE,KAAO,EAAA,eAAA,IAAmB,QAAQ,CAAA;AAAA;AAGpE,EAAM,MAAA,aAAA,GAAgB,CAAmB,QAA2C,KAAA;AACnF,IAAA,MAAM,kBAAkB,gBAAiB,EAAA;AAEzC,IAAA,OAAO,gBAAgB,QAAiB,CAAA;AAAA,GACzC;AAEA,EAAO,OAAA,CAAC,iBAAiB,aAAa,CAAA;AAIvC;AC9Ba,IAAA,OAAA,GACZ,CAAC,YAAc,EAAA,YAAA;AAAA;AAAA,EAEf,IAAI,MAAY,MAAA;AAAA,IACf,GAAG,YAAA;AAAA,IACH,GAAI,YAA6B,CAAA,GAAG,MAAM;AAAA,GAC3C;AAAA;AAEM,IAAM,yBAAyB,CAClC,GAAA,MAAA,KACC,YAAY,OAAQ,CAAA,GAAG,MAAM,CAAC;AAE5B,IAAM,oBAAoB,CAC7B,GAAA,MAAA,KACC,OAAO,OAAQ,CAAA,GAAG,MAAM,CAAC","file":"index.js","sourcesContent":["import type { SelectorFn } from \"@zayne-labs/toolkit-type-helpers\";\nimport { createElement } from \"react\";\nimport type { StoreApi, UseBoundStore } from \"zustand\";\nimport { type CustomContextOptions, createCustomContext, useConstant } from \"../hooks\";\n\nconst createZustandContext = <\n\tTState extends Record<string, unknown>,\n\tTUseBoundStore extends UseBoundStore<StoreApi<TState>> = UseBoundStore<StoreApi<TState>>,\n>(\n\toptions?: CustomContextOptions<TUseBoundStore, true>\n) => {\n\tconst [Provider, useCustomContext] = createCustomContext(options);\n\n\ttype ZustandProviderProps =\n\t\t| {\n\t\t\t\tchildren: React.ReactNode;\n\t\t\t\tstoreCreator: () => TUseBoundStore;\n\t\t }\n\t\t| {\n\t\t\t\tchildren: React.ReactNode;\n\t\t\t\tvalue: TUseBoundStore;\n\t\t };\n\n\tfunction ZustandProvider(props: ZustandProviderProps) {\n\t\tconst { children, ...restOfProps } = props;\n\n\t\tconst useZustandStore = useConstant(() =>\n\t\t\t\"storeCreator\" in restOfProps ? restOfProps.storeCreator() : restOfProps.value\n\t\t);\n\n\t\treturn createElement(Provider, { value: useZustandStore }, children);\n\t}\n\n\tconst useBoundStore = <TResult = TState>(selector?: SelectorFn<TState, TResult>) => {\n\t\tconst useZustandStore = useCustomContext();\n\n\t\treturn useZustandStore(selector as never);\n\t};\n\n\treturn [ZustandProvider, useBoundStore] as [\n\t\tZustandProvider: typeof ZustandProvider,\n\t\tuseBoundStore: typeof useBoundStore,\n\t];\n};\n\nexport { createZustandContext };\n","import type { AnyFunction, AnyObject } from \"@zayne-labs/toolkit-type-helpers\";\nimport { type StateCreator, type StoreMutatorIdentifier, create, createStore } from \"zustand\";\n\nexport type Combine = <\n\tTInitialState extends AnyObject,\n\tTExtraState extends AnyObject,\n\tMps extends Array<[StoreMutatorIdentifier, unknown]> = [],\n\tMcs extends Array<[StoreMutatorIdentifier, unknown]> = [],\n>(\n\tinitialState: TInitialState,\n\tadditionalStateCreator: StateCreator<TInitialState, Mps, Mcs, TExtraState>\n) => StateCreator<TExtraState & TInitialState>;\n\nexport const combine: Combine =\n\t(initialState, storeCreator) =>\n\t// eslint-disable-next-line ts-eslint/no-unsafe-return -- We don't know what the storeCreator will return\n\t(...params) => ({\n\t\t...initialState,\n\t\t...(storeCreator as AnyFunction)(...params),\n\t});\n\nexport const createStoreWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => createStore(combine(...params));\n\nexport const createWithCombine = <TInitialState extends AnyObject, TExtraState extends AnyObject>(\n\t...params: Parameters<typeof combine<TInitialState, TExtraState>>\n) => create(combine(...params));\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zayne-labs/toolkit-react",
3
3
  "type": "module",
4
- "version": "0.8.45",
4
+ "version": "0.8.46",
5
5
  "description": "A collection of utility functions, types and composables used by my other projects. Nothing too fancy but can be useful.",
6
6
  "author": "Ryan Zayne",
7
7
  "license": "MIT",
@@ -50,8 +50,8 @@
50
50
  }
51
51
  },
52
52
  "dependencies": {
53
- "@zayne-labs/toolkit-core": "0.8.45",
54
- "@zayne-labs/toolkit-type-helpers": "0.8.45"
53
+ "@zayne-labs/toolkit-core": "0.8.46",
54
+ "@zayne-labs/toolkit-type-helpers": "0.8.46"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@arethetypeswrong/cli": "^0.17.4",