-
Notifications
You must be signed in to change notification settings - Fork 627
/
renderer.js
44 lines (34 loc) 路 998 Bytes
/
renderer.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
37
38
39
40
41
42
43
44
import inject from '../vdom/inject';
import Instance from '../vdom/instance';
import ServerDriver from 'driver-server';
import Serializer from './serializer';
// Init
inject({
driver: ServerDriver
});
export default {
create(element) {
let container = ServerDriver.createBody();
let rootComponent = Instance.mount(element, container, {});
let renderedComponent = rootComponent.getRenderedComponent();
renderedComponent.toJSON = () => {
return new Serializer(container).toJSON();
};
renderedComponent.getInstance = () => {
return renderedComponent._instance;
};
renderedComponent.update = (element) => {
Instance.mount(element, container, {});
};
renderedComponent.unmount = () => {
let component = Instance.get(container);
if (!component) {
return false;
}
Instance.remove(container);
component._internal.unmountComponent();
return true;
};
return renderedComponent;
}
};