migrate redux store
Summary: Migrating redux stores to TypeScript Reviewed By: passy Differential Revision: D16579796 fbshipit-source-id: e3e507f17f1bdd57eb45e30cb0b28aaee6c4521c
This commit is contained in:
committed by
Facebook Github Bot
parent
2c95ef6b25
commit
64cefd0f84
51
src/reducers/user.tsx
Normal file
51
src/reducers/user.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright 2018-present Facebook.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
* @format
|
||||
*/
|
||||
|
||||
export type User = {
|
||||
name?: string,
|
||||
profile_picture?: {
|
||||
uri: string,
|
||||
},
|
||||
};
|
||||
|
||||
export type State = User;
|
||||
|
||||
export type Action =
|
||||
| {
|
||||
type: 'LOGIN',
|
||||
payload: User,
|
||||
}
|
||||
| {
|
||||
type: 'LOGOUT',
|
||||
};
|
||||
|
||||
const INITIAL_STATE: State = {};
|
||||
|
||||
export default function reducer(
|
||||
state: State = INITIAL_STATE,
|
||||
action: Action,
|
||||
): State {
|
||||
if (action.type === 'LOGOUT') {
|
||||
return {};
|
||||
} else if (action.type === 'LOGIN') {
|
||||
return {
|
||||
...state,
|
||||
...action.payload,
|
||||
};
|
||||
} else {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export const login = (payload: User): Action => ({
|
||||
type: 'LOGIN',
|
||||
payload,
|
||||
});
|
||||
|
||||
export const logout = (): Action => ({
|
||||
type: 'LOGOUT',
|
||||
});
|
||||
Reference in New Issue
Block a user