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

Destroy and reinitialize only changed components #8

Open
frederikschubert opened this issue Dec 20, 2015 · 4 comments
Open

Destroy and reinitialize only changed components #8

frederikschubert opened this issue Dec 20, 2015 · 4 comments

Comments

@frederikschubert
Copy link

Right now the hot loading works by (re)loading the app's root component using the DynamicComponentLoader, i.e. reinitializing the whole application every time a component/template/style is updated.
This could become a problem as the application grows larger. I know that by using patterns like flux or redux the view of the application can be reinitialized just by persisting the state before the application gets reinitialized. But for people who do not use such patterns the hot-loader could be more helpful if only those components (and thus their children) would be reloaded that changed.
I haven't fully understood the inner workings of how Angular instantiates components and their respective views but I think one API one could use for this could be the AppViewManager. If this was possible then there would also be the possibility to transfer some of the state of the old component to the updated component. I think that this could provide an even smoother developer experience.

@mgechev
Copy link
Owner

mgechev commented Dec 21, 2015

Yes, this is in my roadmap. There are a couple of things to be considered here such as managing the reinstantiated view and content children.

I will rename the issue and add it as a feature request.

@mgechev mgechev changed the title Question: Is it possible to only destroy and reinitialize specific components? Destroy and reinitialize only changed components Dec 21, 2015
@frederikschubert
Copy link
Author

I did some work on this and my current state can be seen here. I didn't find a way to destroy a component yet.
I got it working now. Though there are a few things that are not quite right.
1. The hot-reloading now only works if the typescript file was changed. This should be easy to fix.
2. It has to be defined how and if state should be transferred from the old component to the new one.
3. I haven't tested the approach in a more complex example. There could be are problems with the createRootHostView function in case there are multiple instances of a component.
Only the first component in the DOM will be updated.

@mgechev
Copy link
Owner

mgechev commented Dec 22, 2015

Since keeping the component's state is a core problem lets open a separate issue for discussion.

@mgechev mgechev mentioned this issue Dec 22, 2015
2 tasks
@frederikschubert
Copy link
Author

I have mostly implemented the component-scoped reload here but I have a problem with the change detection. The CD only runs for the changed component but not for its parent, so the component's inputs are not refreshed.
I don't know if that is the right way as the addition and removal of an attribute is kind of a hack to misuse the createRootHostView function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants