Skip to content

Feature: basic start and end callbacks#48

Merged
Stanko merged 2 commits intoStanko:masterfrom
idfunctor:feature-callback
Dec 17, 2018
Merged

Feature: basic start and end callbacks#48
Stanko merged 2 commits intoStanko:masterfrom
idfunctor:feature-callback

Conversation

@idfunctor
Copy link
Contributor

This PR adds two props, onPlxStart and onPlxEnd.

This might be helpful in certain cases and doesn't hurt the library by increasing any complexity. I've pretty much just added a decorator to already computed values to enable this feature. It behaves as it previously did if we have neither of the aforementioned new props specified to the component.

@Stanko Let me know what you think!

@Stanko
Copy link
Owner

Stanko commented Dec 16, 2018

Hey, thank you for the PR. I’m travelling atm, but I’ll take a look tomorrow.
Cheers!

source/Plx.js Outdated
if (!wasActive && isActive) {
this.props.onPlxStart();
}
if (wasActive && !isActive) {
Copy link
Owner

Choose a reason for hiding this comment

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

else if would skip unneeded checks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, silly error! I'll fix it now.

source/Plx.js Outdated
style: {},
tagName: 'div',
onPlxStart: emptyFunction,
onPlxEnd: emptyFunction,
Copy link
Owner

Choose a reason for hiding this comment

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

Why not null? IMHO this.props.onPlxStart !== null is a bit cleaner check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True.
I'd done this to keep one flag "callbacksEnabled" and then fire both if even one prop (ex. onlt onPlxStart and not onPlxEnd) is defined. I'm changing the code now to have two flags, plxStartEnabled and plxEndEnabled, so that we can fire only the applied prop.

@Stanko
Copy link
Owner

Stanko commented Dec 17, 2018

Hey @blnk-space,
Good work, only thing I don't like is using classes for determining if the effect is active, but let's keep it for now. I added some nitpicking comments, please correct them and we can merge it.

I'm wondering if we can improve callback system even further. Current implementation allows only for "global" callbacks for a single Plx instance. Maybe it would be better to introduce them per section (for each item in parallaxData). This way it would a lot of flexibility. But it makes it a harder problem as well, so that should be tracked separately.

Related issue: #26

Cheers!

@idfunctor
Copy link
Contributor Author

Yeah, even I don't love the "hacky" method, I thought of doing it until this way I could spend more time and implement a direct solution. Next step for me would be to implement a function like getClasses that does this for us without string comparison. And per-section callBacks are also something I've been wanting to implement, I'll hopefully do this all in the next couple weeks!

@Stanko Stanko merged commit 4cec67f into Stanko:master Dec 17, 2018
@Stanko
Copy link
Owner

Stanko commented Dec 18, 2018

Released in 1.3.11 🎉

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.

2 participants