Add zustand dev tools
This commit is contained in:
@@ -6,6 +6,11 @@
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
import { StateCreator } from 'zustand';
|
||||
import { StateCreator as ZustandStateCreator } from 'zustand';
|
||||
|
||||
export type ImmerStateCreator<T> = StateCreator<T, [['zustand/immer', never], never], [], T>;
|
||||
export type StateCreator<T> = ZustandStateCreator<T, [['zustand/devtools', never], ['zustand/immer', never]], [], T>;
|
||||
|
||||
export type SliceCreator<T> = (
|
||||
actionNameCreator: (...names: string[]) => string,
|
||||
...args: Parameters<StateCreator<T>>
|
||||
) => T;
|
||||
|
||||
23
src/lib/zustand/ZustandUtil.ts
Normal file
23
src/lib/zustand/ZustandUtil.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) Contributors to the Suwayomi project
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
export class ZustandUtil {
|
||||
static createActionName(...names: string[]) {
|
||||
const storeAndSlices = names.slice(0, -1);
|
||||
const action = names.slice(-1)[0];
|
||||
|
||||
return `${storeAndSlices.join(':')}/${action}`;
|
||||
}
|
||||
|
||||
static createActionNameCreator(
|
||||
name: string,
|
||||
parentCreator: typeof ZustandUtil.createActionName = ZustandUtil.createActionName,
|
||||
): typeof ZustandUtil.createActionName {
|
||||
return (...names: string[]) => parentCreator(name, ...names);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user