cogsbox-state 0.5.441 → 0.5.442
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/dist/CogsState.d.ts +2 -2
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.jsx +85 -85
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +15 -11
package/package.json
CHANGED
package/src/CogsState.tsx
CHANGED
|
@@ -676,13 +676,12 @@ export const createCogsState = <State extends Record<StateKeys, unknown>>(
|
|
|
676
676
|
|
|
677
677
|
return { useCogsState, setCogsOptions } as CogsApi<State>;
|
|
678
678
|
};
|
|
679
|
-
// or wherever your shape types are
|
|
680
679
|
export function createCogsStateFromSync<
|
|
681
680
|
TSyncSchema extends {
|
|
682
681
|
schemas: Record<
|
|
683
682
|
string,
|
|
684
683
|
{
|
|
685
|
-
schemas: {
|
|
684
|
+
schemas: { defaultValues: any };
|
|
686
685
|
[key: string]: any;
|
|
687
686
|
}
|
|
688
687
|
>;
|
|
@@ -691,22 +690,27 @@ export function createCogsStateFromSync<
|
|
|
691
690
|
>(
|
|
692
691
|
syncSchema: TSyncSchema
|
|
693
692
|
): CogsApi<{
|
|
694
|
-
[K in keyof TSyncSchema['schemas']]: TSyncSchema['schemas'][K]['schemas']['
|
|
693
|
+
[K in keyof TSyncSchema['schemas']]: TSyncSchema['schemas'][K]['schemas']['defaultValues'];
|
|
695
694
|
}> {
|
|
696
695
|
const schemas = syncSchema.schemas;
|
|
697
696
|
const initialState: any = {};
|
|
698
697
|
|
|
699
|
-
// Extract
|
|
698
|
+
// Extract defaultValues from each entry
|
|
700
699
|
for (const key in schemas) {
|
|
701
|
-
const entry = schemas[key]
|
|
702
|
-
initialState[key] = entry
|
|
700
|
+
const entry = schemas[key];
|
|
701
|
+
initialState[key] = entry?.schemas?.defaultValues || {};
|
|
703
702
|
}
|
|
704
703
|
|
|
705
|
-
// Store sync metadata
|
|
706
|
-
//
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
704
|
+
// Store sync metadata in each state key's options
|
|
705
|
+
// for (const key in schemas) {
|
|
706
|
+
// const currentOptions =
|
|
707
|
+
// getGlobalStore.getState().getInitialOptions(key) || {};
|
|
708
|
+
// getGlobalStore.getState().setInitialStateOptions(key, {
|
|
709
|
+
// ...currentOptions,
|
|
710
|
+
// syncSchema: schemas[key],
|
|
711
|
+
// notificationChannels: syncSchema.notifications,
|
|
712
|
+
// });
|
|
713
|
+
// }
|
|
710
714
|
|
|
711
715
|
return createCogsState(initialState);
|
|
712
716
|
}
|