-
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.
fix: multiple issues with the follower
- Loading branch information
Showing
5 changed files
with
117 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import useMouseStore from '../store/index.js'; | ||
import { FollowerInitialiserComponent } from './follower_init.js'; | ||
|
||
export function Follower() { | ||
const { options } = useMouseStore((state) => ({ options: state.curSettings })); | ||
return <FollowerInitialiserComponent options={options} />; | ||
return <FollowerInitialiserComponent />; | ||
} |
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,42 +1,54 @@ | ||
import { create } from 'zustand'; | ||
// import { create } from 'zustand'; | ||
import { create, StateCreator, StoreApi, SetState, GetState } from 'zustand'; | ||
import { MouseSettings } from '../types/index.js'; | ||
|
||
const defaultSettings: MouseSettings = { | ||
radius: 12 / 2, | ||
}; | ||
|
||
interface useMouseStoreInterface { | ||
curSettings: MouseSettings; | ||
layers: [MouseSettings]; | ||
layers: MouseSettings[]; | ||
|
||
pushLayer: (newLayer: MouseSettings) => void; | ||
popLayer: () => void; | ||
clearLayers: () => void; | ||
} | ||
|
||
const useMouseStore = create<useMouseStoreInterface>((set) => ({ | ||
curSettings: defaultSettings, | ||
layers: [defaultSettings], | ||
const log = | ||
(config: StateCreator<useMouseStoreInterface>) => | ||
(set: SetState<useMouseStoreInterface>, get: GetState<useMouseStoreInterface>, api: StoreApi<useMouseStoreInterface>) => | ||
config( | ||
(args) => { | ||
console.log(' applying', args); | ||
set(args); | ||
console.log(' new state', get()); | ||
}, | ||
get, | ||
api, | ||
); | ||
|
||
const useMouseStore = create<useMouseStoreInterface>( | ||
log((set) => ({ | ||
curSettings: {}, | ||
layers: [], | ||
|
||
pushLayer: (newLayer: MouseSettings) => | ||
set((state) => { | ||
const newCur = { ...state.curSettings, ...newLayer }; | ||
state.layers.push(newCur); | ||
return { layers: state.layers, curSettings: newCur }; | ||
}), | ||
popLayer: () => | ||
set((state) => { | ||
if (state.layers.length > 1) { | ||
state.layers.pop(); | ||
return { layers: state.layers, curSettings: state.layers.at(state.layers.length - 1) }; | ||
} else { | ||
return { layers: [defaultSettings], curSettings: defaultSettings }; | ||
} | ||
}), | ||
clearLayers: () => | ||
set((state) => { | ||
return { layers: [defaultSettings], curSettings: defaultSettings }; | ||
}), | ||
})); | ||
pushLayer: (newLayer: MouseSettings) => | ||
set((state) => { | ||
const newCur = { ...state.curSettings, ...newLayer }; | ||
state.layers.push(newCur); | ||
return { layers: state.layers, curSettings: newCur }; | ||
}), | ||
popLayer: () => | ||
set((state) => { | ||
if (state.layers.length > 1) { | ||
state.layers.pop(); | ||
return { layers: state.layers, curSettings: state.layers.at(state.layers.length - 1) }; | ||
} else { | ||
return { layers: [], curSettings: {} }; | ||
} | ||
}), | ||
clearLayers: () => | ||
set((state) => { | ||
return { layers: [], curSettings: {} }; | ||
}), | ||
})), | ||
); | ||
|
||
export default useMouseStore; |
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