Add zustand dev tools

This commit is contained in:
schroda
2025-09-22 00:50:34 +02:00
parent f6b94c838b
commit b6d7f6da5d
11 changed files with 325 additions and 147 deletions

View File

@@ -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;

View 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);
}
}