Add redux and initial reducer

This commit is contained in:
Drew DeVault 2017-08-20 11:57:57 -04:00
parent 6c933f2585
commit 50161bc2a9
7 changed files with 45 additions and 5 deletions

View File

@ -1,4 +1,3 @@
{
"plugins": ["transform-react-jsx"],
"presets": ["env"]
"presets": ["env", "stage-0", "react", "es2015"]
}

View File

@ -19,6 +19,9 @@
"babel-core": "^6.25.0",
"babel-loader": "^7.1.1",
"babel-preset-env": "^1.6.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"css-loader": "^0.28.4",
"react": "^15.6.1",
"react-dom": "^15.6.1",

1
src/actions/resources.js Normal file
View File

@ -0,0 +1 @@
export const UPDATE_RESOURCES = 'UPDATE_RESOURCES';

View File

@ -1,10 +1,15 @@
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import store from './store';
import scss from '../scss/base.scss';
render(
<Provider store={store}>
<h1>
Hello world!
</h1>,
</h1>
</Provider>,
document.getElementById('root')
);

8
src/reducers/index.js Normal file
View File

@ -0,0 +1,8 @@
import { combineReducers } from 'redux';
import torrents from './torrents';
const root = combineReducers({
torrents
});
export default root;

14
src/reducers/torrents.js Normal file
View File

@ -0,0 +1,14 @@
import { UPDATE_RESOURCES } from '../actions/resources';
export default function torrents(state = {}, action) {
switch (action.type) {
case UPDATE_RESOURCES:
return {
...state,
...action.resources
.filter(r => r.type === "torrent")
.reduce((s, r) => s[r.id] = r, {})
};
}
return state;
}

10
src/store.js Normal file
View File

@ -0,0 +1,10 @@
import { createStore } from 'redux';
import reducer from './reducers';
const store = createStore(
reducer,
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);
export default store;