-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
[Feature request] Make caching of compose configurable #381
Comments
@Sayan751 absolutely, that would be a nice addition. cc @EisenbergEffect @fkleuver for reflection on vNext |
I don't agree it is appropriate to be called caching. If it ends up being called
I would expect that |
I agree with your point. My requirement matches more with the What is your view on that? |
Then what about reusing |
@StrahilKazlachev The new enum can be created with those 2 values. |
This commit introduces @bindable activation-strategy for compose. The default strategy is 'invoke-lifecycle', which is also the current strategy. The strategy 'replace' forces re-creation of bound view and view-model on model change. This is helpful, where the re-instantiation of view and view-model is needed on model change. For example, when validation is used in a custom element; on model change, old validation rules still gets triggered if the view-model is not reinstantiated. Fixes aurelia#381
I'm not so sure if using the lifecycle strategy enum for compose is a good idea. It really shouldn't even have been called |
@fkleuver The only lifecycle hook, in bound VM, called from compose is "activate". Considering that the activation-strategy is relatable in this context. As the |
@fkleuver actually the async hooks canActivate/activate/... are already used in different combinations in different places - router, composition engine, <compose>, dialog, in vCurent ¯_(ツ)_/¯ |
I tested the change on my project (so it's officially "works-on-machine" certified 😛). Once the terminologies are settled, I can update documentation and create 2 PRs in both the repositories. |
Another idea is to call this something like |
@StrahilKazlachev And it's always been a massive source of confusion when I was still learning Aurelia. I think |
This commit introduces @bindable activation-strategy for compose. The default strategy is 'invoke-lifecycle', which is also the current strategy. The strategy 'replace' forces re-creation of bound view and view-model on model change. This is helpful, where the re-instantiation of view and view-model is needed on model change. For example, when validation is used in a custom element; on model change, old validation rules still gets triggered if the view-model is not reinstantiated. Fixes aurelia#381
This commit adds the support to determine the activation strategy of the bound view-model by invoking the determineActivationStrategy hook in the view-model, when implemented. The activation strategy from the view-model always overrides the one in the instance of `compose`. Addendum for aurelia#381
- Refactored activation strategy implmentation - Added negative tests - Minor changes in docs Issue aurelia#381
I'm submitting a feature request
1.11.0
Please tell us about your environment:
Operating System:
Windows 10
Node Version:
10.15.0
6.4.1
webpack 4.35.0
Browser:
all
Language:
TypeScript 3.5.2
Current behavior:
The view-model and view used in
compose
is currently cached, that is whenever the model changes, the view-model and view is never recreated and just reactivated with the new model. This makes sense for most of the cases. However, this causes problem for some cases. For example, when validation is used in a custom element. When the model is changed, old validation rules still gets triggered. Some workarounds in this case can be to use an explicitsignal
behavior oncompose
to force recreation of VM, or to reset the validation rules somehow (I tried the later, but without success). For more details on the use case, please refer this.Expected/desired behavior:
What is the expected behavior?
Naive expectation is that the VM and View will be recreated, considering all custom elements are transient. However, in this case I would suggest for a
@bindable cache:boolean
flag which can be used inprocessChanges
to force the recreation. This is similar to thecache
property ofif.bind
.What is the motivation / use case for changing the behavior?
Any workaround will take considerable time on my part due to non-trivial refactoring, whereas the solution with the configurable
cache
looks very much easily doable.If you are interested for a PR, I would like to give it a try.
The text was updated successfully, but these errors were encountered: