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

How to deal with removed attributes #58

Closed
KonnorRogers opened this issue Jul 1, 2021 · 7 comments
Closed

How to deal with removed attributes #58

KonnorRogers opened this issue Jul 1, 2021 · 7 comments
Labels
Type: Question Further information is requested

Comments

@KonnorRogers
Copy link
Owner

KonnorRogers commented Jul 1, 2021

The mutationObserver now properly checks for changed attributes, but what happens if attributes are removed? Should they be rechecked for their validity and have their event listeners removed? If so, how do we make this happen? Do we create a Set of all watched nodes and run through them and make sure theyre correct? this is an...interesting...problem to say the least.

Perhaps another filter could be added to the src/utils/dom.ts to check the validity of the node[s] whos attributes were removed?

@KonnorRogers KonnorRogers added the Type: Question Further information is requested label Jul 1, 2021
@existentialmutt
Copy link
Contributor

existentialmutt commented Jul 7, 2021

lol, I noticed this behavior when working on #66 Went to log the issue and I wound up here.

Would it be possible to add code to the various observerCallback functions that removes the behaviors if the node doesn't match the designated attributes?

e.g. in method.ts:

  observerCallback (nodeList: Node[]): void {
    nodeList.forEach((node) => {
      if (match(node, window.mrujs.querySelectors.linkClickSelector)) {
        node.addEventListener('click', this.handle)
      } else { // <---------------- THIS IS THE NEW PART
       node.removeEventListener('click', this.handle)
     }

    // ...

  }

@KonnorRogers
Copy link
Owner Author

This may not be the worst way to handle it....I know me and @leastbad have been mulling over "in what scenario would someone ever do this?"

@leastbad
Copy link
Collaborator

leastbad commented Jul 7, 2021

Just to throw an idea on the pile:

You could introduce a method that people could call which would fully de-mrujs an element. This would allow you to sleep well at night while Officially Not Worrying about people randomly disabling parts of an mrujs-blessed element. Programmatically removing the data-remote attribute is just such a weird way to solve a problem.

@KonnorRogers
Copy link
Owner Author

Hmmm....this seems the most sane. Allow you to remove certain pieces of functionality via JS...I like it!

@existentialmutt
Copy link
Contributor

I agree this is a weird case to design for- I've certainly never done it in all my years of working with OG UJS. A de-mrujs method sounds good to me.

@KonnorRogers
Copy link
Owner Author

im just gonna leave it alone until someone can come up with a compelling use case. Ive never had this come up before. Marking as closed unless someone can provide a real life example.

@leastbad
Copy link
Collaborator

leastbad commented Jul 8, 2021

giphy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants