Closed stgolem closed 7 years ago
Personally, I'm not a fan of TypeScript, but I agree that typescript definitions could be helpful for people which use it. If you're familiar with TypeScript, could you add definitions and make pull request? It shouldn't be difficult.
I'm not that good at TypeScript also. Never created definitions for complex modules. Also i am not that good at vidom (just started to learn and try it). So maybe someone else out there in community?
If you have any questions about Vidom, feel free to ask )
The best way to create typings is to know the structure of classes and objects. If you have something like that, maybe internally, it would help a lot. From documentation i cannot see much, mostly there are just generic definitions. What we need is full structure with inheritance and types used in params.
Let's discuss, for instance for children()
method of TagNode
(https://github.com/dfilatov/vidom/wiki/TagNode-API#children)
TagNode children(
VNode child | Array<VNode> children | String text
)
Could you write what is not clear here and what you would expect to see to help you?
Ok. Here you go. What is TagNode? A class? Is there any nested classes? What is TagNode properties (get, set) and functions? How do i create TagNode? Same for VNode.
See? You have high level API documented, with examples and all. But we need class structure. In other case i have to go to sources and spend time composing that.
Ok, let's start with top-level definitions and creating.
VNode = TagNode | TextNode | FragmentNode | ComponentNode | FunctionComponentNode
Is there any nested classes?
No
How do i create TagNode?
All types of nodes are created via top-level factory function node(...)
.
node(String tagName)
creates an instance of class TagNode
node(String "fragment")
creates an instance of class FragmentNode
node(String "text")
creates an instance of class TextNode
node(Function ComponentClass)
creates an instance of class ComponentNode
node(Function FunctionComponentClass)
creates an instance of class FunctionComponentNode
Methods of TagNode
:
key(String key)
ns(String ns)
attrs(Object attrs)
children(String | VNode | Array VNode children)
html(String html)
ctx(Object ctx)
All these methods are setters and setup corresponding fields. There's no any getters. They all return the same instance (this
) for chainability.
Methods of TextNode
:
key(String key)
children(String children)
Methods of FragmentNode
:
key(String key)
children(VNode | Array VNode)
ctx(Object ctx)
Methods of ComponentNode
and FunctionComponentNode
:
key(String key)
attrs(Object attrs)
children(String | VNode | Array VNode children)
ctx(Object ctx)
@stgolem Is it enough to go ahead?
That is great start! I think from here and docs i can compose some typings already. If i have further questions i'll ask here.
I'm gonna add vidom.d.ts
in 0.9
closed in favour of #306
TypeScript is so much cooler than plain JavaScript! And we have typings for everything! But not for vidom :disappointed:
Have you got plans for it?