Skip to content

Commit

Permalink
quack! quack!
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Rasmussen committed Aug 21, 2015
1 parent af04168 commit 3fdf194
Show file tree
Hide file tree
Showing 20 changed files with 195 additions and 258 deletions.
21 changes: 0 additions & 21 deletions src/actions/actionTypes.js

This file was deleted.

36 changes: 0 additions & 36 deletions src/actions/authActions.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/actions/counterActions.js

This file was deleted.

12 changes: 0 additions & 12 deletions src/actions/infoActions.js

This file was deleted.

35 changes: 0 additions & 35 deletions src/actions/widgetActions.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/CounterButton.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {Component, PropTypes} from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {increment} from '../actions/counterActions';
import {increment} from '../ducks/counter';

@connect(
state => ({count: state.counter.count}),
Expand Down
2 changes: 1 addition & 1 deletion src/components/InfoBar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {Component, PropTypes} from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {load} from '../actions/infoActions';
import {load} from '../ducks/info';

@connect(
state => ({info: state.info.data}),
Expand Down
2 changes: 1 addition & 1 deletion src/components/WidgetForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import reduxForm from 'redux-form';
import widgetValidation, {colors} from '../validation/widgetValidation';
import * as widgetActions from '../actions/widgetActions';
import * as widgetActions from '../ducks/widgets';

@connect(
state => ({
Expand Down
103 changes: 103 additions & 0 deletions src/ducks/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
const LOAD = 'redux-example/auth/LOAD';
const LOAD_SUCCESS = 'redux-example/auth/LOAD_SUCCESS';
const LOAD_FAIL = 'redux-example/auth/LOAD_FAIL';
const LOGIN = 'redux-example/auth/LOGIN';
const LOGIN_SUCCESS = 'redux-example/auth/LOGIN_SUCCESS';
const LOGIN_FAIL = 'redux-example/auth/LOGIN_FAIL';
const LOGOUT = 'redux-example/auth/LOGOUT';
const LOGOUT_SUCCESS = 'redux-example/auth/LOGOUT_SUCCESS';
const LOGOUT_FAIL = 'redux-example/auth/LOGOUT_FAIL';

const initialState = {
loaded: false
};

export default function reducer(state = initialState, action = {}) {
switch (action.type) {
case LOAD:
return {
...state,
loading: true
};
case LOAD_SUCCESS:
return {
...state,
loading: false,
loaded: true,
user: action.result
};
case LOAD_FAIL:
return {
...state,
loading: false,
loaded: false,
error: action.error
};
case LOGIN:
return {
...state,
loggingIn: true
};
case LOGIN_SUCCESS:
return {
...state,
loggingIn: false,
user: action.result
};
case LOGIN_FAIL:
return {
...state,
loggingIn: false,
user: null,
loginError: action.error
};
case LOGOUT:
return {
...state,
loggingOut: true
};
case LOGOUT_SUCCESS:
return {
...state,
loggingOut: false,
user: null
};
case LOGOUT_FAIL:
return {
...state,
loggingOut: false,
logoutError: action.error
};
default:
return state;
}
}

export function isLoaded(globalState) {
return globalState.auth && globalState.auth.loaded;
}

export function load() {
return {
types: [LOAD, LOAD_SUCCESS, LOAD_FAIL],
promise: (client) => client.get('/loadAuth')
};
}

export function login(name) {
return {
types: [LOGIN, LOGIN_SUCCESS, LOGIN_FAIL],
promise: (client) => client.post('/login', {
data: {
name: name
}
})
};
}

export function logout() {
return {
types: [LOGOUT, LOGOUT_SUCCESS, LOGOUT_FAIL],
promise: (client) => client.get('/logout')
};
}
23 changes: 23 additions & 0 deletions src/ducks/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const INCREMENT = 'redux-example/counter/INCREMENT';

const initialState = {
count: 0
};

export default function reducer(state = initialState, action = {}) {
switch (action.type) {
case INCREMENT:
const {count} = state;
return {
count: count + 1
};
default:
return state;
}
}

export function increment() {
return {
type: INCREMENT
};
}
File renamed without changes.
21 changes: 13 additions & 8 deletions src/reducers/info.js → src/ducks/info.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import {
INFO_LOAD,
INFO_LOAD_SUCCESS,
INFO_LOAD_FAIL
} from '../actions/actionTypes';
const LOAD = 'redux-example/LOAD';
const LOAD_SUCCESS = 'redux-example/LOAD_SUCCESS';
const LOAD_FAIL = 'redux-example/LOAD_FAIL';

This comment has been minimized.

Copy link
@marcenuc

marcenuc Nov 16, 2015

I think these should be 'redux-example/info/...'. Right?

This comment has been minimized.

Copy link
@erikras

erikras Nov 16, 2015

Owner

Yes, good catch.


const initialState = {
loaded: false
};

export default function info(state = initialState, action = {}) {
switch (action.type) {
case INFO_LOAD:
case LOAD:
return {
...state,
loading: true
};
case INFO_LOAD_SUCCESS:
case LOAD_SUCCESS:
return {
...state,
loading: false,
loaded: true,
data: action.result
};
case INFO_LOAD_FAIL:
case LOAD_FAIL:
return {
...state,
loading: false,
Expand All @@ -37,3 +35,10 @@ export default function info(state = initialState, action = {}) {
export function isLoaded(globalState) {
return globalState.info && globalState.info.loaded;
}

export function load() {
return {
types: [LOAD, LOAD_SUCCESS, LOAD_FAIL],
promise: (client) => client.get('/loadInfo')
};
}
Loading

0 comments on commit 3fdf194

Please sign in to comment.