-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace global reducers with local ones
The global reducer idea would have actually been very appropriate in this context. Have a global reducer sat in front of all the global state to make it clear that no global state should be updated directly. As it stands there is a referencial cycle which can't be avoided when using typescripts `addReducer` function which reactn uses for it's own `addReducer`: CharlesStover/reactn#174 Charles's own advice is to use local reducers instead. I still want to get some kind of benefit like that described above, and while I don't think it's actually as semantically clear doing it locally like this there probably is scope to have saga's like reducers like the one I've created here at `setNewHarpStrataReducer`. Making this pattern ubiquitous in the way required though would be out of scope for this feature. I'll have to raise it as techdebt.
- Loading branch information
js-jslog
committed
Sep 20, 2021
1 parent
c5fcc98
commit 5531776
Showing
15 changed files
with
49 additions
and
88 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
26 changes: 1 addition & 25 deletions
26
packages/harpguru-core/src/components/harp-guru/harp-guru.tsx
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
1 change: 0 additions & 1 deletion
1
...es/harpguru-core/src/components/sync-column-bounds-with-active-harp-strata/hooks/index.ts
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
...nds-with-active-harp-strata/hooks/use-update-column-bounds-by-active-harp-strata/index.ts
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
...ate-column-bounds-by-active-harp-strata/use-update-column-bounds-by-active-harp-strata.ts
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
packages/harpguru-core/src/components/sync-column-bounds-with-active-harp-strata/index.ts
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
...sync-column-bounds-with-active-harp-strata/sync-column-bounds-with-active-harp-strata.tsx
This file was deleted.
Oops, something went wrong.
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
1 change: 1 addition & 0 deletions
1
packages/harpguru-core/src/utils/set-new-harp-strata-reducer/index.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { setNewHarpStrataReducer } from './set-new-harp-strata-reducer' |
21 changes: 21 additions & 0 deletions
21
packages/harpguru-core/src/utils/set-new-harp-strata-reducer/set-new-harp-strata-reducer.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { Dispatch } from 'reactn/default' | ||
import type { HarpStrata } from 'harpstrata' | ||
|
||
import { getNewColumnBoundsForDispatcher } from '../get-new-column-bounds-for-dispatcher' | ||
import type { GlobalState } from '../../types' | ||
|
||
export const setNewHarpStrataReducer = ( | ||
global: GlobalState, | ||
_dispatch: Dispatch, | ||
newHarpStrata: HarpStrata | ||
): Pick<GlobalState, 'activeHarpStrata' | 'columnBounds'> => { | ||
const newGlobal = { | ||
...global, | ||
activeHarpStrata: newHarpStrata, | ||
} | ||
|
||
return { | ||
...newGlobal, | ||
...getNewColumnBoundsForDispatcher(newGlobal, _dispatch), | ||
} | ||
} |