-
Notifications
You must be signed in to change notification settings - Fork 546
Remove filters #97
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
Remove filters #97
Conversation
I think this is great. The only bad thing about removing filters would be if they were cached, since methods are not, but it seems like they aren't as well, and things we often filter would not really get super performance impact if they were cached. I usually use filters only to add currency formatting to numbers or for formatting dates. |
Good to see these out of the picture |
@yyx990803 -1 for this, and hope we can provide something cachable like Angular Pipe as Personally I'm a fan of impure Or is any chance that how can we extend the template syntax via vue-loader plugins. |
So will global filters and the I like how filters gives you a hook to a function that is "separate" from the main logic of a component. Right now I'm building a financial app, and we use filters for formatting filters a lot; having to explicitly mix in filters to components feels like both a convenience and organisational hit. Something like the static data plugin would be nice to have in the core if this is going away. <template>
<div>{{ filter(action()) }}</div>
</template>
<script>
export default {
staticData: {
filter () { ... },
...
},
methods: {
action () { ... }
}
}
</script> |
Composition API may help you separate these methods by concern |
How could it be? I just want to use the global filters and now I'd have to import them everywhere? |
Let's be clearer, A cachable filter is much better then pipeline operator, and it does not even reach stage 3. |
Sure. JSX is "kind of HTML in Javascript". Our templates are, for the most part, snippets of Javascript expesssions in HTML, with special, but parser-compliant attributes like v-bind:click on the one hand and our special v-for syntax. That being said, the reason we want to be closer to "just javascript" in the template expressions is clearly laid out in the proposal: Tooling. Each special syntax that we introduce makes it harder for us to provide things like type safety, code completion and other things people do want and value in templates via tooling like the vetur extension in vscode. Ourt filter syntax is one of the things that makes this harder for us to provide.
filter return values are not cached (like computed properties are), in case you mean that. If you mean something else, I'm not sure what. Since filters are usually pure functions, they can be memoized though, just like normal functions. |
Angular does have related tool
Oh, really? Vue has added Finally, we love Vue because it's easy to use and full of magic. If we prefer plain JavaScript why do we not choose React which is pure JavaScript? (Automatically binding this for methods for example) It's definitely not reasonable to remove You're the library authors may think about refactoring or simplifying the code base, it's of course reasonable, but I'm still a single user totally against this proposal to destroy the good part of Vue. |
Yep, I meant a proposal by adding cache support for filters instead. So that And again, Or is any chance that how can we extend the template syntax via vue-loader plugins. It will also make senses for library authors and users. |
Yep. And the expression int hat <div v-slot="{ someprop, someOtherprop }"> That make it very easy to parse, any JS parser can. So tooling can very easily analyse this expression and provide code completion for it.
We want to stay lean and small and be usable directly in a browser. not having to ship additional parsing code for stuff because it's just javascript that we can insert into the generated code as-is, makes our bundle smaller. Angular doesn't focus on that stuff as that's not a specific usecase for angular
The "we" you are talking about is likely not as homgenous as you make it out to be. As you can see in this RFc discussion, quite a number of people are happy filters might be gone.
I definitely disagree. :)
Because we don't have none of issues with directives or v-model that we have with the filters, because directives/v-model don't introduce a new, proprietary syntax into the Javascript expression that we pass as their value. They don't come with issues for parsing or tooling. Syntax-wise, they are XML attributes whose content we can parse as Javascript. nothing proprietary.
Just to make sure, have you read that we would consider providing backwards compatibility in the Comptibility build of Vue 3? That would still mean that filters will be gone in v4, but you could migrate slowly at your own pace. |
Filters are just a Vue-specific syntax for function calls. Literally. Why not just calling functions the JavaScript way instead of learning a non-standard syntax which doesn't really provide additional value? |
Angular async pipes are awkward for error handling. By simplifying something intrinsically impure/stateful into a pure-looking syntax, it also leads developers to forget about handling pending / error cases, or figure out esoteric workarounds to solve it inside the template. IMO a scoped-slots based component like vue-promised is more explicit and understandable for handling async values (and observables as well). Or, if using composition API: const { data, error, isPending } = usePromise(fetch('/api'))
const { value, error } = useObservable(source$) Not sure if extending the template syntax to handle such cases really is a good idea. |
This is not true. Angular team is focusing on If you mean using it in browser directly via CDN, I can't contradict, but they may not care about bundle size that much, because Vue 3 via support tree shaking much better, if they do care about bundle size so much, why not adding a build step?
Maybe, but as @yyx990803 always said (maybe not totally correct here), not the main part of people represents all of people/users. There are a lot of people won't stand-up before or even after changes happened.
Is there anyone using And modifiers of directives is something against JavaScript expression to me. There is no such usage in html template before Vue AFAIK.
It is not true.
Doesn't that means if we want Vue 3 bundle only, filters will not be supported. And I do not want to remove filters. |
@Akryum That's true, so my proposal is extending current filter and enhancing it to support |
So how would you say why So my another proposal is, adding support for custom template syntax via And in general, please don't pretend template as plain JavaScript, it's not, it's full of DSL and magic. |
We're most likely handling API which is always asynchronous in full of our real works, so built-in support for Promise and Observable seems reasonable to me personally. (I'm a big fan of Observable here). |
Waiting for your responses, and I'm going to sleep now. Good night(morning or afternoon actually 🤪). |
It's still an already existing JavaScript operator. IMO it would be better to have the actual
They are still valid XML attributes with JavaScript expressions in the value. You can do the same with some HTML attributes before Vue (for example,
We already have computed and we don't want to make the templates more complex. The goal of the RFC is actually the opposite.
We don't pretend Vue templates are plain JavaScript. They are valid HTML/XML with JavaScript expressions in some attributes. |
@JounQin I think the async pipe case is in fact irrelevant, as Vue filters never supported impure use cases anyway. Our general design perspective is that most of the abstraction needs can be achieved via either scoped slots (which is the reason why we improved it with That said, you can technically do anything with the template using a custom compiler transform in Vue 3, so if you really really want to add your own syntax, you can. |
I played a lot with filters at the early days of Vue, but I had 3 years ago a job where a had use of filters had repercussions in production. I can't remember exactly what, because it wasn't in my team, but I know it was syntax related. From this time, I always had some mistrust in filter and never used it anymore... It's so easy to make a computed or a method, eventually calling a lib function, that I don't really need the feature. |
The value that I see in using a filter v.s. calling a method is when using global filters. Sure if you define a filter within a component that you only use once, there's not much value in using a filter v.s. a method. But, for things like creating a Technically the Vue Composition API can help with this concern, but I'm not sure it's worth importing and calling a composition function to just modify a string, or for other common filter use-cases. Consider the following two solutions: With Filters
Without Filters, using the Composition API
Lastly, I come from a CMS called Craft, which uses the Twig templating language which has filters. The built-in Twig filters like |
you wouldn't have to actually format the value in I would use a simple import (or maybe // filter.js
export default {
formatPrice(value) { /* implementation here ... */ }
}
// my-component.vue
import filters from '@filters'
setup() {
return {
filters,
item,
}
} <template>
<div>Price: {{ filters.formatPrice(item.price) }}
</template> Yeah, you have to import the filters but that's something your editor can automatically insert for you. I found myself using less and less globally registered stuff and locally registering components etc as I value the explicitness, being able to jump to the definition of the import in my editor, for example... |
@jakedohm In Vue 2 you can register a global mixin: Vue.mixin({
methods: {
formatPrice (value) { ... }
}
}) |
what's the difference in writing? {{ amount | formatPrice }}
{{ formatPrice(amount) }} Personally for me the second one is clearer, if {{ connection | fastConnection }} |
The others said they want to keep syntax just JavaScript, but implicitly calling onClick is not JavaScript here. And
It does. It's could be an alternative for it.
Yeah, only v3, not v4.
So how could you say we are removing filters for better Editor/IDE support then.
Or a leanest bundle with a standard bundle. And of course, it's my personal idea, maybe not related to this RFC. |
It has been declared a few times that the key difference is And also, I've said We can make |
Are you worried about v4? v3 is not even out.... if it follows the same steps as the v2 we are a long way from it. Not even worth to discuss, I bet the core team is not even thinking on v4.
I didn't say that...
The standard bundle wouldn't be the leanest...
You know I wasn't replying to you, right? I was actually replying to underfin... To be honest you are not discussing anything at this point, are all you concerns of this RFC address or you still have more? if so please describe your arguments, thanks |
That's kinda weird way to put it, though. VanillaJS equivalent is It's not the same, but definitely much less confusing than filters that are used on a place where you expect to be able to put any javascript expression. |
@panstromek So why |
|
That's equivalent of [edit] Moreover, both of those are still valid javascript expressions with more ore less same semantics as vanillaJS. Filters are invalid JS expressions - or kinda valid, but with completely different semantics. |
That's @LinusBorg said filters will gone on v4 at #97 (comment), not me, thanks.
My apologize then, some others said that.
I mean two bundles, OK?
Of course I knew, I was just telling you there was no worth to talking that again and again.
Aren't you? I'm talking about writing a custom transform for dropping built-in filters. |
@pikax @panstromek You guys are just talking about what you picked.
Can I say
It's only your own theory, it's confusing for others. I won't apply you guys anymore, it's meaningless. |
I can't answer for him, but on my opinion, v4 is so far that a lot of things can change.
There will be at least 2 bundles:
It wasn't worth talking that to you again, but not to the person I answered to. Also your reply was not useful at all.
No one will stop you to write custom directives and append them to the compiler, and no one is arguing that.
Since you didn't understand, I apologise, what I mean is, |
The RFC states very specifically why it's desirable that the "Javascript" in templates doesn't have any extra syntax. I even explained it again, but it seems you don't understand so I'll try a third time:
So you see, it's not about us wanting to use "just Javascript" because that's cleaner in a philophical sense. We say that the filters syntax not being Javascript add both complexity and bundle size to Vue, at litle advantage. So please stop arguing about |
@LinusBorg I understand your approach, and I have to say it's great, and I also said we could add it back via My point here then is that, if we do want to make a compatible v3 version of
That's what I'm talking about now. |
Well yes you can do that. But that's then something you/the community can provide and is out of scope of this discussion. I prrsonally don't think that we as the Vue team will provide an "official" transform as that would support fragmentation. |
@LinusBorg Interesting. Then how would v3 compatible Maybe still |
I remember fighting for not removing some of the filters that were in 1.0, when 2.0 came out. Later, (after becoming smarter about Vue) I was sort of wondering when this would happen. It'll be painful for those who based a lot of functionality on custom filters, but in the end, it's a good streamlining decision IMHO. Scott |
@LinusBorg thanks for the additional (or re-explained) information on why removing filters is good for the bundle size and reducing complexity for Vue. My main concerns have been addressed and I'll be happy with the removal of filters in Vue 3 if that's the way you decide to go. |
This RFC is now in final comments stage. An RFC in final comments stage means that: The core team has reviewed the feedback and reached consensus about the general direction of the RFC and believe that this RFC is a worthwhile addition to the framework. |
@ yyx990803 I still recommend to provide an implement of custom transformer as an alternative! |
@yyx990803, I totally agree with this RFC. Go ahead with it please |
Why not make an IDE plugin like golang ,Using press Ctrl + s or tab to automatically import ". / filters" . |
Rendered