Add redux and initial reducer
This commit is contained in:
parent
6c933f2585
commit
50161bc2a9
3
.babelrc
3
.babelrc
|
@ -1,4 +1,3 @@
|
||||||
{
|
{
|
||||||
"plugins": ["transform-react-jsx"],
|
"presets": ["env", "stage-0", "react", "es2015"]
|
||||||
"presets": ["env"]
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
"babel-core": "^6.25.0",
|
"babel-core": "^6.25.0",
|
||||||
"babel-loader": "^7.1.1",
|
"babel-loader": "^7.1.1",
|
||||||
"babel-preset-env": "^1.6.0",
|
"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",
|
"css-loader": "^0.28.4",
|
||||||
"react": "^15.6.1",
|
"react": "^15.6.1",
|
||||||
"react-dom": "^15.6.1",
|
"react-dom": "^15.6.1",
|
||||||
|
|
1
src/actions/resources.js
Normal file
1
src/actions/resources.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export const UPDATE_RESOURCES = 'UPDATE_RESOURCES';
|
11
src/index.js
11
src/index.js
|
@ -1,10 +1,15 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render } from 'react-dom';
|
import { render } from 'react-dom';
|
||||||
|
import { Provider } from 'react-redux';
|
||||||
|
|
||||||
|
import store from './store';
|
||||||
import scss from '../scss/base.scss';
|
import scss from '../scss/base.scss';
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<h1>
|
<Provider store={store}>
|
||||||
Hello world!
|
<h1>
|
||||||
</h1>,
|
Hello world!
|
||||||
|
</h1>
|
||||||
|
</Provider>,
|
||||||
document.getElementById('root')
|
document.getElementById('root')
|
||||||
);
|
);
|
||||||
|
|
8
src/reducers/index.js
Normal file
8
src/reducers/index.js
Normal 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
14
src/reducers/torrents.js
Normal 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
10
src/store.js
Normal 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;
|
Loading…
Reference in New Issue
Block a user