Skip to content

Commit 927df4f

Browse files
committed
Switch to redux
1 parent eb3622c commit 927df4f

14 files changed

+99
-79
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ All the changes can be found below. Order used:
99
- Fixed
1010
- Security
1111

12+
## master
13+
14+
### Changed
15+
- Replace `webpack-dev-server` with `react-hmre`.
16+
- Revert to use `createClass`.
17+
- Switch to Redux from Flummox.
18+
19+
### Fixed
20+
- Menu goes outside when closer to edges
21+
1222
## v0.3.0
1323

1424
### Added

examples.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ module.exports = {
2626
compressor: {
2727
warnings: false
2828
}
29+
}),
30+
new webpack.DefinePlugin({
31+
"process.env": {
32+
"NODE_ENV": JSON.stringify("production")
33+
}
2934
})
3035
]
3136
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
"dependencies": {
3232
"autobind-decorator": "^1.3.3",
3333
"classnames": "^2.2.3",
34-
"flummox": "^3.6.8",
3534
"invariant": "^2.2.0",
3635
"lodash.isobject": "^3.0.2",
37-
"object-assign": "^4.0.1"
36+
"object-assign": "^4.0.1",
37+
"redux": "^3.3.1"
3838
},
3939
"peerDependencies": {
4040
"react": "^0.14.0",

server.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ var express = require("express"),
99
config.module.loaders[0].query = {presets: ["react-hmre"]};
1010
config.entry.unshift("webpack-hot-middleware/client");
1111

12-
config.plugins.push(
12+
config.plugins = [
13+
new webpack.optimize.OccurenceOrderPlugin(),
14+
new webpack.optimize.UglifyJsPlugin({
15+
compressor: {
16+
warnings: false
17+
}
18+
}),
1319
new webpack.HotModuleReplacementPlugin(),
1420
new webpack.NoErrorsPlugin()
15-
);
21+
];
1622

1723
var app = express();
1824

src/context-menu.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"use strict";
22

33
import React from "react";
4-
import FluxComponent from "flummox/component";
5-
import flux from "./flux";
4+
import store from "./redux/store";
65
import ContextMenuContainer from "./menu-container";
76

87
let { PropTypes } = React;
@@ -12,11 +11,29 @@ const ContextMenu = React.createClass({
1211
propTypes: {
1312
identifier: PropTypes.string.isRequired
1413
},
14+
childContextTypes: {
15+
store: PropTypes.object
16+
},
17+
getInitialState() {
18+
return store.getState();
19+
},
20+
getChildContext() {
21+
return {
22+
store
23+
};
24+
},
25+
componentDidMount() {
26+
this.unsubscribe = store.subscribe(this.handleUpdate);
27+
},
28+
componentWillUnmount() {
29+
if (this.unsubscribe) this.unsubscribe();
30+
},
31+
handleUpdate() {
32+
this.setState(this.getInitialState());
33+
},
1534
render() {
1635
return (
17-
<FluxComponent flux={flux} connectToStores={["menu"]}>
18-
<ContextMenuContainer {...this.props}/>
19-
</FluxComponent>
36+
<ContextMenuContainer {...this.props} {...this.state}/>
2037
);
2138
}
2239
});

src/contextmenu-layer.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ReactDOM from "react-dom";
55
import invariant from "invariant";
66
import _isObject from "lodash.isobject";
77

8-
import flux from "./flux";
8+
import store from "./redux/store";
99

1010
let { Component } = React;
1111

@@ -54,13 +54,14 @@ export default function(identifier, configure) {
5454

5555
event.preventDefault();
5656

57-
const actions = flux.getActions("menu");
58-
59-
actions.setParams({
60-
x: event.clientX,
61-
y: event.clientY,
62-
currentItem,
63-
isVisible: typeof identifier === "function" ? identifier(this.props) : identifier
57+
store.dispatch({
58+
type: "SET_PARAMS",
59+
data: {
60+
x: event.clientX,
61+
y: event.clientY,
62+
currentItem,
63+
isVisible: typeof identifier === "function" ? identifier(this.props) : identifier
64+
}
6465
});
6566
}
6667
},

src/flux/actions.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/flux/index.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/flux/store.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/menu-container.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import classnames from "classnames";
66

77
const MenuContainer = React.createClass({
88
displayName: "MenuContainer",
9+
contextTypes: {
10+
store: React.PropTypes.object.isRequired
11+
},
912
getInitialState() {
1013
return {
1114
position: "fixed",
@@ -77,9 +80,12 @@ const MenuContainer = React.createClass({
7780
}
7881
},
7982
_hideMenu() {
80-
this.props.flux.getActions("menu").setParams({
81-
isVisible: false,
82-
currentItem: {}
83+
this.context.store.dispatch({
84+
type: "SET_PARAMS",
85+
data: {
86+
isVisible: false,
87+
currentItem: {}
88+
}
8389
});
8490
},
8591
_bindHandlers() {

0 commit comments

Comments
 (0)