Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb8eb516

Browse files
committed
fix
1 parent9389b32 commitb8eb516

File tree

7 files changed

+48
-50
lines changed

7 files changed

+48
-50
lines changed

‎.changeset/pink-guests-jump.md‎

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,13 @@
22
'zustand-x':minor
33
---
44

5-
- Introduced a React-free`createVanillaStore` in`zustand-x/vanilla` using`zustand/vanilla`.
6-
- Extracted shared internal logic (`middleware`,`options parsing`,`selector/action helpers`) to`src/internal` for reuse.
7-
- Refactored React entry (`createStore`, hooks) to use shared internal logic without breaking existing API.
8-
- Split types: base hook-free definitions vs React-specific types for compatibility with both entries.
9-
- Updated package exports to include`./vanilla` while keeping`.` for React.
10-
- Added vanilla-focused tests to ensure store functionality works without React.
11-
- Ensured middleware, selector/action extensions, and mutative utilities work in both vanilla and React contexts.
12-
-**Example usage (vanilla, no React):**
5+
Added`createVanillaStore`: create a vanilla Zustand store in Node.js, workers, or any non-React environment. Example:
136

147
```ts
158
import {createVanillaStore }from'zustand-x/vanilla';
169

17-
const counterStore=createVanillaStore(
18-
{ count:0 },
19-
{ name:'vanilla-counter', persist:true }
20-
)
21-
.extendSelectors(({get })=> ({
22-
doubled: ()=>get('count')*2,
23-
}))
24-
.extendActions(({set })=> ({
25-
increment: ()=>set('count', (value)=>value+1),
26-
}));
10+
const store=createVanillaStore({ count:0 }, { name:'counter' });
2711

28-
counterStore.actions.increment();
29-
console.log(counterStore.get('doubled'));// 2
12+
store.get('count');
13+
store.set('count',1);
3014
```

‎packages/zustand-x/src/internal/buildStateCreator.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const buildStateCreator = <
8080
(typeofinitializer==='function'
8181
?initializer
8282
:()=>initializer)asStateCreator<StateType>
83-
)asStateCreator<StateType,[],Mutators>;
83+
)asunknownasStateCreator<StateType,[],Mutators>;
8484

8585
constisMutative=
8686
isMutativeState||immerConfig.enabled||mutativeConfig.enabled;
@@ -89,5 +89,5 @@ export const buildStateCreator = <
8989
stateCreator:subscribeWithSelector(stateCreator),
9090
isMutative,
9191
name,
92-
}asBuildStateCreatorResult<StateType,Mutators>;
92+
}asunknownasBuildStateCreatorResult<StateType,Mutators>;
9393
};

