defineMeta
to define props, events, options at one place
#514
Replies: 2 comments 5 replies
-
Drawbacks
Also provided examples don't really appear to me as "easy to read & navigate" and the proposal still doesn't provide full separation between component meta/definition & business logic, you can still mix them: const foo = 'foo';
function bar () {}
defineMeta(...);
// more business logic I do however agree with the idea in general. Maybe a separate tag ( |
Beta Was this translation helpful? Give feedback.
-
I think just having the That being said, I don't think the problem here is well-defined or valid:
|
Beta Was this translation helpful? Give feedback.
-
Summary
Make SFC code structural just like
defineComponent
by separating component meta (props, events, options) & business logic.Problem
With the increase of new macros in Vue 3, we are breaking the SFC's
script
block in much smaller chunks and it makes code less structural.ATM, we have to write multiple macros to define props, events, options, slots, etc. This is make code less structural and hard to read & navigate when component have all three of them.
Above is just minimal example using all three macros. In real world, we may have more props, emits, options & slots. It will be hard to read, navigate and maintain. Taking it further, due to multiple macros written independently there's possibility of writing business logic between them.
Naming
Following @johnsoncodehk convention from volar ("show component meta"), I named it
defineMeta
.Alternatively, We can also name it
defineComponent
(like withoutsetup
attribute inscript
block) to align with existing API but it might make more confusion or might not be possible.Example/Design
Basic Usage
Basically, this is like writing
defineComponent
but without setup function. and returningprops
&context
likesetup
function.Component meta at one place. No more, multiple macros for props, emits, options, attrs, slots, etc.
Alternative API
Alternatively, We can make
context
flat for better DX.TypeScript
We can also use
defineMeta
with TypeScript.Drawbacks
props
&emits
in generic placeholder (IDK what<>
is called) and options asdefineMeta
's argument.defineMeta
withwithDefaults
is arguable. (I don't know how it will work withdefineMeta
).One possible solution is we can allow default in
defineMeta
's argumentprops
.View Example
Benefits
props
,emits
,options
,attrs
,slots
&expose
. (In next major version if we remove other macros in case if this RFC is accepted then Vue SFC setup API will be simple at it's best and easy to learn)Enforces avoid writing business logic between multiple macros.ESLint rule can do thisAlternatives
Using existing API with multiple macros
Adoption Strategy
Beta Was this translation helpful? Give feedback.
All reactions