angular2-hot-loader icon indicating copy to clipboard operation
angular2-hot-loader copied to clipboard

Preserving component's state

Open mgechev opened this issue 10 years ago • 3 comments

mgechev avatar Dec 22 '15 15:12 mgechev

I think that inputs, outputs and methods should not be transferred from the old component to the new one. So this leaves only the internal state of the component and I am not sure if we should persist this. Because it could lead to a state in the component that cannot be recreated by using either the old or the new implementation. A (silly) example: A component has a counter that starts with 0 and is incremented by 2 by a click event. After a 2 clicks the component gets reloaded and the counter is now incremented by 3. After one more click the component is now in a state (7) that is not reachable from the old or the new implementation. This could be very difficult to debug and can only be fixed by doing a page reload.

Also when the refactoring is done the overall state of the application stays the same and only the subtrees of components that depend on the changed component will loose their state.

frederikschubert avatar Dec 23 '15 17:12 frederikschubert

We can take a look at preserving the state from one more perspective - we need to keep the element injectors which are instantiated for the individual directives.

AFAIK they are stored in the AppView(s). This implies that the AppView needs to be restored once the application has been loaded.

mgechev avatar Dec 23 '15 23:12 mgechev

@frederikschubert last night I spend a few hours preserving the instantiated dependencies for static injectors. I have some progress there, next goal is to refactor, provide dynamic injector support + component state preservation.

mgechev avatar Mar 16 '16 10:03 mgechev