jorgebucaran / superfine

Absolutely minimal view layer for building web interfaces
https://git.io/super
MIT License
1.57k stars 78 forks source link

Add types for VDOM events. #65

Closed jorgebucaran closed 5 years ago

jorgebucaran commented 6 years ago

We have 3 VDOM events at the moment:

But they are not typed in the type declarations.

mindplay-dk commented 6 years ago

I haven't been able to figure out the right syntax for this - hopefully a solution can be used as a reference to solve #36 more broadly, which I'd be happy to help with :-)

solenya-group commented 6 years ago

In case it's of any help, I'm maintaining a typescript version of ultradom (here: https://github.com/pickle-ts/pickle/blob/master/src/dom.ts ). The types in question:

export interface VAttributes extends VLifecycle {
    key?: string | number
}

export interface VLifecycle {
    oncreate? (element: Element, attributes?: VAttributes) : void
    onupdate? (element: Element, attributes?: VAttributes) : void
    onremove? (element: Element, remove: () => void) : void
    ondestroy? (element: Element) : void
}

By separating out lifecycle into an interface, I'm able to reuse this interface for a function that composes lifecycle events: https://github.com/pickle-ts/pickle/blob/master/src/lifecycle.ts (very handy for animations!)

Maybe some interesting background here. I wrote an HTML DOM generator in C# a while ago ( https://github.com/hyperlinq/hyperlinq ) . C# generics are very expressive, so I was even able to statically type check that a particular attribute was legal for a particular element. I might investigate whether something similar is possible with typescript/ultradom in the future. I'm just like everyone else rather bogged down in work right now!

jorgebucaran commented 5 years ago

Superfine 7 dropped lifecycle events.