-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathasync.js
More file actions
34 lines (28 loc) · 797 Bytes
/
async.js
File metadata and controls
34 lines (28 loc) · 797 Bytes
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
import asyncTag from 'async-tag';
import umap from 'umap';
import {render as $render, html as $html, svg as $svg} from './index.js';
const {defineProperties} = Object;
const tag = original => {
const wrap = umap(new WeakMap);
return defineProperties(
asyncTag(original),
{
for: {
value(ref, id) {
const tag = original.for(ref, id);
return wrap.get(tag) || wrap.set(tag, asyncTag(tag));
}
},
node: {
value: asyncTag(original.node)
}
}
);
};
export const html = tag($html);
export const svg = tag($svg);
export const render = (where, what) => {
const hole = typeof what === 'function' ? what() : what;
return Promise.resolve(hole).then(what => $render(where, what));
};
export {Hole} from './index.js';