Skip to content

Commit 3fdf194

Browse files
author
Erik Rasmussen
committed
quack! quack!
1 parent af04168 commit 3fdf194

20 files changed

+195
-258
lines changed

src/actions/actionTypes.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/actions/authActions.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/actions/counterActions.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/actions/infoActions.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/actions/widgetActions.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/components/CounterButton.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {Component, PropTypes} from 'react';
22
import {bindActionCreators} from 'redux';
33
import {connect} from 'react-redux';
4-
import {increment} from '../actions/counterActions';
4+
import {increment} from '../ducks/counter';
55

66
@connect(
77
state => ({count: state.counter.count}),

src/components/InfoBar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {Component, PropTypes} from 'react';
22
import {bindActionCreators} from 'redux';
33
import {connect} from 'react-redux';
4-
import {load} from '../actions/infoActions';
4+
import {load} from '../ducks/info';
55

66
@connect(
77
state => ({info: state.info.data}),

src/components/WidgetForm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {connect} from 'react-redux';
33
import {bindActionCreators} from 'redux';
44
import reduxForm from 'redux-form';
55
import widgetValidation, {colors} from '../validation/widgetValidation';
6-
import * as widgetActions from '../actions/widgetActions';
6+
import * as widgetActions from '../ducks/widgets';
77

88
@connect(
99
state => ({

src/ducks/auth.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
const LOAD = 'redux-example/auth/LOAD';
2+
const LOAD_SUCCESS = 'redux-example/auth/LOAD_SUCCESS';
3+
const LOAD_FAIL = 'redux-example/auth/LOAD_FAIL';
4+
const LOGIN = 'redux-example/auth/LOGIN';
5+
const LOGIN_SUCCESS = 'redux-example/auth/LOGIN_SUCCESS';
6+
const LOGIN_FAIL = 'redux-example/auth/LOGIN_FAIL';
7+
const LOGOUT = 'redux-example/auth/LOGOUT';
8+
const LOGOUT_SUCCESS = 'redux-example/auth/LOGOUT_SUCCESS';
9+
const LOGOUT_FAIL = 'redux-example/auth/LOGOUT_FAIL';
10+
11+
const initialState = {
12+
loaded: false
13+
};
14+
15+
export default function reducer(state = initialState, action = {}) {
16+
switch (action.type) {
17+
case LOAD:
18+
return {
19+
...state,
20+
loading: true
21+
};
22+
case LOAD_SUCCESS:
23+
return {
24+
...state,
25+
loading: false,
26+
loaded: true,
27+
user: action.result
28+
};
29+
case LOAD_FAIL:
30+
return {
31+
...state,
32+
loading: false,
33+
loaded: false,
34+
error: action.error
35+
};
36+
case LOGIN:
37+
return {
38+
...state,
39+
loggingIn: true
40+
};
41+
case LOGIN_SUCCESS:
42+
return {
43+
...state,
44+
loggingIn: false,
45+
user: action.result
46+
};
47+
case LOGIN_FAIL:
48+
return {
49+
...state,
50+
loggingIn: false,
51+
user: null,
52+
loginError: action.error
53+
};
54+
case LOGOUT:
55+
return {
56+
...state,
57+
loggingOut: true
58+
};
59+
case LOGOUT_SUCCESS:
60+
return {
61+
...state,
62+
loggingOut: false,
63+
user: null
64+
};
65+
case LOGOUT_FAIL:
66+
return {
67+
...state,
68+
loggingOut: false,
69+
logoutError: action.error
70+
};
71+
default:
72+
return state;
73+
}
74+
}
75+
76+
export function isLoaded(globalState) {
77+
return globalState.auth && globalState.auth.loaded;
78+
}
79+
80+
export function load() {
81+
return {
82+
types: [LOAD, LOAD_SUCCESS, LOAD_FAIL],
83+
promise: (client) => client.get('/loadAuth')
84+
};
85+
}
86+
87+
export function login(name) {
88+
return {
89+
types: [LOGIN, LOGIN_SUCCESS, LOGIN_FAIL],
90+
promise: (client) => client.post('/login', {
91+
data: {
92+
name: name
93+
}
94+
})
95+
};
96+
}
97+
98+
export function logout() {
99+
return {
100+
types: [LOGOUT, LOGOUT_SUCCESS, LOGOUT_FAIL],
101+
promise: (client) => client.get('/logout')
102+
};
103+
}

src/ducks/counter.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const INCREMENT = 'redux-example/counter/INCREMENT';
2+
3+
const initialState = {
4+
count: 0
5+
};
6+
7+
export default function reducer(state = initialState, action = {}) {
8+
switch (action.type) {
9+
case INCREMENT:
10+
const {count} = state;
11+
return {
12+
count: count + 1
13+
};
14+
default:
15+
return state;
16+
}
17+
}
18+
19+
export function increment() {
20+
return {
21+
type: INCREMENT
22+
};
23+
}
File renamed without changes.
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
import {
2-
INFO_LOAD,
3-
INFO_LOAD_SUCCESS,
4-
INFO_LOAD_FAIL
5-
} from '../actions/actionTypes';
1+
const LOAD = 'redux-example/LOAD';
2+
const LOAD_SUCCESS = 'redux-example/LOAD_SUCCESS';
3+
const LOAD_FAIL = 'redux-example/LOAD_FAIL';
64

75
const initialState = {
86
loaded: false
97
};
108

119
export default function info(state = initialState, action = {}) {
1210
switch (action.type) {
13-
case INFO_LOAD:
11+
case LOAD:
1412
return {
1513
...state,
1614
loading: true
1715
};
18-
case INFO_LOAD_SUCCESS:
16+
case LOAD_SUCCESS:
1917
return {
2018
...state,
2119
loading: false,
2220
loaded: true,
2321
data: action.result
2422
};
25-
case INFO_LOAD_FAIL:
23+
case LOAD_FAIL:
2624
return {
2725
...state,
2826
loading: false,
@@ -37,3 +35,10 @@ export default function info(state = initialState, action = {}) {
3735
export function isLoaded(globalState) {
3836
return globalState.info && globalState.info.loaded;
3937
}
38+
39+
export function load() {
40+
return {
41+
types: [LOAD, LOAD_SUCCESS, LOAD_FAIL],
42+
promise: (client) => client.get('/loadInfo')
43+
};
44+
}

0 commit comments

Comments
 (0)