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

Lifecycle method after a Rerender #204

Open
jsonmurphy opened this issue May 22, 2018 · 3 comments
Open

Lifecycle method after a Rerender #204

jsonmurphy opened this issue May 22, 2018 · 3 comments

Comments

@jsonmurphy
Copy link

Apologies if this has been asked before, I've tried to look through the issue log but I'm unsure what vecty's terminology would be for something like this.

I have a component that loads some data asynchronously as soon as it is mounted. Once the data is loaded, I call vecty.Rerender() and the data shows up as expected however I also need to call an external JQuery library that will manipulate the dom that has the data. Simply calling the function after vecty.Rerender does not work. It always gets executed before the rerender.

So my question is how would vecty handle a situation like this? I would imagine that there would be a need for something analogous to React's componentDidUpdate that is only triggered after a rerender.

@pdf
Copy link
Contributor

pdf commented May 22, 2018

We don't have a lifecycle hook for this currently, and native JS interop in general is something we've only lightly tackled.

Even if we had such a hook, you might find that you run into problems, because signification modifications to the DOM by an outside library will result in vecty's view of the DOM being out of sync with reality, and this is likely to produce unpredictable behaviour. Do you mind telling me which JQuery library you're trying to use, if it's public?

@jsonmurphy
Copy link
Author

The library I'm trying to integrate is JQuery DataTables. I think my alternative would be to supply the data on initial render and then initialize the table on mount which is probably a better idea for this use case i suppose.

Are there plans to support solid interop with native JS for 1.0.0 or beyond? if so, are there any tickets/threads where it is being discussed that you could point me to?

@pdf
Copy link
Contributor

pdf commented May 22, 2018

Yeah, for a library like that, I'd suggest you simply create a container element, and let the library deal with rendering anything inside that, using the Mount hook to initialise it, and updating data via the lib's API. I can't tell you how DataTables will act when you remove the underlying element upon navigating to a new view, whether it leaves a clean state in the browser - if it has a destructor, that should be called via Unmount.

I'm not sure there's any way we can meaningfully integrate with JS libraries that modify the DOM significantly, and React doesn't support this either - it's orthogonal to the design of these tools. Currently, I'm not entirely sure what the pain-points are for interop, or how they might be mitigated.

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

No branches or pull requests

2 participants