Skip to content

Commit

Permalink
v3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
glitch100 committed Mar 25, 2017
1 parent e171569 commit 6d7dd9a
Show file tree
Hide file tree
Showing 23 changed files with 240 additions and 34 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

### v0.3.0
> Release Date: 25/03/2017
* Removed old demo page in favour of slow buildout via webpack2
* Fixed stateless components not working as expected
* Adding in groundwork for reverse explicit mode
* Minor adjustments
* Doc update

### v0.2.0
> Release Date: 31/01/2016
* Added in start of demo page
Expand Down
23 changes: 0 additions & 23 deletions OLD_DEMO.js

This file was deleted.

14 changes: 14 additions & 0 deletions demo/components/StockApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import TraderCTA from './TraderCTA';
import StocksTable from './StocksTable';
import './style.scss';

export default function StockApp() {
return (
<div>
<p>Synape Demo Page for Stock Application (In Progress)</p>
<TraderCTA />
<StocksTable />
</div>
);
}
29 changes: 29 additions & 0 deletions demo/components/StocksTable/StocksTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { PropTypes } from 'react';

export default class StocksTable extends React.Component {
static propTypes = {
stocks: PropTypes.any.isRequired,
addStock: PropTypes.func.isRequired,
};

constructor(props) {
super(props);
}

renderStocks = () => {
return this.props.stocks.map((p, i) => {
return (
<p key={i}>{p.name}</p>
);
});
}

render() {
return (
<div>
<h2>Stocks Table</h2>
{this.renderStocks()}
</div>
);
}
}
16 changes: 16 additions & 0 deletions demo/components/StocksTable/StocksTableContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const mapStateToProps = (state) => {
return {
stocks: state.stocks.allStocks,
};
};

export const mapDispatchToProps = (dispatch) => {
return {
addStock: (name, currentValue, previousValue) => dispatch({
type: 'ADD_STOCK',
name,
currentValue,
previousValue,
}),
};
};
5 changes: 5 additions & 0 deletions demo/components/StocksTable/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { synapse } from 'redux-synapse';
import StocksTable from './StocksTable';
import { mapStateToProps, mapDispatchToProps } from './StocksTableContainer';

export default synapse(mapStateToProps, mapDispatchToProps, ['stocks'])(StocksTable);
35 changes: 35 additions & 0 deletions demo/components/TraderCTA/TraderCTA.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { PropTypes } from 'react';

export default class TraderCTA extends React.Component {
static propTypes = {
name: PropTypes.string.isRequired,
setName: PropTypes.func.isRequired,
setAccountValue: PropTypes.func.isRequired,
};

constructor(props) {
super(props);
this.state = {
name: props.name,
};
}

handleChange = (e) => {
this.setState({
name: e.target.value,
});
}

handleClick = () => {
this.props.setName(this.state.name);
}

render() {
return (
<div>
<input type="text" onChange={this.handleChange} value={this.state.name} />
<button onClick={this.handleClick}>Set Name</button>
</div>
);
}
}
16 changes: 16 additions & 0 deletions demo/components/TraderCTA/TraderCTAContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const mapStateToProps = (state) => {
return {
name: state.trader.name,
accountValue: state.trader.accountValue,
};
};

export const mapDispatchToProps = (dispatch) => {
return {
setName: (name) => dispatch({
type: 'SET_TRADER_NAME',
name,
}),
setAccountValue: () => {},
};
};
5 changes: 5 additions & 0 deletions demo/components/TraderCTA/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { synapse } from 'redux-synapse';
import TraderCTA from './TraderCTA';
import { mapStateToProps, mapDispatchToProps } from './TraderCTAContainer';

export default synapse(mapStateToProps, mapDispatchToProps, ['trader'])(TraderCTA);
7 changes: 7 additions & 0 deletions demo/components/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$font-stack: Helvetica, sans-serif;
$primary-color: red;

body {
font: 100% $font-stack;
color: $primary-color;
}
6 changes: 3 additions & 3 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>Synapse Todo Demo</title>
<title>Synapse Demo</title>
<meta charset="utf-8"/>
</head>
<body>
<div id="app">
<h1>Loading Synapse Demo...</h1>
<h1>=Loading=</h1>
</div>
<script src="./dist/bundle.js" ></script>
<script src="./dist/app.bundle.js" ></script>
</body>
</html>
8 changes: 4 additions & 4 deletions demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import React from 'react';
import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
import { Provider } from 'redux-synapse';
import thunkMiddleware from 'redux-thunk';
import reducers from './stock/reducers';
import StockApp from './stock/components/StockApp';
import reducers from './reducers';
import StockApp from './components/StockApp';

const composeEnhancers = typeof window !== 'undefined'
&& window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
: compose;

const createStoreWithMiddleware = composeEnhancers(applyMiddleware(thunkMiddleware))(createStore);
const store = createStoreWithMiddleware(combineReducers(reducers));
const createComposedStore = composeEnhancers(applyMiddleware(thunkMiddleware))(createStore);
const store = createComposedStore(combineReducers(reducers));

ReactDOM.render(
<Provider store={store}>
Expand Down
9 changes: 9 additions & 0 deletions demo/records/StockRecord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Record, List } from 'immutable';

export default Record({
name: '',
currentValue: 0,
previousValue: 0,
valueDifference: 0,
bidHistory: List(),
});
12 changes: 12 additions & 0 deletions demo/records/StocksRecord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Record, List } from 'immutable';

const OptionsRecord = Record({
updateSpeedMs: 2500,
});

export default Record({
stockTotalValue: 0,
allStocks: List(),
options: new OptionsRecord(),
});

6 changes: 6 additions & 0 deletions demo/records/TraderRecord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Record } from 'immutable';

export default Record({
name: 'NONE_SET',
accountValue: 0,
});
7 changes: 7 additions & 0 deletions demo/reducers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import trader from './traderReducer';
import stocks from './stockSReducer';

export default {
trader,
stocks,
};
37 changes: 37 additions & 0 deletions demo/reducers/stocksReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import StocksRecord from '../records/StocksRecord';
import StockRecord from '../records/StockRecord';
import { List } from 'immutable';

const defaultState = new StocksRecord({
allStocks: List([
new StockRecord({
name: 'FTSE',
currentValue: 1000,
previousValue: 750,
valueDifference: 250,
bidHistory: List([
0,
]),
}),
]),
});

const stock = (state = defaultState, action) => {
let newState;
switch (action.type) {
case 'SET_UPDATE_SPEED':
newState = state.setIn(['options', 'updateSpeedMs'], action.updateSpeedMs);
prepareNotification(['stock-options']);
return newState;
case 'ADD_STOCK':
let allStocks = state.allStocks;
allStocks = allStocks.push(new StockRecord(action.stock));
newState = state.set('allStocks', allStocks);
prepareNotification(['stocks']);
return newState;
default:
return state;
}
};

export default stock;
20 changes: 20 additions & 0 deletions demo/reducers/traderReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import TraderRecord from '../records/TraderRecord';
import { prepareNotification } from 'redux-synapse';

const trader = (state = new TraderRecord(), action) => {
let newState;
switch (action.type) {
case 'SET_TRADER_VALUE':
newState = state.set('accountValue', action.accountValue);
prepareNotification(['trader']);
return newState;
case 'SET_TRADER_NAME':
newState = state.set('name', action.name);
prepareNotification(['trader']);
return newState;
default:
return state;
}
};

export default trader;
Empty file removed demo/stock/components/StockApp.js
Empty file.
Empty file removed demo/stock/reducers/index.js
Empty file.
2 changes: 1 addition & 1 deletion demo/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const config = {
],
},
output: {
path: __dirname + '/stock/dist',
path: __dirname + '/dist',
filename: '[name].bundle.js',
},
resolve: {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-synapse",
"version": "0.2.1",
"version": "0.3.0",
"main": "lib/index.js",
"files": [
"src",
Expand All @@ -22,7 +22,7 @@
"watch:demo": "webpack --watch ./demo --config ./demo/webpack.config.js",
"lint": "eslint ./src",
"test": "jest",
"test:tc": "jest --runInBand",
"test:tc": "jest --runInBand"
},
"author": "Jon Evans ([email protected])",
"license": "MIT",
Expand Down
5 changes: 4 additions & 1 deletion src/components/synapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export default (mapStateToProps, mapDispatchToProps, pathArray) => {
class Synapse extends Component {
constructor(props, context) {
super(props, context);
this.oldProps = msp(context.store.getState(), props);
this.oldProps = {
...msp(context.store.getState(), props),
...mapDispatchToProps ? mapDispatchToProps(context.store.dispatch) : {},
};
synapseProps = this.oldProps;
this.state = {
version: 0,
Expand Down

0 comments on commit 6d7dd9a

Please sign in to comment.