From 2cb7d35a924b0e1cf3c72bc6be6b78e0916e3f2c Mon Sep 17 00:00:00 2001 From: Piper Merriam Date: Wed, 8 Feb 2017 10:53:18 -0700 Subject: [PATCH] add example --- www-src/js/actions/index.jsx | 2 ++ www-src/js/actions/thing.jsx | 10 ++++++++++ www-src/js/actions/types.jsx | 2 ++ www-src/js/components/pages/SiteIndex.jsx | 10 +++++++++- www-src/js/reducers/index.jsx | 2 ++ www-src/js/reducers/thing.jsx | 22 ++++++++++++++++++++++ 6 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 www-src/js/actions/thing.jsx create mode 100644 www-src/js/reducers/thing.jsx diff --git a/www-src/js/actions/index.jsx b/www-src/js/actions/index.jsx index 3eb0ecd..3823ce5 100644 --- a/www-src/js/actions/index.jsx +++ b/www-src/js/actions/index.jsx @@ -3,6 +3,7 @@ import * as Web3Actions from './web3' import * as ChainActions from './chain' import * as ConfigActions from './config' import * as PackageIndexActions from './package_index' +import * as ThingActions from './thing' export default { ...PaginationActions, @@ -10,4 +11,5 @@ export default { ...ChainActions, ...ConfigActions, ...PackageIndexActions, + ...ThingActions, } diff --git a/www-src/js/actions/thing.jsx b/www-src/js/actions/thing.jsx new file mode 100644 index 0000000..f08e7e4 --- /dev/null +++ b/www-src/js/actions/thing.jsx @@ -0,0 +1,10 @@ +import TYPES from './types' + + + +export function setThing(value) { + return { + type: TYPES.SET_THING, + value: value, + } +} diff --git a/www-src/js/actions/types.jsx b/www-src/js/actions/types.jsx index 7631d64..48ca31c 100644 --- a/www-src/js/actions/types.jsx +++ b/www-src/js/actions/types.jsx @@ -22,4 +22,6 @@ export default { SET_RELEASE_HASH: 'SET_RELEASE_HASH', // release data SET_RELEASE_DATA: 'SET_RELEASE_DATA', + // Thing Setter + SET_THING: 'SET_THING' } diff --git a/www-src/js/components/pages/SiteIndex.jsx b/www-src/js/components/pages/SiteIndex.jsx index 939b238..0ffa6a4 100644 --- a/www-src/js/components/pages/SiteIndex.jsx +++ b/www-src/js/components/pages/SiteIndex.jsx @@ -4,12 +4,18 @@ import { Link } from 'react-router' import BSCard from '../bootstrap/BSCard' import FAIcon from '../common/FAIcon' import layoutStyles from '../../../css/layout.css' +import actions from '../../actions' function mapStateToProps(state) { - return {} + return { + thing: state.thing.get('thingValue') + } } export default connect(mapStateToProps)(React.createClass({ + setThing() { + this.props.dispatch(actions.setThing(5)) + }, render() { return (
@@ -22,6 +28,8 @@ export default connect(mapStateToProps)(React.createClass({

The Ethereum Package Registry

A package index for Ethereum smart contract packages.

Registry +

Thing is {this.props.thing}

+
diff --git a/www-src/js/reducers/index.jsx b/www-src/js/reducers/index.jsx index 95b9486..aa27b51 100644 --- a/www-src/js/reducers/index.jsx +++ b/www-src/js/reducers/index.jsx @@ -7,6 +7,7 @@ import config from './config' import pagination from './pagination' import web3 from './web3' import packageIndex from './package_index' +import thing from './thing' export default combineReducers({ @@ -15,6 +16,7 @@ export default combineReducers({ pagination, web3, packageIndex, + thing, routing: routerReducer, form: formReducer, }) diff --git a/www-src/js/reducers/thing.jsx b/www-src/js/reducers/thing.jsx new file mode 100644 index 0000000..2c1d68c --- /dev/null +++ b/www-src/js/reducers/thing.jsx @@ -0,0 +1,22 @@ +import Immutable from 'immutable' +import TYPES from '../actions/types' + +var initialState = Immutable.fromJS({ + thingValue: 'initial-value' +}) + +export default function(state, action) { + if (state === undefined) { + return initialState + } + + var newState = state + + switch (action.type) { + case TYPES.SET_THING: + newState = newState.set('thingValue', action.value) + break + } + + return newState +}