Skip to content

fix listeners re-adding with share buttons update #28

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

Closed
wants to merge 2 commits into from

Conversation

tnga
Copy link
Contributor

@tnga tnga commented Aug 29, 2021

Previous added listeners to share buttons are re-added twice or multiple time when execute ShareButtons.update().
In browsers, if data-url or data-title or data-desc have been changed before calling ShareButtons.update(), the changes will not be considered because the previous added listeners with previous data value on share buttons will be executed on click event before the new added listeners after ShareButtons.update().
This pull request aims to fix that.

Copy link
Owner

@wcoder wcoder left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! 🚀

Could you please revert changes for dist, package-lock, package ?
I will recompile these before NPM release later.

var iehandler = function () {
handler.call(el);
};
var cachedRef = el.getAttribute('data-sharebtn-ref')
Copy link
Owner

Choose a reason for hiding this comment

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

Great idea to store refs, but I think it will be more clear when this logic will be split as init (add listeners) and deinit/dispose (remove listeners, clear states), after that update() can compose these methods

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, but actually update use this.i() to reinit .share-btn expected data and actions. Splitting the process with a deinit function address the challenge to loop links a twice to add and remove listeners. However it can be more convenient to process removeEventListener and then addEventListener in prepareLink step. This like you suggest, to be more clear on that logic.

@wcoder wcoder added the bugfix label Aug 29, 2021
@wcoder wcoder added this to the vNext milestone Aug 29, 2021
@tnga
Copy link
Contributor Author

tnga commented Aug 31, 2021

Okay

Thanks for the PR! rocket

Could you please revert changes for dist, package-lock, package ?
I will recompile these before NPM release later.

Okay will do it.

@tnga
Copy link
Contributor Author

tnga commented Sep 5, 2021

Close this PR in favor of this PR #30 addressing requested changes

@wcoder wcoder removed this from the vNext milestone Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants