-
Notifications
You must be signed in to change notification settings - Fork 17
Decorator #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pconerly
wants to merge
1
commit into
jasonslyvia:master
Choose a base branch
from
pconerly:decorator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Decorator #10
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| { "stage": 1 } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /** | ||
| * react-menu-aim is a React Mixin heavily inspired by jQuery-menu-aim. All rights | ||
| * reserved by the original author. | ||
| * | ||
| * https://github.com/jasonslyvia/react-menu-aim | ||
| * https://github.com/kamens/jQuery-menu-aim | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| // import {on, off, handleMouseMoveDocument, activate, getActivateDelay, mousemoveListener, mouseLocs} from './src/core.js'; | ||
| import {on, off, handleMouseMoveDocument, activate, getActivateDelay, menuAimModel} from './src/core.js'; | ||
|
|
||
|
|
||
| function possiblyActivate(rowIdentifier, handler, config) { | ||
| var delay = getActivateDelay.call(this, config); | ||
|
|
||
| if (delay) { | ||
| var self = this; | ||
| this.__reactMenuAimTimer = setTimeout(function(){ | ||
| possiblyActivate.call(self, rowIdentifier, handler, config); | ||
| }, delay); | ||
| } | ||
| else { | ||
| handler(rowIdentifier); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @export | ||
| */ | ||
| export default function reactMenuAimDecorator(reactMenuAimConfig) { | ||
| return function (ComposedComponent) { | ||
| return class MenuAimDecorator extends React.Component { | ||
|
|
||
| __getMouseMoveDocumentHandler() { | ||
| if (!this.__mouseMoveDocumentHandler) { | ||
| this.__mouseMoveDocumentHandler = handleMouseMoveDocument.bind(this); | ||
| } | ||
|
|
||
| return this.__mouseMoveDocumentHandler; | ||
| } | ||
|
|
||
| componentDidMount() { | ||
| if (menuAimModel.mousemoveListener === 0) { | ||
| on(document, 'mousemove', this.__getMouseMoveDocumentHandler()); | ||
| } | ||
|
|
||
| menuAimModel.mousemoveListener += 1; | ||
| } | ||
|
|
||
| componentWillUnmount() { | ||
| menuAimModel.mousemoveListener -= 1; | ||
|
|
||
| if (menuAimModel.mousemoveListener === 0) { | ||
| off(document, 'mousemove', this.__getMouseMoveDocumentHandler()); | ||
| menuAimModel.mouseLocs = []; | ||
| } | ||
|
|
||
| clearTimeout(this.__reactMenuAimTimer); | ||
| this.__reactMenuAimTimer = null; | ||
| this.__mouseMoveDocumentHandler = null; | ||
| } | ||
|
|
||
| /** | ||
| * @param {function} handler The true event handler for your app | ||
| * @param {object} e React's synthetic event object | ||
| */ | ||
| handleMouseLeaveMenu(handler, e) { | ||
| if (this.__reactMenuAimTimer) { | ||
| clearTimeout(this.__reactMenuAimTimer); | ||
| } | ||
|
|
||
| if (typeof handler === 'function') { | ||
| handler.call(this, e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param {number} rowIdentifier The identifier of current row, ie. index or name | ||
| * @param {function} handler The true event handler for your app | ||
| * @param {object} e React's synthetic event object | ||
| */ | ||
| handleMouseEnterRow(rowIdentifier, handler) { | ||
| if (this.__reactMenuAimTimer) { | ||
| clearTimeout(this.__reactMenuAimTimer); | ||
| } | ||
|
|
||
| // possiblyActivate.call(this, rowIdentifier, handler, reactMenuAimConfig); | ||
| possiblyActivate.call(this, rowIdentifier, handler, reactMenuAimConfig); | ||
| } | ||
|
|
||
| render() { | ||
| return <ComposedComponent {...this.props} | ||
| handleMouseLeaveMenu={this.handleMouseLeaveMenu.bind(this)} | ||
| handleMouseEnterRow={this.handleMouseEnterRow.bind(this)} | ||
| ></ComposedComponent>; | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import React from 'react'; | ||
| import reactMenuAimDecorator from '../../decorator'; | ||
|
|
||
|
|
||
| @reactMenuAimDecorator({ | ||
| submenuDirection: 'right', | ||
| menuSelector: '.menu', | ||
| delay: 300, | ||
| tolerance: 75}) | ||
| export default class Menu extends React.Component { | ||
|
|
||
| constructor(props) { | ||
| super(); | ||
|
|
||
| this.state = { | ||
| activeMenuIndex: 0, | ||
| }; | ||
| } | ||
|
|
||
| handleSwitchMenuIndex(index) { | ||
| this.setState({ | ||
| activeMenuIndex: index | ||
| }); | ||
| } | ||
|
|
||
| render() { | ||
| var containerClassName = 'menu-container ' + this.props.submenuDirection; | ||
|
|
||
| var subMenuStyle = {}; | ||
| if (this.props.submenuDirection === 'below') { | ||
| subMenuStyle.left = this.state.activeMenuIndex * 140; | ||
| } | ||
|
|
||
| return ( | ||
| <div className={containerClassName}> | ||
| <ul className="menu" onMouseLeave={this.props.handleMouseLeaveMenu}> | ||
| {this.props.menuData.map((menu, index) => { | ||
| var className = 'menu-item'; | ||
| if (index === this.state.activeMenuIndex) { | ||
| className += ' active'; | ||
| } | ||
|
|
||
| return ( | ||
| <li className={className} key={index} | ||
| onMouseEnter={() =>{ | ||
| this.props.handleMouseEnterRow(index, this.handleSwitchMenuIndex.bind(this)); | ||
| }}> | ||
| {menu.name} | ||
| </li> | ||
| ); | ||
| })} | ||
| </ul> | ||
| <ul className="sub-menu" style={subMenuStyle}> | ||
| {this.props.menuData[this.state.activeMenuIndex].subMenu.map(((subMenu, index) => { | ||
| return ( | ||
| <li className="sub-menu-item" key={index}>{subMenu}</li> | ||
| ); | ||
| }))} | ||
| </ul> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| Menu.defaultProps = { | ||
| submenuDirection: 'right', | ||
| }; | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use Babel 5? Here's a config for Babel 6:
{ "presets": [ "es2015", "stage-1", "react" ], "plugins": [ "transform-decorators-legacy" ] }Shouldn't we also have babel in the devDependencies:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, you are right. I was using babel6, I think that babel6 is just backwards-compatible?
I was enabling stage:1 to turn on decorators.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Umm, Babel 6 is not backwards compatible, you must have Babel 5 running somehow (?). Decorators have been removed from stage 1 and are now in the transform-decorators-legacy plugin. So I guess this could be the config:
{ "presets": [ "es2015", "react" ], "plugins": [ "transform-decorators-legacy" ] }Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I was confused. The repo is using
babelifyversion 6.1.2, which usesbabel-coreversion 5: https://github.com/babel/babelify/blob/v6.1.2/package.jsonAnyway, upgrading to babel6 is something that we should do, but it's out-of-scope for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
babelifyis only intended for demos that using ES6 syntax, the module itself (index.js) is written in pure ES5 so no transformation is needed.But I guess it's been a long time since I released this repo initially, the tool chains changed a lot, maybe it worth upgrading to state of the art.