‎packages/zustand-x/src/internal/extendActions.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const extendActions = <
2828
set:((key:string, ...args:unknown[])=>{
2929
if(keyinactions){
3030
constaction=actions[key];
31-
returnaction(...args);
31+
returnaction?.(...args);
3232
}
3333

3434
returnapi.set(keyasany,args[0]);

‎packages/zustand-x/src/internal/extendSelectors.ts‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type {
33
TBaseStateApiForBuilder,
44
TSelectorBuilder,
55
}from'../types/baseStore';
6-
importtype{StoreMutatorIdentifier}from'zustand';
76
importtype{TState}from'../types/utils';
7+
importtype{StoreMutatorIdentifier}from'zustand';
88

99
constidentity=<T>(arg:T)=>arg;
1010

@@ -41,7 +41,7 @@ export const extendSelectors = <
4141
get:((key:string, ...args:unknown[])=>{
4242
if(keyinselectors){
4343
constselector=selectors[key];
44-
returnselector(...args);
44+
returnselector?.(...args);
4545
}
4646

4747
returnbaseGet(keyaskeyofStateType);
@@ -70,9 +70,7 @@ export const extendSelectors = <
7070
'state',
7171
()=>
7272
selectorArg(
73-
selectors[keyaskeyoftypeofselectors](
74-
...selectorArgs
75-
)
73+
selectors[keyaskeyoftypeofselectors](...selectorArgs)
7674
),
7775
listener,
7876
optionsArg
@@ -91,10 +89,7 @@ export const extendSelectors = <
9189

9290
if(options?.selectWithStore){
9391
constselectWithStore=options.selectWithStore;
94-
(extendedApiasany).useValue=(
95-
key:string,
96-
...args:unknown[]
97-
)=>{
92+
(extendedApiasany).useValue=(key:string, ...args:unknown[])=>{
9893
if(keyinselectors){
9994
constselector=selectors[key];
10095
constmaybeEqualityFn=args.at(-1);
@@ -103,7 +98,7 @@ export const extendSelectors = <
10398
constselectorArgs=equalityFn ?args.slice(0,-1) :args;
10499

105100
returnselectWithStore(
106-
()=>selector(...selectorArgs),
101+
()=>selector?.(...selectorArgs),
107102
equalityFnasAnyFunction
108103
);
109104
}

‎packages/zustand-x/src/types/middleware.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export type TExtractMutatorFromMiddleware<M> = M extends (
66
...rest:any[]
77
)=>StateCreator<any,any, inferMutators,any>
88
?// eslint-disable-next-line unused-imports/no-unused-vars
9-
Mutatorsextends[inferMutator, ...inferRest]
9+
Mutatorsextends[inferMutator, ...unknown[]]
1010
?Mutatorextends[StoreMutatorIdentifier,unknown]
1111
?Mutator
1212
:never

‎packages/zustand-x/src/types/store.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import{StoreMutatorIdentifier}from'zustand';
22

3-
import{
3+
import{TCreatedStoreType,TState}from'./utils';
4+
5+
importtype{
46
AnyFunction,
57
TActionBuilder,
68
TBaseStateApi,
79
TSelectorBuilder,
8-
TStoreApiGet,
9-
TStoreApiSet,
10-
TStoreApiSubscribe,
1110
}from'./baseStore';
12-
import{TCreatedStoreType,TState}from'./utils';
13-
1411
importtype{TEqualityChecker}from'./utils';
1512

1613
exporttypeTStateApi<

‎tsconfig.json‎

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,44 @@
33
"ignoreDiagnostics": [7005]
44
},
55
"compilerOptions": {
6+
"strict":true,
7+
"strictNullChecks":true,
8+
"allowUnusedLabels":false,
9+
"allowUnreachableCode":false,
10+
"exactOptionalPropertyTypes":true,
11+
"noFallthroughCasesInSwitch":true,
12+
"noImplicitOverride":true,
13+
"noImplicitReturns":true,
14+
"noPropertyAccessFromIndexSignature":true,
15+
"noUncheckedIndexedAccess":true,
16+
"noUnusedLocals":true,
17+
"noUnusedParameters":true,
18+
19+
"isolatedModules":true,
20+
621
"allowJs":true,
7-
"allowSyntheticDefaultImports":true,
8-
"downlevelIteration":true,
22+
"checkJs":true,
23+
924
"esModuleInterop":true,
25+
"skipLibCheck":true,
1026
"forceConsistentCasingInFileNames":true,
11-
"isolatedModules":true,
12-
"jsx":"react",
13-
"lib": ["dom","dom.iterable","esnext"],
27+
28+
"lib": ["es2023"],
1429
"module":"esnext",
15-
"moduleResolution":"node",
16-
"noEmit":true,
30+
"target":"es2022",
31+
"moduleResolution":"bundler",
32+
"moduleDetection":"force",
1733
"resolveJsonModule":true,
18-
"skipLibCheck":true,
34+
"noEmit":true,
35+
"incremental":true,
36+
37+
"declaration":true,
38+
"declarationMap":true,
1939
"sourceMap":true,
20-
"strict":true,
21-
"target":"es2017",
40+
"pretty":true,
41+
"preserveWatchOutput":true,
42+
43+
"jsx":"react",
2244
"outDir":"dist",
2345
"types": ["vitest/globals"]
2446
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp