-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2aa4c44
commit 7afdece
Showing
15 changed files
with
63 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
import { createStore } from 'zustand/vanilla'; | ||
|
||
import type { State } from '../features/index.js'; | ||
import type { AppState } from '../features/index.js'; | ||
|
||
export const store = createStore<State>()(() => ({ | ||
type Subscribe = (listener: (state: AppState, prevState: AppState) => void) => () => void; | ||
|
||
export type Store = { | ||
getState: () => AppState; | ||
getInitialState: () => AppState; | ||
setState: (stateSetter: (state: AppState) => AppState) => void; | ||
subscribe: Subscribe; | ||
}; | ||
|
||
const initialState: AppState = { | ||
counter: 0, | ||
})); | ||
}; | ||
|
||
export const store = createStore<AppState>()(() => initialState); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { createUseStore } from 'zutron'; | ||
import type { State } from '../../features/index.js'; | ||
|
||
export const useStore = createUseStore<State>(window.zutron); | ||
import type { AppState } from '../../features/index.js'; | ||
|
||
export const useStore = createUseStore<AppState>(window.zutron); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
import { handlers as counterHandlers } from './counter/index.js'; | ||
import type { Store } from '../main/store.js'; | ||
|
||
export const actionHandlers = (store: Store, initialState: State) => ({ | ||
export type Handlers = Record<string, () => void>; | ||
export type AppState = { counter: number }; | ||
|
||
export const actionHandlers = (store: Store, initialState: AppState) => ({ | ||
...counterHandlers(store), | ||
'STORE:RESET': () => store.setState(() => initialState), | ||
}); | ||
|
||
export type Subscribe = (listener: (state: State, prevState: State) => void) => () => void; | ||
export type Handlers = Record<string, () => void>; | ||
export type State = { counter: number }; | ||
export type Store = { | ||
getState: () => State; | ||
getInitialState: () => State; | ||
setState: (stateSetter: (state: State) => State) => void; | ||
subscribe: Subscribe; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
import { createStore } from 'zustand/vanilla'; | ||
|
||
import type { State } from '../features/index.js'; | ||
import type { AppState } from '../features/index.js'; | ||
|
||
export const initialState = { | ||
type Subscribe = (listener: (state: AppState, prevState: AppState) => void) => () => void; | ||
|
||
export type Store = { | ||
getState: () => AppState; | ||
getInitialState: () => AppState; | ||
setState: (stateSetter: (state: AppState) => AppState) => void; | ||
subscribe: Subscribe; | ||
}; | ||
|
||
export const initialState: AppState = { | ||
counter: 0, | ||
}; | ||
|
||
export const store = createStore<State>()(() => initialState); | ||
export const store = createStore<AppState>()(() => initialState); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
apps/example-separate-handlers/src/renderer/hooks/useStore.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { createUseStore } from 'zutron'; | ||
import type { State } from '../../features/index.js'; | ||
|
||
export const useStore = createUseStore<State>(window.zutron); | ||
import type { AppState } from '../../features/index.js'; | ||
|
||
export const useStore = createUseStore<AppState>(window.zutron); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters