Permalink
Browse files

Add Flow types for actions

  • Loading branch information...
frantic committed May 31, 2016
1 parent 350ded0 commit c351616afc148840f762439c4404a86f65c44a95
Showing with 11 additions and 4 deletions.
  1. +9 −4 actions.js
  2. +2 −0 reducers.js
@@ -1,3 +1,10 @@
// @flow

export type Action =
{ type: 'LOGGED_IN', userName: string}
| { type: 'LOGGED_OUT' }
;

function callAPI(endpoint, params) {
// Just for the demo, normally we'd use something like `fetch`
// to talk to our servers
@@ -6,9 +13,7 @@ function callAPI(endpoint, params) {
});
}



export async function logIn(login, pass) {
export async function logIn(login: string, pass: string): Promise<Action> {
const response = await callAPI('/login', login, pass);
if (!response.success) {
throw new Error('Login failed');
@@ -20,6 +25,6 @@ export async function logIn(login, pass) {
};
}

export function logOut() {
export function logOut(): Action {
return { type: 'LOGGED_OUT' };
}
@@ -1,5 +1,7 @@
// @flow

import type {Action} from './actions';

type State = {
isLoggedIn: boolean;
userName: string;

0 comments on commit c351616

Please sign in to comment.