UNPKG

2.13 kBPlain TextView Raw
1import debug = require("debug");
2import { Application, ModulesManager, PageMetaManager, Seance } from "neweb-browser";
3import { Component, Document } from "neweb-components";
4import { INITIAL_VAR, ISeanceInitialInfo } from "neweb-core";
5import Neweb = require("./common");
6import ClientPageRenderer from "./lib/neweb-components/client/ClientPageRenderer";
7if (process.env.NODE_ENV === "development") {
8 debug.enable(
9 "*,-socket.io:*,-engine:*,-socket.io-client:*,-engine.io-client:*,-socket.io-client,-socket.io-parser");
10}
11import SocketIOClient = require("socket.io-client");
12const doc = new Document({
13 window,
14});
15Component.setDocument(doc);
16const initial: ISeanceInitialInfo = (window as any)[INITIAL_VAR];
17const socket = SocketIOClient(window.location.protocol + "//" + window.location.host);
18const modulesManager = new ModulesManager({
19 address: window.location.protocol + "//" + window.location.host + "/modules",
20 modules: [{
21 name: "neweb",
22 version: undefined,
23 type: "npm",
24 content: "",
25 exports: Neweb,
26 },
27 /*{
28 name: "react",
29 version: undefined,
30 type: "npm",
31 content: "",
32 exports: React,
33 },
34 {
35 name: "react-dom",
36 version: undefined,
37 type: "npm",
38 content: "",
39 exports: ReactDOM,
40 }*/],
41});
42const app = new Application({
43 modulesManager,
44});
45const pageRenderer = new ClientPageRenderer({
46 app,
47 rootHtmlElement: document.getElementById("root") as HTMLElement,
48});
49const pageMetaManager = new PageMetaManager();
50const seance = new Seance({
51 app,
52 seanceId: initial.seanceId,
53 socket,
54 pageRenderer,
55 pageMetaManager,
56});
57const realPushState = history.pushState.bind(history);
58history.pushState = (url: string) => {
59 seance.navigate(url);
60 realPushState(url, "", url);
61};
62const logger = console;
63seance.initialize(initial).then(() => {
64 window.dispatchEvent(new Event("neweb-seans-initialized"));
65 logger.log("Initialized");
66});
67(window as any).global = window;