You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 12, 2020. It is now read-only.
Copy file name to clipboardexpand all lines: README.md
+17-9
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,9 @@ When an app communicates with a HTTP API, which enforces some form of authentica
12
12
13
13
With the work flow defined above we'll start with the Reflux _action creators_ and _reducers_.
14
14
15
-
## Action Creators ##
15
+
# Logging In #
16
+
17
+
### Action Creators ###
16
18
17
19
In _step 2_ the user taps the submit button, which dispatches the `login(username, password)` function.
18
20
@@ -58,22 +60,26 @@ export function login(username, password) {
58
60
59
61
The above function dispatches 3 other actions: `LOGIN_REQUEST`, `LOGIN_FAILURE`, `LOGIN_SUCCESS`. (They're fairly generic, and not really worth documenting - Check `actions/user.js`)
60
62
61
-
## Reducers ##
63
+
### Reducers ###
64
+
65
+
Some of the properties in the reducer can be used to update the
66
+
UI.
62
67
63
-
In our reducer we can use `isLoggingIn`, `isAuthenticated`, and `error`
64
-
to update the user-interface.
68
+
-`isLoggingIn`: Display a loading indicator.
69
+
-`isAuthenticated`: Hide/ Show a login modal
70
+
-`error`: Self explanatory.
65
71
66
72
```
67
73
/// reducers/user.js
68
74
69
75
function user(state = {
70
-
isLoggingIn: false, // loading indicator
71
-
isAuthenticated: false // show, or hide the authentication modal.
76
+
isLoggingIn: false,
77
+
isAuthenticated: false
72
78
}, action) {
73
79
switch(action.type) {
74
80
case LOGIN_REQUEST:
75
81
return {
76
-
isLoggingIn: true,
82
+
isLoggingIn: true, // Show a loading indicator.
77
83
isAuthenticated: false
78
84
}
79
85
case LOGIN_FAILURE:
@@ -85,12 +91,14 @@ function user(state = {
85
91
case LOGIN_SUCCESS:
86
92
return {
87
93
isLoggingIn: false,
88
-
isAuthenticated: true,
89
-
hash: action.hash,
94
+
isAuthenticated: true, // Dismiss the login view.
95
+
hash: action.hash, // Used in subsequent API requests.
0 commit comments