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

Knockout binding issue on Aurelia cached views #8

Closed
mirkolugano opened this issue Dec 15, 2016 · 4 comments
Closed

Knockout binding issue on Aurelia cached views #8

mirkolugano opened this issue Dec 15, 2016 · 4 comments
Labels

Comments

@mirkolugano
Copy link

mirkolugano commented Dec 15, 2016

Hi I am converting a web app from Durandal/Knockout to Aurelia CLI. I am successfully using the aurelia-knockout plugin, but I am having an issue when using view caching on Aurelia. I understand that view caching is still something which is "under construction" in Aurelia but I would like to know if this is a known issue or how if there is some workaround that I could use.
My issue is described on this Stack Overflow post:

I know I can bypass the issue with KnockoutBindable but I was wondering if there was a 'cleaner' way to solve it.

Thank you in advance.
If this is not the right place or way to submit such a request, please excuse me, and feel free to remove it.

@ckotzbauer
Copy link
Member

Hi @mirkolugano, I check your problem at the moment. I can reproduce it and try to find a fix for it.

@ckotzbauer
Copy link
Member

@mirkolugano
The results of my investigation:

  • Aurelia caches the whole "View" object (including the document-fragment which holds the html) if you switch to another view. If you go back, Aurelia uses the cached view and binds it against your new view-model. This works fine because all Aurelia bindings are processed again completly. But the templating engine doesn't know the Knockout syntax which dynamically generates html too. It treats it as "normal html" and doesn't revert the changes from previous runs.
  • This plugin calls ko.cleanNode(...) if the unbind callback is invoked from Aurelia. This reverts the changes Knockout made before (so exactly what you need). Unfortunately the callback is called too late. The old view is already detached and this cleaning takes no effect. The document-fragment is cached as is.
  • The reason why the bypass with my KnockoutBindable works is not my plugin. It works because you used the Aurelia syntax to bind your data to your view. You can remove this workaround completely in order to use raw aurelia syntax without any knockout syntax in it.

@mirkolugano
Copy link
Author

mirkolugano commented Dec 16, 2016

Yes, I noticed yesterday that also using normal aurelia computeds which simply return the corresponding knockout variables does the trick. Thanx for investigating, I guess I will switch to Aurelia syntax everywhere.

@ckotzbauer
Copy link
Member

closed

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

No branches or pull requests

2 participants