Skip to content
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

Feature/bounds #109

Merged
merged 2 commits into from
Jul 13, 2016
Merged

Feature/bounds #109

merged 2 commits into from
Jul 13, 2016

Conversation

thomassuckow
Copy link
Contributor

@thomassuckow thomassuckow commented Jul 13, 2016

Resolve adding bounds values as described in #107

Also resolves an issue with findDOMNode "Uncaught Invariant Violation: getNodeFromInstance"

Thomas Suckow added 2 commits July 6, 2016 18:43
* Use ref instead of findDOMNode
* Better compatability with React 15.2.x
let contextHeight;
let contextScrollTop;
if (this.scrollableAncestor === window) {
contextHeight = window.innerHeight;
contextScrollTop = 0;
} else {
contextHeight = this.scrollableAncestor.offsetHeight;
contextScrollTop = ReactDOM
.findDOMNode(this.scrollableAncestor)
contextScrollTop = this.scrollableAncestor
Copy link
Collaborator

Choose a reason for hiding this comment

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

Worth noting that this would be a breaking change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand how this changes anything.
this.scrollableAncestor is a dom element so
ReactDOM.findDOMNode(this.scrollableAncestor) === this.scrollableAncestor

Copy link
Collaborator

@jamesplease jamesplease Jul 13, 2016

Choose a reason for hiding this comment

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

Ah, you're right. I was thinking that passing a component instance in as a scrollableAncestor would work (by leveraging findDOMNode), but I took another look at the source and saw that it would error earlier on in the code.

Ignore me! 🙈

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch!

@jamesplease
Copy link
Collaborator

jamesplease commented Jul 13, 2016

Also resolves an issue with findDOMNode "Uncaught Invariant Violation: getNodeFromInstance"

What's this issue? I do think it's a good idea to move away from findDOMNode, as React might deprecate it.

As an aside, I find it's usually easier to land PRs if they're separate things tho (since a single problem can hold up merging everything else 😄 )

@thomassuckow
Copy link
Contributor Author

https://github.com/apollostack/meteor-starter-kit/issues/16 describes the issue I was seeing while working on these changes. For some reason building react-waypoint on my machine caused ReactDOM.findDOMNode to throw an invariant exception.

@thomassuckow
Copy link
Contributor Author

I would normally separate them, but the changes overlap so they would have to be submitted one at a time. I did pull the third commit (No forced layout on mount/update) though because it isn't strictly necessary and breaks the tests.

});
this.props.onLeave.call(this, {
currentPosition,
previousPosition: POSITIONS.inside,
event,
waypointTop: bounds.waypointTop,
viewportTop: bounds.viewportTop,
viewportBottom: bounds.viewportBottom,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you could use an object spread here (and in two places above) to avoid having to repeat the bounds properties:

this.props.onLeave.call(this, {
  currentPosition,
  previousPosition: POSITIONS.inside,
  event,
  ...bounds,
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could, but I would need to add a few babel plugins. If you would prefer that syntax I can do so.
https://babeljs.io/docs/plugins/transform-object-rest-spread/

@trotzig
Copy link
Collaborator

trotzig commented Jul 13, 2016

Thanks @thomassuckow, this all looks good to me. Good call on pulling the third commit (makes this PR easier to merge), although I'd love to see a separate PR for that!

I'll let you decide if you want to take action on my comment to DRY up src/waypoint.jsx a little before merging.

@thomassuckow
Copy link
Contributor Author

thomassuckow commented Jul 13, 2016

DRY:

  • Object rest spread

Unless I am mistaken the above is the only DRYing change, if I am wrong point it out. It is also dependant on whether this project wants to add more babel plugins or if there is some reason not to.

@trotzig
Copy link
Collaborator

trotzig commented Jul 13, 2016

Ah, I thought we had that wired up already. Let's merge this without it. We can change that later on.

@trotzig trotzig merged commit af2fe72 into civiccc:master Jul 13, 2016
@lencioni
Copy link
Collaborator

rest/spread is only a stage 2 proposal right now. I think we should wait until it hits stage 3 to bring it in.

https://github.com/sebmarkbage/ecmascript-rest-spread

@trotzig
Copy link
Collaborator

trotzig commented Jul 13, 2016

I included this change in v3.1.0 (just released). Thanks for the contribution @thomassuckow!

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

Successfully merging this pull request may close these issues.

4 participants