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

Added initialization logic when changing container attributes #162

Merged

Conversation

devxom
Copy link
Contributor

@devxom devxom commented Dec 25, 2019

Added logic to manual update the Likely instance when changing the data attributes of the container on which Likely is initialized

Changes:

  • Added the updateOptionFromDataSet method to update the Likely instance configuration after from the data attributes after initialization
  • Added an html page for the ability to manually and automatically test data updates when changing data attributes
  • Added automatic tests to verify that after changing the data-url attribute on the widget container when opening the model window for sharing, the updated url from the data-url attribute on the container is used
  • Added an example to README.md to use the logic for updating the configuration from the date of attributes after initializing the Likely instance

Fixed: #151

Previous version of description Added logic to initialize the library when changing the data attributes of the container on which Likely is initialized

Changes:

  • When initializing a shared sharing widget, the creation of MutationObserver was added to change the attributes of the widget container
  • Added an html page for the ability to manually and automatically test data updates when changing data attributes
  • Added automatic tests to verify that after changing the data-url attribute on the widget container when opening the model window for sharing, the updated url from the data-url attribute on the container is used

Important: to determine that the data-url attribute on the container has changed, it uses the MutationObserver API which works on a slightly narrower number of browsers. In browsers without support for this API, just this logic will not work.

img

Fixed: #151

test/index.js Outdated
{ name: 'Telegram', likelyName: 'telegram', urlRegex: `${encodeURIComponent(targetUrl)}` },
{ name: 'Twitter', likelyName: 'twitter', urlRegex: `${encodeURIComponent(targetUrl)}` },
{ name: 'VK', likelyName: 'vkontakte', urlRegex: `${encodeURIComponent(targetUrl)}` },
// Pinterest and Linkedin do not contain sharing URLs if not authorized and the test will fail
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just out of curiosity, wouldn't this happen for these buttons in production?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a problem only for this particular auto test. We cannot determine that the data has been verified. It's not a problem.

@vitkarpov
Copy link
Collaborator

In browsers without support for this API, just this logic will not work.

Could users initialize the widget once again manually?

@NikolayRys NikolayRys self-assigned this Dec 26, 2019
@NikolayRys
Copy link
Owner

NikolayRys commented Dec 26, 2019

Hi, @devxom, thank you for the PR, I appreciate your effort.

However, after some consideration, I've got a feeling that the proposed solution might be unnecessarily complicated. Namely, I think it's sufficient to provide the client with something like likely.reinitialize or likely.updateOptions to use when the attributes are changed.

If the user needs to detect it automatically, they can add a Mutation Observer approach on their own. In the scope of your pull request, I suggest to keep the content of "updateOptionFromDataSet" and remove the observer.

What do you think?

@devxom
Copy link
Contributor Author

devxom commented Dec 29, 2019

@NikolayRys, i agree. Adding DOM attribute tracking logic is unnecessarily complicated in the library itself.

Within a few days I will update the pull request. Where from the edits will be:

  • logic updateOptionFromDataSet
  • tests
  • an example in README.md that will show how, for example, you can use MutationsObserver from outside the library

@NikolayRys
Copy link
Owner

Sounds awesome, thank you.

@NikolayRys NikolayRys mentioned this pull request Jan 1, 2020
14 tasks
@devxom
Copy link
Contributor Author

devxom commented Jan 6, 2020

Updated patch and description for pull request. Review please.

Copy link
Collaborator

@vitkarpov vitkarpov left a comment

Choose a reason for hiding this comment

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

@devxom @NikolayRys guys, what do you think about to not introduce a new method but use existing init? It's like there's only one way to (re)initialize the widget.

readme.md Outdated

3. Some logic for update data attributes

2. Logic for update configuration on instance *Likely*
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's weird but the list is rendered as 1, 3, 4 (check out the preview on GitHub) 🤔
I don't get the second item, "some logic to update attributes", could you elaborate, pls?

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 will rewrite the example so that it displays normally.

Copy link
Owner

@NikolayRys NikolayRys Feb 5, 2020

Choose a reason for hiding this comment

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

Please complete the description.

2. Logic for update configuration on instance *Likely*

```javascript
// find in dom likely
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably it's better to call it "the DOM"? (like developers.mozilla does)

Copy link
Owner

Choose a reason for hiding this comment

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

Please use "Find Likely in the DOM"

source/widget.js Outdated
@@ -37,6 +37,13 @@ class Likely {
}
}

updateOptionFromDataSet() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't it be plural, I mean updateOptionsFromDataSet?

Copy link
Owner

@NikolayRys NikolayRys Feb 5, 2020

Choose a reason for hiding this comment

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

Please use plural.

@devxom
Copy link
Contributor Author

devxom commented Jan 7, 2020

@devxom @NikolayRys guys, what do you think about to not introduce a new method but use existing init? It's like there's only one way to (re)initialize the widget.

It sounds logical, I tested it works well. I updated the edits leaving only an example and tests.

@vitkarpov
Copy link
Collaborator

@devxom sorry, I'm not sure I get it right. Are you going to change the code in a way it uses init only or leave it as-is? (the latter is fine, just asking)

@devxom
Copy link
Contributor Author

devxom commented Jan 9, 2020

@vitkarpov I liked the idea of such a simplification, I will update the edits in the near future using init

@vitkarpov
Copy link
Collaborator

vitkarpov commented Jan 10, 2020

Gotcha, thanks! 👍

Copy link
Owner

@NikolayRys NikolayRys left a comment

Choose a reason for hiding this comment

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

@devxom Sorry for the delay, I was caught up with other projects.
It's pretty good now, please do the quested fixes - they are all pretty much cosmetical, while the feature itself is mergeable.

2. Logic for update configuration on instance *Likely*

```javascript
// find in dom likely
Copy link
Owner

