@4399ywkf/cli 2.0.14 → 2.0.16

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.
@@ -0,0 +1,4 @@
1
+ export { useAppStore, getAppStoreState } from "./store";
2
+ export type { AppStore } from "./store";
3
+ export { initialState } from "./initialState";
4
+ export type { AppStoreState } from "./initialState";
@@ -0,0 +1,10 @@
1
+ import {
2
+ type CounterState,
3
+ initialCounterState,
4
+ } from "./slices/counter/initialState";
5
+
6
+ export type AppStoreState = CounterState;
7
+
8
+ export const initialState: AppStoreState = {
9
+ ...initialCounterState,
10
+ };
@@ -0,0 +1,37 @@
1
+ import type { StateCreator } from "zustand/vanilla";
2
+ import type { AppStore } from "../../store";
3
+
4
+ export interface CounterAction {
5
+ increment: () => void;
6
+ decrement: () => void;
7
+ reset: () => void;
8
+ setLoading: (loading: boolean) => void;
9
+ setError: (error: string | null) => void;
10
+ fetchCount: () => Promise<void>;
11
+ }
12
+
13
+ export const createCounterSlice: StateCreator<
14
+ AppStore,
15
+ [["zustand/devtools", never]],
16
+ [],
17
+ CounterAction
18
+ > = (set, get) => ({
19
+ increment: () => set((s) => ({ count: s.count + 1 })),
20
+ decrement: () => set((s) => ({ count: s.count - 1 })),
21
+ reset: () => set({ count: 0, error: null }),
22
+ setLoading: (loading) => set({ loading }),
23
+ setError: (error) => set({ error }),
24
+
25
+ fetchCount: async () => {
26
+ set({ loading: true, error: null });
27
+ try {
28
+ await new Promise((r) => setTimeout(r, 500));
29
+ set({ count: 42, loading: false });
30
+ } catch (err) {
31
+ set({
32
+ error: err instanceof Error ? err.message : "未知错误",
33
+ loading: false,
34
+ });
35
+ }
36
+ },
37
+ });
@@ -0,0 +1,11 @@
1
+ export interface CounterState {
2
+ count: number;
3
+ loading: boolean;
4
+ error: string | null;
5
+ }
6
+
7
+ export const initialCounterState: CounterState = {
8
+ count: 0,
9
+ loading: false,
10
+ error: null,
11
+ };
@@ -0,0 +1,30 @@
1
+ import { subscribeWithSelector } from "zustand/middleware";
2
+ import { shallow } from "zustand/shallow";
3
+ import { createWithEqualityFn } from "zustand/traditional";
4
+ import type { StateCreator } from "zustand/vanilla";
5
+
6
+ import { createDevtools } from "../middleware/createDevtools";
7
+ import { type AppStoreState, initialState } from "./initialState";
8
+
9
+ import {
10
+ type CounterAction,
11
+ createCounterSlice,
12
+ } from "./slices/counter/actions";
13
+
14
+ export type AppStore = AppStoreState & CounterAction;
15
+
16
+ const createStore: StateCreator<AppStore, [["zustand/devtools", never]]> = (
17
+ ...parameters
18
+ ) => ({
19
+ ...initialState,
20
+ ...createCounterSlice(...parameters),
21
+ });
22
+
23
+ const devtools = createDevtools("app");
24
+
25
+ export const useAppStore = createWithEqualityFn<AppStore>()(
26
+ subscribeWithSelector(devtools(createStore)),
27
+ shallow,
28
+ );
29
+
30
+ export const getAppStoreState = () => useAppStore.getState();
@@ -0,0 +1,2 @@
1
+ export { useAppStore, getAppStoreState } from "./app";
2
+ export type { AppStore, AppStoreState } from "./app";
@@ -0,0 +1,19 @@
1
+ import type { DevtoolsOptions } from "zustand/middleware";
2
+ import { devtools as devtoolsMiddleware } from "zustand/middleware";
3
+ import type { StateCreator, StoreMutatorIdentifier } from "zustand/vanilla";
4
+
5
+ export const createDevtools =
6
+ (name: string, options?: DevtoolsOptions) =>
7
+ <
8
+ T,
9
+ Mps extends [StoreMutatorIdentifier, unknown][] = [],
10
+ Mcs extends [StoreMutatorIdentifier, unknown][] = [],
11
+ >(
12
+ initializer: StateCreator<T, [...Mps, ["zustand/devtools", never]], Mcs>,
13
+ ) =>
14
+ devtoolsMiddleware(initializer, {
15
+ name,
16
+ enabled: process.env.NODE_ENV === "development",
17
+ trace: process.env.NODE_ENV === "development",
18
+ ...options,
19
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4399ywkf/cli",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
4
4
  "description": "运维开发部脚手架",
5
5
  "main": "dist/index.js",
6
6
  "bin": {