Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

navlink performance improvement, provide createNavLink, remove handleRoutes #70

Merged
merged 1 commit into from
Jul 28, 2015

Conversation

kaesonho
Copy link
Contributor

Higher order component pattern is good but since users might use NavLink everywhere, so having connectToStore -> handleRoute -> NavLink -> a should be too much and the performance might be able to be improved.

  1. We only use makePath and isActive from routeStore, use it directly, so that we can reduce two higher component and we can remove the eventListeners to the RouteStore. previously the RouteStore might propagate hundreds emitChange to every NavLink on the page.
  2. move out NavLink functions to be navLinkUtils, so that if users have the use case they can compose there own NavLink.
    provide createNavLink so that users can overwrite the attribute with whatever they want, maybe add a mixin or a custom click event handler

@mridgway @redonkulus @lingyan @Vijar


describe('componentWillUnmount', function () {
it('should update active state', function () {
var div = document.createElement('div');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this test was removed? I think the test was misnamed, but should still be valid right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when we remove handleRoute (also connectToStore) I think we no longer listen to RouteStore change and remove listener

@kaesonho
Copy link
Contributor Author

updated, now provide a function for users to overwrite attributes and create a NavLink component

@kaesonho kaesonho changed the title [Proposal] navlink performance improvement, move out navlink functions, remove h… [Proposal] navlink performance improvement, provide createNavLink, remove handleRoutes Jul 23, 2015
@kaesonho
Copy link
Contributor Author

updated, still listen to the RouteStore change.

@yahoocla
Copy link

CLA is valid!

return false;
},
componentWillReceiveProps: function (nextProps) {
this.receivedNewProps = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to prevent the re-render for route store change, (only render when isActive change), while we still need to re-render for props change, so set a flag receivedNewProps and clear it after rendered.

@mridgway
Copy link
Collaborator

lgtm

@kaesonho
Copy link
Contributor Author

thanks 🎆, squashed

@redonkulus
Copy link
Contributor

👍

},
propTypes: {
currentRoute: React.PropTypes.object,
currentNavigate: React.PropTypes.object,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who will populate currentRoute and currentNavigate props, after handleRoute is removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great

@kaesonho
Copy link
Contributor Author

do we want to put createNavLink in lib ? or addons ?

@mridgway
Copy link
Collaborator

Keep it in lib since it's used by core. We can export it from require('fluxible-router').createNavLinkComponent.

@kaesonho kaesonho changed the title [Proposal] navlink performance improvement, provide createNavLink, remove handleRoutes navlink performance improvement, provide createNavLink, remove handleRoutes Jul 27, 2015
@kaesonho
Copy link
Contributor Author

updated, change file name as createNavLinkComponent, also export it with index.js


| Param Name | Param Type | Description |
|-----------|-----------|-------------|
| options | Object | the object taken to overwrite the default attribute when we create NavLink |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to document what these options are. Maybe with | options.foo | Object | <description> |.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the description will be the same as React API, maybe give users a link http://facebook.github.io/react/docs/component-specs.html ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. That wasn't clear to me. Yeah it might be good to say it's the same as the parameter passed to React.createClass.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure updated, also update the parameter name, use overwriteSpec, which align with React, https://github.com/facebook/react/blob/master/src/isomorphic/classic/class/ReactClass.js#L804

@lingyan
Copy link
Contributor

lingyan commented Jul 27, 2015

👍

@mridgway
Copy link
Collaborator

@kaesonho
Copy link
Contributor Author

rebased, let me merge it

kaesonho added a commit that referenced this pull request Jul 28, 2015
navlink performance improvement, provide createNavLink, remove handleRoutes
@kaesonho kaesonho merged commit af15b8c into master Jul 28, 2015
@Vijar Vijar removed the in progress label Jul 28, 2015
@kaesonho kaesonho deleted the refactornavlink branch July 28, 2015 00:24
@roderickhsiao
Copy link
Contributor

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants