Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit 2bf707b

Browse files
committed
replace merge with assign and remove children cloning
1 parent 9f6e68a commit 2bf707b

File tree

6 files changed

+35
-28
lines changed

6 files changed

+35
-28
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
bundle.js
3+
bundle.js.map
34
index.html

examples.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = {
66
entry: "./examples/index.js",
77
output: {
88
filename: "./bundle.js",
9+
sourceMapFileName: "./bundle.js.map"
910
},
1011
module: {
1112
loaders: [
@@ -16,6 +17,7 @@ module.exports = {
1617
}
1718
]
1819
},
20+
devtool: "source-map",
1921
plugins: [
2022
new webpack.optimize.OccurenceOrderPlugin(),
2123
new webpack.optimize.UglifyJsPlugin({

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
"version": "0.1.0",
44
"description": "Context Menu implemented in React",
55
"main": "modules/index.js",
6-
"keywords": ["react", "reactjs", "react-component", "contextmenu", "rightclick" ],
6+
"keywords": [
7+
"react",
8+
"reactjs",
9+
"react-component",
10+
"contextmenu",
11+
"rightclick"
12+
],
713
"scripts": {
814
"dist": "./node_modules/.bin/webpack --progress --profile --colors",
915
"module": "./node_modules/.bin/babel src --out-dir modules",
@@ -26,7 +32,7 @@
2632
"flummox": "^3.5.2",
2733
"invariant": "^2.1.0",
2834
"lodash.isobject": "^3.0.2",
29-
"lodash.merge": "^3.3.2",
35+
"object-assign": "^3.0.0",
3036
"react": "^0.13.3"
3137
},
3238
"devDependencies": {

src/menu-container.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ const MenuContainer = React.createClass({
5454

5555
return menuStyles;
5656
},
57-
_hideMenu() {
58-
this.props.flux.getActions("menu").setParams({
59-
isVisible: false,
60-
currentItem: {}
61-
});
62-
},
6357
_outsideClickHandler(event) {
6458
let localNode = this.localNode,
6559
source = event.target,
@@ -102,9 +96,7 @@ const MenuContainer = React.createClass({
10296
return (
10397
<div className={classes} style={this.state}>
10498
<ul ref="menu" className="dropdown-menu">
105-
{React.Children.map(this.props.children, (child) => {
106-
return React.cloneElement(child, { currentItem, hideMenu: this._hideMenu });
107-
})}
99+
{this.props.children}
108100
</ul>
109101
</div>
110102
);

src/menu-item.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,56 @@
11
"use strict";
22

3-
import React from "react";
3+
import React, { PropTypes } from "react";
44
import classnames from "classnames";
5-
import _merge from "lodash.merge";
6-
7-
let { PropTypes } = React;
5+
import assign from "object-assign";
6+
import flux from "./flux";
7+
import monitor from "./monitor";
88

99
const MenuItem = React.createClass({
1010
displayName: "MenuItem",
1111
propTypes: {
12+
data: PropTypes.object,
1213
disabled: PropTypes.bool,
13-
selected: PropTypes.bool,
1414
divider: PropTypes.bool,
15-
data: PropTypes.object,
15+
onClick: PropTypes.func,
1616
onSelect: PropTypes.func,
17-
onClick: PropTypes.func
17+
selected: PropTypes.bool
1818
},
1919
getDefaultProps() {
2020
return {
2121
disabled: false,
2222
selected: false,
23-
data: null
23+
data: {}
2424
};
2525
},
2626
handleClick(event) {
27-
let { disabled, onSelect, onClick, currentItem, data } = this.props;
27+
let { disabled, onSelect, onClick, data } = this.props;
2828

2929
if (disabled) {
3030
event.preventDefault();
3131
return;
3232
}
3333

34+
assign(data, monitor.getItem());
35+
3436
if (typeof onSelect === "function") {
3537
event.preventDefault();
36-
onSelect(_merge(currentItem, data));
37-
this.props.hideMenu();
38+
onSelect(data);
39+
this.hideMenu();
3840
return;
3941
}
4042

4143
if (typeof onClick === "function") {
42-
onClick(event, _merge(currentItem, data));
44+
onClick(event, data);
4345
}
4446

45-
this.props.hideMenu();
47+
this.hideMenu();
48+
},
49+
hideMenu() {
50+
flux.getActions("menu").setParams({
51+
isVisible: false,
52+
currentItem: {}
53+
});
4654
},
4755
render() {
4856
let { divider, disabled, selected, children } = this.props;

src/monitor.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
import flux from "./flux";
44

5-
const { state } = flux.getStore("menu");
6-
75
export default {
86
getItem() {
9-
return state.currentItem;
7+
return flux.getStore("menu").state.currentItem;
108
},
119
getPosition() {
12-
let { x, y } = state;
10+
let { x, y } = flux.getStore("menu").state;
1311
return {x, y};
1412
}
1513
};

0 commit comments

Comments
 (0)