UNPKG

1.07 kBJavaScriptView Raw
1module.exports = function components(ripple){
2 if (!client) return ripple
3 log('creating')
4
5 // if no render is defined on a component, load up definition
6 Node.prototype.render = function(){
7 const name = this.nodeName.toLowerCase()
8 if (name.includes('-'))
9 return this.fn$ = this.fn$ || ripple
10 .subscribe(name)
11 .map(component => define(name, component))
12 // TODO: test this works well across all instances
13 // .until(new Promise(resolve => this.addEventListener('disconnected', () => {
14 // if (!this.isConnected) resolve()
15 // })))
16 }
17
18 // this is for backwards compatibility
19 Node.prototype.draw = function(){
20 this.render()
21 }
22
23 ready(() => Array.from(document.querySelectorAll('*'))
24 .filter(d => d.nodeName.includes('-'))
25 .map(node => node.render())
26 )
27
28 return ripple
29}
30
31const log = require('utilise/log')('[ri/components]')
32 , client = require('utilise/client')
33 , ready = require('utilise/ready')
34 , define = require('@compone/define')
\No newline at end of file