Skip to content

Commit

Permalink
finished simple example
Browse files Browse the repository at this point in the history
  • Loading branch information
fidgety committed Jan 18, 2017
1 parent 4462255 commit 5fc7fb5
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 8 deletions.
4 changes: 2 additions & 2 deletions client/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { valueAdded } from './constants';
import { valueAdded } from '../constants';

export const addValue = value => {
export const add = value => {
return {
type: valueAdded,
value
Expand Down
24 changes: 24 additions & 0 deletions client/components/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { add } from '../actions';

const addComponent = store => {
const valueAdded = () => {
const value = document.getElementById('text-value').value;
document.getElementById('text-value').value = '';
store.dispatch(add(value));
};

const render = () => {
const input = '<input type="text" id="text-value"/><button id="add-button">add</button>';
document.write(input);
document.getElementById('add-button')
.addEventListener('click', valueAdded);
};

// store.subscribe(() => {
// render();
// });

render();
};

export default addComponent;
18 changes: 18 additions & 0 deletions client/components/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const list = store => {
const render = items => {
const listItems = store.getState().list.values;

const listLis = listItems.map(item => `<li>${item}</li>`).join('');
const html = `<ul>${listLis}</ul>`;

document.getElementById('list').innerHTML = html;
};

store.subscribe(() => {
render();
});

render();
};

export default list;
4 changes: 3 additions & 1 deletion client/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import store from './store';

document.write('hi');
import page1 from './pages/page1';

page1(store);
10 changes: 10 additions & 0 deletions client/pages/page1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import list from '../components/list';
import add from '../components/add';

const page1 = store => {
document.write('<div id="list"></div><div id="add"></div>');
list(store);
add(store);
};

export default page1;
4 changes: 2 additions & 2 deletions client/reducers/reducerA.js → client/reducers/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { valueAdded } from '../constants';
export default (state, action) => {
if (!state) {
return {
values: []
values: ['a']
};
}

if (action.type === valueAdded) {
state.values = state.values.concat([action.newValue]);
state.values = state.values.concat([action.value]);
}

return state;
Expand Down
4 changes: 2 additions & 2 deletions client/store/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createStore, applyMiddleware, combineReducers } from 'redux';
import thunkMiddleware from 'redux-thunk';
import reducerA from '../reducers/reducerA';
import list from '../reducers/list';
import createLogger from 'redux-logger';

const reducers = combineReducers({
reducerA
list
});

const createStoreWithMiddleware = applyMiddleware(
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const config = {
};


if (env === 'dev') {
if (env !== 'prod') {
new WebpackDevServer(webpack(config), {
contentBase: './public',
historyApiFallback: true,
Expand Down

0 comments on commit 5fc7fb5

Please sign in to comment.