forked from nullstack/nullstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
101 lines (90 loc) · 3.09 KB
/
index.js
File metadata and controls
101 lines (90 loc) · 3.09 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import deserialize from '../shared/deserialize';
import element from '../shared/element';
import fragment from '../shared/fragment';
import generateTree from '../shared/generateTree';
import getProxyableMethods from '../shared/getProxyableMethods';
import { loadPlugins, usePlugins } from '../shared/plugins';
import client from './client';
import context, { generateContext } from './context';
import environment from './environment';
import instanceProxyHandler from './instanceProxyHandler';
import invoke from './invoke';
import './liveReload';
import page from './page';
import params, { updateParams } from './params';
import project from './project';
import render from './render';
import rerender from './rerender';
import router from './router';
import settings from './settings';
import worker from './worker';
context.page = page;
context.router = router;
context.settings = settings;
context.worker = worker;
context.params = params;
context.project = project;
context.environment = window.environment;
client.memory = deserialize(JSON.stringify(window.instances));
const scope = client;
scope.generateContext = generateContext;
scope.context = context;
client.plugins = loadPlugins(scope);
export default class Nullstack {
static element = element;
static invoke = invoke;
static fragment = fragment;
static use = usePlugins('client');
static start(Starter) {
setTimeout(async () => {
window.addEventListener('popstate', () => {
router._popState();
});
client.routes = {};
updateParams(router.url);
client.currentInstance = null;
client.initializer = () => element(Starter);
client.selector = document.querySelector('#application');
if (environment.mode === 'spa') {
scope.plugins = loadPlugins(scope);
worker.online = navigator.onLine;
typeof context.start === 'function' && await context.start(context);
context.environment = environment;
client.virtualDom = await generateTree(client.initializer(), scope);
const body = render(client.virtualDom);
client.selector.replaceWith(body);
client.selector = body
} else {
client.virtualDom = await generateTree(client.initializer(), scope);
context.environment = environment;
scope.plugins = loadPlugins(scope);
worker.online = navigator.onLine;
typeof context.start === 'function' && await context.start(context);
client.nextVirtualDom = await generateTree(client.initializer(), scope);
rerender(client.selector);
client.virtualDom = client.nextVirtualDom;
client.nextVirtualDom = null;
}
client.processLifecycleQueues();
delete window.context;
}, 0)
return generateContext({});
}
_self = {
prerendered: false,
initiated: false,
hydrated: false,
terminated: false,
}
constructor() {
const methods = getProxyableMethods(this);
const proxy = new Proxy(this, instanceProxyHandler);
for (const method of methods) {
this[method] = this[method].bind(proxy);
}
return proxy;
}
render() {
return false;
}
}