Choose a reason for hiding this comment

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

Please use "Find Likely in the DOM"

readme.md Outdated

3. Some logic for update data attributes

2. Logic for update configuration on instance *Likely*
Copy link
Owner

@NikolayRys NikolayRys Feb 5, 2020

Choose a reason for hiding this comment

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

Please complete the description.

// find in dom likely
const likelyWidget = document.querySelector(".likely");

// find instance of likely
Copy link
Owner

Choose a reason for hiding this comment

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

"Get the instance of Likely"

// find instance of likely
const likelyInstance = likelyWidget.likely;

// Call inner method for update options from data attributes
Copy link
Owner

Choose a reason for hiding this comment

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

"...to update options from the data attributes"

source/widget.js Outdated
@@ -37,6 +37,13 @@ class Likely {
}
}

updateOptionFromDataSet() {
Copy link
Owner

@NikolayRys NikolayRys Feb 5, 2020

Choose a reason for hiding this comment

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

Please use plural.

@@ -5,6 +5,7 @@ const LikelyPage = {
NO_AUTOINIT: 'no-autoinit.html',
NO_AUTOINIT_MULTIPLE: 'no-autoinit-multiple.html',
ISSUE_67: 'issues/67.html',
ISSUE_151: 'issues/151.html',
Copy link
Owner

@NikolayRys NikolayRys Feb 11, 2020

Choose a reason for hiding this comment

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

Those names for the tests and pages aren't great. Let's please use some more descriptive as UPDATE_OPTIONS: 'update-options.html'.
I will eventually refactor that 67.html too.

@NikolayRys
Copy link
Owner

NikolayRys commented Mar 25, 2020

@devxom @vitkarpov Guys, I need your help.
I see that we have a test that covers changing attributes with re-initialization after that: https://github.com/NikolayRys/Likely/blob/master/test/index.js#L158

Here's where re-initialization currently happen:
https://github.com/NikolayRys/Likely/blob/master/source/index.js#L32

Could you help me figure out, does this pull request add any capabilities beyond that?

@vitkarpov
Copy link
Collaborator

@NikolayRys What do you mean? What capabilities exactly?

@NikolayRys
Copy link
Owner

I'm under impression that we already have a completely functional re-initialization logic in place, could you please confirm/deny this?
If it is indeed the case, then do we still need the separate method from this PR that updates attributes from the HTML tag?

@vitkarpov
Copy link
Collaborator

Yeah, I see what you mean. It seems that this PR doesn't do anything new 🤔I think we need to reproduce what #151 reports, probably it's already fine.

@devxom
Copy link
Contributor Author

devxom commented Mar 25, 2020

Really necessary logic to update configuration from date attributes. In this form, Pull Request does not make sense.

@NikolayRys @vitkarpov How do you look at simply describing the approach to do when using dynamic date attributes and adding a test that checks and shows how this happens?

@vitkarpov
Copy link
Collaborator

vitkarpov commented Mar 25, 2020 via email

@NikolayRys
Copy link
Owner

NikolayRys commented Mar 25, 2020

We definitely lacked this information about that in the readme, so at least this part of work in this PR can be kept.

@devxom But about the test - doesn't this test: https://github.com/NikolayRys/Likely/blob/master/test/index.js#L158 already cover it?

@devxom
Copy link
Contributor Author

devxom commented Mar 27, 2020

@NikolayRys

@devxom But about the test - doesn't this test: https://github.com/NikolayRys/Likely/blob/master/test/index.js#L158 already cover it?

You are right, indeed this test covers this case

This weekend I will update the Pull Request. I will remove unnecessary edits and update changes with edits in README.md with an explanation of how to reinitialize Likely when using dynamic date attributes

@NikolayRys NikolayRys mentioned this pull request Apr 29, 2020
13 tasks
@NikolayRys
Copy link
Owner

@devxom No update yet?

@devxom devxom force-pushed the feature/add-observable-data-options branch from 2e41c38 to 1d634be Compare April 30, 2020 23:46
Signed-off-by: Ilya Reshetnikov <ilya.reshetnikov@devxom.tech>
@devxom devxom force-pushed the feature/add-observable-data-options branch from 1d634be to f3e7678 Compare May 1, 2020 00:22
@devxom
Copy link
Contributor Author

devxom commented May 1, 2020

@NikolayRys Reassembled edits based on comments. Please take another look at the code.

@devxom devxom requested a review from NikolayRys May 1, 2020 00:25
@devxom devxom requested a review from vitkarpov May 3, 2020 01:32
Copy link
Collaborator

@vitkarpov vitkarpov left a comment

Choose a reason for hiding this comment

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

There are some notes about typos & grammar in README. Have you looked at them? Probably we decided to disregard, I don't remember.

@NikolayRys
Copy link
Owner

Hi, @devxom, thanks for taking care of this.

@NikolayRys NikolayRys merged commit 549f56d into NikolayRys:master May 5, 2020
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.

Error dynamic data-url params
3 participants