Skip to content
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

Add types for VDOM events. #65

Closed
jorgebucaran opened this issue Dec 3, 2017 · 3 comments
Closed

Add types for VDOM events. #65

jorgebucaran opened this issue Dec 3, 2017 · 3 comments
Labels
types Strings, numbers, booleans

Comments

@jorgebucaran
Copy link
Owner

We have 3 VDOM events at the moment:

  • oncreate(element)
  • onupdate(element, oldProps)
  • onremove(element): remove

But they are not typed in the type declarations.

@jorgebucaran jorgebucaran added the types Strings, numbers, booleans label Dec 3, 2017
@mindplay-dk
Copy link
Contributor

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 :-)

@jorgebucaran jorgebucaran mentioned this issue Feb 13, 2018
@solenya-group
Copy link

solenya-group commented Mar 18, 2018

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
Copy link
Owner Author

Superfine 7 dropped lifecycle events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types Strings, numbers, booleans
Projects
None yet
Development

No branches or pull requests

3 participants