wip: mixins
This commit is contained in:
parent
2507ad2b44
commit
3a7d11ca15
@ -62,9 +62,7 @@ export function initializeComponentInstance(instance: ComponentInstance) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.$options =
|
instance.$options = resolveComponentOptions(instance.constructor)
|
||||||
instance.constructor.options ||
|
|
||||||
resolveComponentOptions(instance.constructor)
|
|
||||||
instance.$parentVNode = currentVNode as MountedVNode
|
instance.$parentVNode = currentVNode as MountedVNode
|
||||||
|
|
||||||
// renderProxy
|
// renderProxy
|
||||||
@ -262,6 +260,9 @@ export function createComponentClassFromOptions(
|
|||||||
export function resolveComponentOptions(
|
export function resolveComponentOptions(
|
||||||
Component: ComponentClass
|
Component: ComponentClass
|
||||||
): ComponentOptions {
|
): ComponentOptions {
|
||||||
|
if (Component.options) {
|
||||||
|
return Component.options
|
||||||
|
}
|
||||||
const descriptors = Object.getOwnPropertyDescriptors(Component)
|
const descriptors = Object.getOwnPropertyDescriptors(Component)
|
||||||
const options = {} as any
|
const options = {} as any
|
||||||
for (const key in descriptors) {
|
for (const key in descriptors) {
|
||||||
|
@ -1,6 +1,48 @@
|
|||||||
import { ComponentInstance } from '../component'
|
import { Component } from '../component'
|
||||||
import { ComponentOptions } from '../componentOptions'
|
|
||||||
|
|
||||||
export interface Mixin extends ComponentOptions {}
|
interface ComponentConstructor<This = Component> {
|
||||||
|
new (): This
|
||||||
|
}
|
||||||
|
|
||||||
export function applyMixins(Component: ComponentInstance, mixins: Mixin[]) {}
|
// mind = blown
|
||||||
|
type UnionToIntersection<U> = (U extends any
|
||||||
|
? (k: U) => void
|
||||||
|
: never) extends ((k: infer I) => void)
|
||||||
|
? I
|
||||||
|
: never
|
||||||
|
|
||||||
|
type ExtractInstance<T> = T extends (infer U)[]
|
||||||
|
? UnionToIntersection<U extends ComponentConstructor<infer V> ? V : never>
|
||||||
|
: never
|
||||||
|
|
||||||
|
function mixins<T extends ComponentConstructor[], V = ExtractInstance<T>>(
|
||||||
|
...args: T
|
||||||
|
): ComponentConstructor<V>
|
||||||
|
function mixins(...args: any[]): any {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Example usage
|
||||||
|
|
||||||
|
class Foo extends Component<{ foo: number }> {
|
||||||
|
test() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Bar extends Component<{ bar: string }> {
|
||||||
|
ok() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Baz extends mixins(Foo, Bar) {
|
||||||
|
created() {
|
||||||
|
this.foo
|
||||||
|
this.bar
|
||||||
|
this.test()
|
||||||
|
this.ok()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user