UNPKG

1.96 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const debug = require("debug");
4const neweb_browser_1 = require("neweb-browser");
5const neweb_components_1 = require("neweb-components");
6const neweb_core_1 = require("neweb-core");
7const Neweb = require("./common");
8const ClientPageRenderer_1 = require("./lib/neweb-components/client/ClientPageRenderer");
9if (process.env.NODE_ENV === "development") {
10 debug.enable("*,-socket.io:*,-engine:*,-socket.io-client:*,-engine.io-client:*,-socket.io-client,-socket.io-parser");
11}
12const SocketIOClient = require("socket.io-client");
13const doc = new neweb_components_1.Document({
14 window,
15});
16neweb_components_1.Component.setDocument(doc);
17const initial = window[neweb_core_1.INITIAL_VAR];
18const socket = SocketIOClient(window.location.protocol + "//" + window.location.host);
19const modulesManager = new neweb_browser_1.ModulesManager({
20 address: window.location.protocol + "//" + window.location.host + "/modules",
21 modules: [{
22 name: "neweb",
23 version: undefined,
24 type: "npm",
25 content: "",
26 exports: Neweb,
27 },
28 ],
29});
30const app = new neweb_browser_1.Application({
31 modulesManager,
32});
33const pageRenderer = new ClientPageRenderer_1.default({
34 app,
35 rootHtmlElement: document.getElementById("root"),
36});
37const pageMetaManager = new neweb_browser_1.PageMetaManager();
38const seance = new neweb_browser_1.Seance({
39 app,
40 seanceId: initial.seanceId,
41 socket,
42 pageRenderer,
43 pageMetaManager,
44});
45const realPushState = history.pushState.bind(history);
46history.pushState = (url) => {
47 seance.navigate(url);
48 realPushState(url, "", url);
49};
50const logger = console;
51seance.initialize(initial).then(() => {
52 window.dispatchEvent(new Event("neweb-seans-initialized"));
53 logger.log("Initialized");
54});
55window.global = window;