-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Polymorphic Flow Types #356
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[ignore] | ||
.*/node_modules/webpack/.* | ||
.*/node_modules/webpack-dev-server/.* | ||
.*/node_modules/redux/examples/.* | ||
.*/node_modules/redux/lib/.* | ||
|
||
[include] | ||
|
||
[libs] | ||
|
||
[options] | ||
module.system=node | ||
module.name_mapper='\(redux\)' -> '\1/src/index' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export const INCREMENT_COUNTER = 'INCREMENT_COUNTER'; | ||
export const DECREMENT_COUNTER = 'DECREMENT_COUNTER'; | ||
/* @flow */ | ||
|
||
export var INCREMENT_COUNTER = 'INCREMENT_COUNTER'; | ||
export var DECREMENT_COUNTER = 'DECREMENT_COUNTER'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../constants/ActionTypes'; | ||
/* @flow */ | ||
|
||
export default function counter(state = 0, action) { | ||
import type {State, Action} from '../types'; | ||
|
||
export default function counter(state: State, action: Action) : State { | ||
switch (action.type) { | ||
case INCREMENT_COUNTER: | ||
case 'INCREMENT_COUNTER': | ||
return state + 1; | ||
case DECREMENT_COUNTER: | ||
case 'DECREMENT_COUNTER': | ||
return state - 1; | ||
default: | ||
return state; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will forgetting a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💃 👯 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* @flow */ | ||
|
||
import type {Reducer, Store} from 'redux/flow/types'; | ||
import {createStore} from 'redux'; | ||
|
||
import type {State, Action} from './types'; | ||
|
||
import counter from './reducers/counter'; | ||
|
||
var store = createStore(counter, 0); | ||
// var reducer = store.getReducer(); | ||
// counter(0, {type: 'a'}) // fails type check | ||
// reducer(0, {type: 'a'}) // fails type check | ||
// store.getState().replace('hey', 'ho'); // fails type check | ||
store.dispatch({type: 'INCREMENT_COUNTER'}); | ||
// store.dispatch({type: 'foo'}); // fails type check | ||
// store.dispatch({type: 'INCREMENT_COUNTE'}); // fails type check | ||
store.dispatch({type: '@@redux/INIT'}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* @flow */ | ||
export type State = number; | ||
|
||
export type Action = | ||
{ type: '@@redux/INIT' } | | ||
{ type: 'INCREMENT_COUNTER' } | | ||
{ type: 'DECREMENT_COUNTER' }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* @flow */ | ||
|
||
export type ReduxInitAction = {type: '@@redux/INIT'}; | ||
export type ReduxAction<Action> = ReduxInitAction | Action; | ||
|
||
export type Reducer<State, Action> = (state: State, action: Action) => State; | ||
export type Store<State, Action> = { | ||
dispatch: (action: Action) => Action, | ||
subscribe: (listener: () => void) => (() => void), | ||
getState: () => State, | ||
getReducer: () => Reducer<State, Action>, | ||
replaceReducer: any | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will returning non-number fail the type check here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes!