-
Notifications
You must be signed in to change notification settings - Fork 131
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
onAfterChanges option (or something similar) #223
Comments
I've had a need today for Adding this to morphdom would be very useful. In the meantime, are you able to share your working but hacky code? |
Yes. Of course. What i do is to throttle all calls of Example: import rafThrottle from 'raf-throttle';
const onAfterChanges = rafThrottle(() => console.log('onAfterChanges'));
morphdom(
document.getElementById('foo'),
'<div>bar</div>',
{
onElUpdated: () => onAfterChanges(),
onNodeAdded: node => { onAfterChanges(); return node; },
onNodeDiscarded: node => { onAfterChanges(); return node; }
}
); What happens is, that the throttled function If you have further questions, feel free to ask. 😄 |
|
I'd love to see this implemented, so bump. One thing that I'd strongly suggest is that such an "after" callback fire even if no changes are performed. We're currently dealing with the opposite situation eg. we need to run some cleanup after |
Building on @StefanJelner's solution - while acknowledging that I'm hoping for an outcome where a callback fires after processing even if there are no changes - is it fair and reasonable to say that a final call to |
If |
I share your desire; it would be nice. In fact, I'm implementing a comparison concept in a library that uses morphdom right now. Thing is, I would rather have morphdom be super fast than provide a changeset. I genuinely worry that making those changes available would require a lot more code and a lot more CPU cycles to run that code. (I'd be thrilled to be wrong.) In our library, given that this functionality hasn't been merged and released yet, we're making use of the techniques discussed earlier in this thread - paired with an initial check where we compare the source fragment against the innerHTML of the target element. We figure that even if this is a heavy operation, it's still less heavy than calling morphdom if we know the source and target are already equal. If this functionality does get merged down the line, we'll take that as an opportunity to simplify our local implementation by adopting the morphdom onAfterChanges event. |
First of all thanks for this great library. I am using it for small reactive widgets in websites and it works like a charm.
In some scenarios i need to know, when morphing is completely finished. My approach now is to add
onElUpdated
,onNodeAdded
andonNodeDiscarded
and inside of the callbacks fire another callback which is throttled by request animation frame. This works for me, but is a little bit hacky in my opinion.Would it be possible to provide an option - like
onAfterChanges
- which becomes invoked after everything has been done?The text was updated successfully, but these errors were encountered: