-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
Component (base issue) #4
Comments
NOTE: |
After team discussion, we (with Evan) think that the basic feature of components should be implemented, including props/emits/slots... (Basic APIs part) However, I guess maybe we can have another version of functional components that are lightweight and cheap cost (in the future). So the to-do is: To implement Basic APIs and LifeCycles first and align the behavior with the core as much as possible. |
Well done! The basic implementation was merged. So the next step is about LifeCycles (Hooks API) and props/emits/attrs. |
archivePropsI'm going to work on props/emit from now on (I plan to separate them into separate PRs). Based on some comments in previous PRs, I feel that components should be expressed as functions that return Discussion 1It is likely that the interface will be defined through defineProps for now, but I'm wondering if we are assuming that users will use Props Option in the Options API format. Discussion 2How should we store the options information of user-defined props in the component? export default (props, { expose }) => {
// .
// .
return t0;
}; // satisfies BlockFn code like this is planned to be outputted. (Currently, the output is represented as setup or render options, but referring to the interface And export function render(
comp: BlockFn,
container: string | ParentNode
): ComponentInternalInstance {
const instance = createComponentInstance(comp);
// .
// .
} So, we need to discuss how to store user-defined props options.
|
The implementation of Props has been merged. I have already submitted a PR for Emit. |
Since we are changing the component behaviour, I wonder if we could change the API. What I was thinking is: since passing Props, Events and Attributes are the same object in Vue 3, why not just making them the same? What are props in vueThe way I see it, is props are a way for the developer to create a contract for the component, I believe Vue added type validation just for DX purpose, since at the time there was no way to get errors easily, but now there's typescript and Volar does a great job at letting us know in the IDE. DifferencesThere's basically no differences between them(validation, but not a big deal), just attributes are the props not known by the component. The only behaviour I'm not too sure in this idea is Validation and DefaultThese can be done by helper functions, the implementation should be straightforward. Proposal UsageSFC stays basically the same and the heavy lifting is done by tooling. const Comp = defineComponent(()=> {
const props = defineProps<{ test: string }>({ test: { default: 'foo' } });
const slots = defineSlots({})
return ()=> [ h('div', props.a), slots.default?.()]
}) The easiest way to explain, it's just function defineComponent(setup: ()=> any){
return _defineComponent(setup)
} Proposal ChangesDrop core support for Props, Attributes and EventsAll their related setup macros (defineProps, defineEmits), will be available outside of setup and actually have implementations across the board, based on attributes. example function defineProps(propsDefinition: ComponentOptions) {
const attrs = useAttrs()
// handle prop validation hooks
if (isObject(propsDefinition)) {
// add validation hook if needed and defaults
}
return attrs
}
function defineEmits(_emits: EmitsOptions) {
const attrs = useAttrs()
return (event: string, ...args: any[]) {
const e = attrs[`on${capitalize(event)}`];
isArray(e) ? e.forEach(c => c(...args)) : e?.(...args);
}
} SlotsI'm not too sure about this one, but technically you could consider slots as a prop too, I TSX does not support slots, by considering special function defineSlots(slots: SlotsType) {
const attrs = useAttrs()
return new Proxy(attrs, {
get(target, s) {
if (isString(s))
return target[`$_${s}`]
return target[s]
}
})
} Backwards compatibilityThis is only valid for manual
Final thoughtsThis would solve some of the issues we currently have in terms of typing, and at least personally I've been relying much more on typing to do validation than expecting vue at runtime to give me the error, and I see people fiddling with typescript definitions with Allowing these low level manipulations would possibly allow greater flexibility when is needed. I've focused more on CompositionAPI, not sure how it would play in Options API 🤔 RelatedInfer attrs for implementing HOCs |
I remember that |
Perhaps this comment is related 👀 |
Supporting them and build around them is different :)
|
They're represented in types as a |
Maybe we could support that as slots 🤔 |
I think we should have a formal RFC and experiment with it in Vue core first. |
Update progress: in PR #151, I finished creating components, refactoring props, attrs, and lifecycle. On the compiler side, I implemented the use of components in templates. |
Will vuejs/core-vapor be merged into vuejs/core one day, or keep it separated from vuejs/core? |
Ideally, |
Currently TODO
Failed to resolve component
#196Component (Runtime)
feat: vapor component base #5
[Runtime] Component Props #25
feat(runtime-vapor): component props #40
Component Emits #41
feat(runtime-vapor): component emits #103
feat(runtime-vapor): component attrs #124
feat: implement inheritAttrs #153
Component Slots #53
feat(runtime-vapor): component slot #143
Component slots #154
feat(runtime-vapor):
createSlot
#170Component slots #154
feat: Added
expose
to component instances #75feat(runtime-vapor): implement expose #181
feat(runtime-vapor): provide and inject #158
feat(runtime-vapor): setup helpers useAttrs & useSlots #172
Component setRef #184
feat(runtime-vapor): template ref on component #185
setRef update #190
feat: implement setRef update #191
Component LifeCycles #31
ref: https://x.com/sanxiaozhizi/status/1719734796832932062?s=20
The text was updated successfully, but these errors were encountered: