-
Notifications
You must be signed in to change notification settings - Fork 130
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
template does not react to array changes #420
Comments
Yes, that is by design. This is because usually you don't want the whole tag to refresh whenever one of the arrays changes - especially with So the design is largely driven by perf considerations. On the other hand, depends paths, and observe paths do trigger changes if arrays change. So in your sample if you write
then But that said, this is not very intuitive, and as a fix for your scenario might be considered a bit hacky... So once again your feedback has led me to some interesting considerations, and here: you will find an update which includes a new feature. On any tag, you can set In your case you can write
Or you could create a custom tag
with
Let me know if it works for you, and if you find any issues. |
Would it be possible to have onArrayChange set to true by default for colon/print tags (:) such as |
Yes, I agree that makes sense... I had some concerns about backward compat since previously be default tags didn't observe array changes. Also we need some level of consistency between different tags. But on reflection I decided on the following approach: By default any tag (or data-link binding) will 'observe' array changes as well as property changes. However you can set Any tag which has onAfterChange set to a function (at the tag markup level or the tag declaration level) is assumed to handle its own onAfterChange behavior, so the built-in default of updating the tag whenever there is an array change will be suppressed for that tag. So by default Here is the code: jsviews_1.0.3_candidateF.zip |
Initial testing is positive. I'll keep monitoring to see if anything shows up. |
Feature improvements: Parens are now supported within $.observe() paths - e.g. "person.address().street()" - https://www.jsviews.com/#jsvmodel@chain - https://www.jsviews.com/#jsvviewmodelsapi@ismanagersample - https://www.jsviews.com/#computed@observe-computed - https://www.jsviews.com/#computed@depend-computed Improved features for managing how tags respond to onArrayChange events - https://www.jsviews.com/#tagoptions@onarraychange New support for referencing the parent object in hierarchical View Model scenarios (parentRef): - https://www.jsviews.com/#jsrmodel@parentref - https://www.jsviews.com/#viewmodelsapi@accessparent - https://www.jsviews.com/#jsvviewmodelsapi@ismanagersample New support for asynchronous or batched observable change events (asyncObserve): - https://www.jsviews.com/#delay New features available for scenarios using sorting and filtering (mapProps and mapDepends): - https://www.jsviews.com/#tagoptions@mapprops Bug fixes: - BorisMoore/jsviews#415 (Markup within element tag - incorrect whitespace) - BorisMoore/jsviews#417 (Side-effect when calling Tag.updateValue during setProperty call) - BorisMoore/jsviews#419 (Regression: checkbox widget not working since v1.0.0) - BorisMoore/jsviews#420 (Template tag responses to array changes) - Several other minor bug fixes Additional and improved documentation topics and samples... Updated tree view samples: - https://www.jsviews.com/#samples/tag-controls/tree Updated Typescript definitions (soon to be deployed DefinitelyTyped): - https://www.jsviews.com/#typescript Many additional unit tests...
Feature improvements: Parens are now supported within $.observe() paths - e.g. "person.address().street()" - https://www.jsviews.com/#jsvmodel@chain - https://www.jsviews.com/#jsvviewmodelsapi@ismanagersample - https://www.jsviews.com/#computed@observe-computed - https://www.jsviews.com/#computed@depend-computed Improved features for managing how tags respond to onArrayChange events - https://www.jsviews.com/#tagoptions@onarraychange New support for referencing the parent object in hierarchical View Model scenarios (parentRef): - https://www.jsviews.com/#jsrmodel@parentref - https://www.jsviews.com/#viewmodelsapi@accessparent - https://www.jsviews.com/#jsvviewmodelsapi@ismanagersample New support for asynchronous or batched observable change events (asyncObserve): - https://www.jsviews.com/#delay New features available for scenarios using sorting and filtering (mapProps and mapDepends): - https://www.jsviews.com/#tagoptions@mapprops Bug fixes: - #415 (Markup within element tag - incorrect whitespace) - #417 (Side-effect when calling Tag.updateValue during setProperty call) - #419 (Regression: checkbox widget not working since v1.0.0) - #420 (Template tag responses to array changes) - Several other minor bug fixes Additional and improved documentation topics and samples... Updated tree view samples: - https://www.jsviews.com/#samples/tag-controls/tree Updated Typescript definitions (soon to be deployed DefinitelyTyped): - https://www.jsviews.com/#typescript Many additional unit tests...
The above changes are included in the new v1.0.3 release. (Let me know if see any issues!) |
Please see the following fiddle
What I'm trying to do is have a function execute when an array is changed observably. I.e. adding or removing elements from the array.
The example is very simple. I want to aggregate information from the array and present it. Here I have used a function on the viewmodel but it might as well have been a converter.
As demonstrated the following template expression does not pick up the observable insert:
{^{:highestNumber(array)}}
but this expression does:
{^{:array.length && highestNumber(array)}}
I assume that the thought process is that you would normally iterate over arrays such as
{^for{ array}}
but in my case I want to present the array by passing it through a function or a converter.I'm able to make it work by adding
.length
to the template expression and this causes jsviews to re-evaluate the whole expression as a result of the length changing.The text was updated successfully, but these errors were encountered: