Convert user dispatcher to TS

Summary: Convert file to TS

Reviewed By: passy

Differential Revision: D16687861

fbshipit-source-id: 5aa88b169b915bc1abd71d312f510073ea78b0c7
This commit is contained in:
John Knox
2019-08-09 04:50:48 -07:00
committed by Facebook Github Bot
parent 7a594cf456
commit cff023150e
2 changed files with 4 additions and 4 deletions

27
src/dispatcher/user.tsx Normal file
View File

@@ -0,0 +1,27 @@
/**
* 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
*/
import {Store} from '../reducers/index';
import {Logger} from '../fb-interfaces/Logger.js';
import {login} from '../reducers/user';
import {getUser, logoutUser} from '../fb-stubs/user';
export default (store: Store, logger: Logger) => {
getUser()
.then(user => {
store.dispatch(login(user));
})
.catch(console.debug);
let prevUserName = store.getState().user.name;
store.subscribe(() => {
if (prevUserName && !store.getState().user.name) {
logoutUser();
}
prevUserName = store.getState().user.name;
});
};