11import element from '../shared/element'
2- import fragment from '../shared/fragment'
32import generateTree from '../shared/generateTree'
43import { loadPlugins , useClientPlugins } from '../shared/plugins'
54import client from './client'
65import context , { generateContext } from './context'
76import environment from './environment'
87import hydrate from './hydrate'
98import instanceProxyHandler , { instanceProxies } from './instanceProxyHandler'
10- import invoke from './invoke'
119import page from './page'
1210import params , { updateParams } from './params'
1311import project from './project'
@@ -16,7 +14,6 @@ import rerender from './rerender'
1614import router from './router'
1715import settings from './settings'
1816import state from './state'
19- import windowEvent from './windowEvent'
2017import worker from './worker'
2118
2219context . page = page
@@ -35,11 +32,12 @@ scope.context = context
3532
3633client . plugins = loadPlugins ( scope )
3734
35+ if ( environment . development ) {
36+ globalThis . $nullstack = context
37+ }
38+
3839export default class Nullstack {
3940
40- static element = element
41- static invoke = invoke
42- static fragment = fragment
4341 static use = useClientPlugins
4442 static context = generateContext ( { } )
4543
@@ -104,48 +102,3 @@ export default class Nullstack {
104102 }
105103
106104}
107-
108- if ( module . hot ) {
109- Nullstack . serverHashes ??= { }
110- Nullstack . serverPings = 0
111- Nullstack . clientPings = 0
112- const socket = new WebSocket ( `ws${ router . base . slice ( 4 ) } /ws` )
113- socket . onmessage = async function ( e ) {
114- const data = JSON . parse ( e . data )
115- if ( data . type === 'NULLSTACK_SERVER_STARTED' ) {
116- Nullstack . serverPings ++
117- if ( Nullstack . needsReload || ! environment . hot ) {
118- window . location . reload ( )
119- }
120- }
121- }
122- Nullstack . updateInstancesPrototypes = function updateInstancesPrototypes ( klass , hash , serverHash ) {
123- for ( const key in context . instances ) {
124- const instance = context . instances [ key ]
125- if ( instance . constructor . hash === hash ) {
126- Object . setPrototypeOf ( instance , klass . prototype )
127- }
128- }
129- if ( Nullstack . serverHashes [ hash ] ) {
130- if ( Nullstack . serverHashes [ hash ] !== serverHash ) {
131- if ( Nullstack . clientPings < Nullstack . serverPings ) {
132- window . location . reload ( )
133- } else {
134- Nullstack . needsReload = true
135- }
136- }
137- Nullstack . clientPings ++
138- }
139- Nullstack . serverHashes [ hash ] = serverHash
140- client . update ( )
141- }
142- Nullstack . hotReload = function hotReload ( klass ) {
143- if ( client . skipHotReplacement ) {
144- window . location . reload ( )
145- } else {
146- Nullstack . start ( klass )
147- windowEvent ( 'environment' )
148- }
149- }
150- module . hot . decline ( )
151- }
0 commit comments