-
Notifications
You must be signed in to change notification settings - Fork 61
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
Added initialization logic when changing container attributes #162
Conversation
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Could users initialize the widget once again manually? |
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 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? |
@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:
|
Sounds awesome, thank you. |
Updated patch and description for pull request. Review please. |
There was a problem hiding this 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* |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use plural.
It sounds logical, I tested it works well. I updated the edits leaving only an example and tests. |
@devxom sorry, I'm not sure I get it right. Are you going to change the code in a way it uses |
@vitkarpov I liked the idea of such a simplification, I will update the edits in the near future using |
Gotcha, thanks! 👍 |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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* |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use plural.
test/utils/getLikelyPage.js
Outdated
@@ -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', |
There was a problem hiding this comment.
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.
@devxom @vitkarpov Guys, I need your help. Here's where re-initialization currently happen: Could you help me figure out, does this pull request add any capabilities beyond that? |
@NikolayRys What do you mean? What capabilities exactly? |
I'm under impression that we already have a completely functional re-initialization logic in place, could you please confirm/deny this? |
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. |
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? |
Sounds good to me! 👍
--
Cheers,
Viktor
|
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? |
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 |
@devxom No update yet? |
2e41c38
to
1d634be
Compare
Signed-off-by: Ilya Reshetnikov <ilya.reshetnikov@devxom.tech>
1d634be
to
f3e7678
Compare
@NikolayRys Reassembled edits based on comments. Please take another look at the code. |
There was a problem hiding this 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.
Hi, @devxom, thanks for taking care of this. |
Added logic to manual update the Likely instance when changing the data attributes of the container on which Likely is initialized
Changes:
updateOptionFromDataSet
method to update the Likely instance configuration after from the data attributes after initializationFixed: #151
Previous version of description
Added logic to initialize the library when changing the data attributes of the container on which Likely is initializedChanges:
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.
Fixed: #151