Reviewed By: jknoxville Differential Revision: D14224403 fbshipit-source-id: 8341dd8af03148c4b1f648641bda522804acb22d
52 lines
865 B
JavaScript
52 lines
865 B
JavaScript
/**
|
|
* 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',
|
|
});
|