-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (31 loc) · 1.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module.exports = function components(ripple){
if (!client) return ripple
log('creating')
// if no render is defined on a component, load up definition
Node.prototype.render = function(){
const name = this.nodeName.toLowerCase()
if (name.includes('-')) {
this.state = this.state || {}
return this.fn$ = this.fn$ || ripple
.subscribe(name)
.map(component => define(name, component))
// TODO: test this works well across all instances
// .until(new Promise(resolve => this.addEventListener('disconnected', () => {
// if (!this.isConnected) resolve()
// })))
}
}
// this is for backwards compatibility
Node.prototype.draw = function(){
this.render()
}
ready(() => Array.from(document.querySelectorAll('*'))
.filter(d => d.nodeName.includes('-'))
.map(node => node.render())
)
return ripple
}
const log = require('utilise/log')('[ri/components]')
, client = require('utilise/client')
, ready = require('utilise/ready')
, define = require('@compone/define')