Permalink
Browse files

Autodux

  • Loading branch information...
imjoehaines committed Mar 20, 2018
1 parent d4a179f commit f4d9f8c80d39d3da9c88506e8b54c2d65d88915f
Showing with 42 additions and 46 deletions.
  1. +1 −0 package.json
  2. +4 −3 src/Email/container.js
  3. +4 −5 src/EmailForm/container.js
  4. +2 −1 src/Username/container.js
  5. +4 −5 src/UsernameForm/container.js
  6. +17 −32 src/ducks/index.js
  7. +10 −0 yarn.lock
@@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"autodux": "^3.0.0",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-redux": "^5.0.7",
@@ -1,9 +1,10 @@
import { connect } from 'react-redux'

import Username from './component'
import Email from './component'
import { getEmail } from '../ducks'

export default connect(
state => ({
email: state.email
email: getEmail(state)
})
)(Username)
)(Email)
@@ -1,14 +1,13 @@
import { connect } from 'react-redux'

import Email from './component'

import { setEmail } from '../ducks'
import EmailForm from './component'
import { setEmail, getEmail } from '../ducks'

export default connect(
state => ({
email: state.email
email: getEmail(state)
}),
dispatch => ({
handleEmailChange: event => dispatch(setEmail(event.target.value))
})
)(Email)
)(EmailForm)
@@ -1,9 +1,10 @@
import { connect } from 'react-redux'

import Username from './component'
import { getUsername } from '../ducks'

export default connect(
state => ({
username: state.username
username: getUsername(state)
})
)(Username)
@@ -1,14 +1,13 @@
import { connect } from 'react-redux'

import Username from './component'

import { setUsername } from '../ducks'
import UsernameForm from './component'
import { setUsername, getUsername } from '../ducks'

export default connect(
state => ({
username: state.username
username: getUsername(state)
}),
dispatch => ({
handleUsernameChange: event => dispatch(setUsername(event.target.value))
})
)(Username)
)(UsernameForm)
@@ -1,37 +1,22 @@
const initialState = {
username: 'Anonymous',
email: 'anonymous@example.com'
}
import autodux from 'autodux'

export default (state = initialState, { type, payload }) => {
switch (type) {
case SET_USERNAME:
return {
...state,
username: payload
}

case SET_EMAIL:
return {
...state,
email: payload
}

default:
return state
const {
reducer,
actions: {
setUsername,
setEmail
},
selectors: {
getUsername,
getEmail
}
} = autodux({
initial: {
username: 'Anonymous',
email: 'anonymous@example.com'
}
}

const SET_USERNAME = 'SET_USERNAME'

export const setUsername = username => ({
type: SET_USERNAME,
payload: username
})

const SET_EMAIL = 'SET_EMAIL'
export default reducer

export const setEmail = email => ({
type: SET_EMAIL,
payload: email
})
export { setUsername, setEmail, getUsername, getEmail }

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit f4d9f8c

Please sign in to comment.