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

Reprocess time elements on mutation #152

Closed

Conversation

northeastprince
Copy link

Fixes #151.

Copy link
Contributor

@josefarias josefarias 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 this @northeastprince

I don't think creating mutation observers within processElements would work, since that method can be called repeatedly from outside this class, and also in a recurring interval:

startTimer: ->
if interval = config.timerInterval
@timer ?= setInterval(@processElements, interval)

That would result in tons of observers being created, possibly overwhelming the runtime.

Observing each element was my first instinct, too, when I first learned about this bug. But I'm not super keen on that approach because it has no upper bound on the amount of observers we're creating (even if only one per element). Plus, every observer will have the same purpose. Feels like we should be able to handle this further upstream.

I'll have to look at the morphing implementation (my colleagues @jorgemanrubia @afcapel are more familiar with that than I am) — but I wonder if we could dispatch an event after morphing (if we're not already) and force a reprocess when that happens. We could add a one-liner snippet to the readme to take care of this scenario, for users who happen to use both libraries.

Or, we could modify the single existing page observer to catch characterData mutations, in addition to childList ones.

processMutations: (mutations) =>
elements = []
for mutation in mutations
switch mutation.type
when "childList"
for node in mutation.addedNodes
elements.push(@findSignificantElements(node)...)
@notify(elements)

I feel like observing characterData might be a bit much (and I'm not even sure it would work). So I'm partial to acting on a morph event. Will revisit this next week if time allows.

@northeastprince
Copy link
Author

Agreed, we should just add something to the README. I opened #155 to add compatibility instructions.

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.

Existing elements change to their raw form when rerendered
2 participants