-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explore pushing the types through Redux all the way
How far can we go with autocomplete and compile-time guarantees? I'm exploring different approaches to doing that with several goals: - get full auto-complete on all calls to dispatch, all state values, all action types - move runtime overhead into the type system - reduce the number of required imports around the app - remove existing clutter and minimize syntax required for typing
- Loading branch information
Showing
8 changed files
with
87 additions
and
36 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,3 +1,21 @@ | ||
export const AUTH_SET = 'AUTH_SET'; | ||
export const FILTER_NOTES = 'FILTER_NOTES'; | ||
export const TAG_DRAWER_TOGGLE = 'TAG_DRAWER_TOGGLE'; | ||
import * as T from '../types'; | ||
|
||
export type Action< | ||
T extends string, | ||
Args extends { [extraProps: string]: any } | ||
> = { type: T } & Args; | ||
|
||
export type AuthSet = Action<'AUTH_SET', { status: Symbol }>; | ||
export type FilterNotes = Action<'FILTER_NOTES', { notes: T.NoteEntity[] }>; | ||
export type ToggleTagDrawer = Action<'TAG_DRAWER_TOGGLE', { show: boolean }>; | ||
export type SetFontSize = Action<'setFontSize', { fontSize?: number }>; | ||
export type SetWPToken = Action<'setWPToken', { token: string }>; | ||
|
||
export type ActionType = | ||
| AuthSet | ||
| FilterNotes | ||
| ToggleTagDrawer | ||
| SetFontSize | ||
| SetWPToken; | ||
|
||
export type Reducer<S> = (state: S, action: ActionType) => S; |
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,9 @@ | ||
import * as auth from './auth/actions'; | ||
import * as settings from './settings/actions'; | ||
import * as ui from './ui/actions'; | ||
|
||
export default { | ||
auth, | ||
settings, | ||
ui, | ||
}; |
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,11 +1,12 @@ | ||
import { FILTER_NOTES, TAG_DRAWER_TOGGLE } from '../action-types'; | ||
import * as A from '../action-types'; | ||
import * as T from '../../types'; | ||
|
||
export const filterNotes = notes => ({ | ||
type: FILTER_NOTES, | ||
export const filterNotes = (notes: T.NoteEntity[]): A.FilterNotes => ({ | ||
type: 'FILTER_NOTES', | ||
notes, | ||
}); | ||
|
||
export const toggleTagDrawer = show => ({ | ||
type: TAG_DRAWER_TOGGLE, | ||
export const toggleTagDrawer = (show: boolean): A.ToggleTagDrawer => ({ | ||
type: 'TAG_DRAWER_TOGGLE', | ||
show, | ||
}); |
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