-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Added reverse filter support for v-for #1441
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
Conversation
|
Nice one. Since this is |
|
Agree. Btw, remember I offered to use |
src/instance/misc.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think splitting this here makes the code harder to follow. It's ok that this check stay in the watcher.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's more about responsibilities, IMO. Written this way, misc.js mixin is responsible for both forward and reverse filters, and abstracts forContext existence from the watcher.
Also, alias === expression does not look nice (because I easily bypassed this logic in my initial fiddle), so the logic will probably grow and I definitely don't want to put it to watcher (because it is not its responsibility) or for directive (to keep reverse filtering logic reusable just for a case). Any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I saw scope._bubbleChanges it's a bit confusing, because this is a v-for-scope-only thing, but is attached to Vue's prototype, which imo is the wrong place. It only works because of the prototypal inheritance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for expression check - a reverse write should be applied as long as the expression starts with the alias. e.g. item.test and item[test] both should trigger reverse write. So you need a regular expression, e.g. new RegExp(alias + '\\b'). To be more efficient we might want to construct this regex right when we parse the alias in v-for.
|
Btw, if possible please re-submit this to the |
|
this.reverse=(this.sortKey==sortKey)?!this.reverse:false; is not working in latest version for example {{ people.name}} {{ people.age}} |
|
@MicroDreamIT I think you're missing the point of this PR. It's intended to allow to re-apply changes done to the array processed with two-way filters. Sorting and reverse order sorting are irrelevant to this. |
|
@karevn I am new in vuejs and javascript world, how can i make it happen? |
|
@MicroDreamIT please ask this question at Vue chat: https://gitter.im/vuejs/vue |
An implementation for this issue: #1433