Skip to content

Commit ef9b596

Browse files
committed
[feature] custom components
1 parent 52017cb commit ef9b596

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

README.litcoffee

+15-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ and plain Arrays
2828

2929
VNODE = Symbol 'VNODE'
3030
31+
_registry = {}
32+
3133
Our Virtual Node is produced from a list of arguments passed
3234
to `h` function. Children are passed as tail of arguments,
3335
but any of them could be wrapped in Array
@@ -42,14 +44,26 @@ This is compensated by a more advenced child walker used in
4244
[@playframe/dom](https://github.com/playframe/dom)
4345

4446
module.exports = h = (a...)=>
45-
if typeof a[0] is 'function'
47+
if typeof (name = a[0]) is 'function'
48+
invoke a...
49+
else if component = _registry[name]
50+
a[0] = component
4651
invoke a...
4752
else
4853
a[VNODE] = true
4954
a
5055
56+
5157
h.VNODE = VNODE
5258
59+
Registering custom components like
60+
`h.use({'my-component': MyComponent})`
61+
62+
h.use = (components)=>
63+
_registry[k] = v for k, v of components
64+
return
65+
66+
5367
If the first argument of `h` function is a not a `'div'` but
5468
your Component function, we will flatten the children and attach
5569
them to `props`

index.js

+18-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)