Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,36 @@ export default class Nullstack {

if (module.hot) {
Nullstack.serverHashes ??= {}
Nullstack.serverPings = 0
Nullstack.clientPings = 0
const socket = new WebSocket('ws' + router.base.slice(4) + '/ws');
socket.onmessage = async function (e) {
const data = JSON.parse(e.data)
if (data.type === 'NULLSTACK_SERVER_STARTED' && (Nullstack.needsReload || !environment.hot)) {
window.location.reload()
if (data.type === 'NULLSTACK_SERVER_STARTED') {
Nullstack.serverPings++
if (Nullstack.needsReload || !environment.hot) {
window.location.reload()
}
}
};
Nullstack.updateInstancesPrototypes = function updateInstancesPrototypes(klass, hash, serverHashes) {
Nullstack.updateInstancesPrototypes = function updateInstancesPrototypes(klass, hash, serverHash) {
for (const key in context.instances) {
const instance = context.instances[key]
if (instance.constructor.hash === hash) {
Object.setPrototypeOf(instance, klass.prototype);
}
}
if (Nullstack.serverHashes[hash] && Nullstack.serverHashes[hash] !== serverHashes) {
Nullstack.needsReload = true
if (Nullstack.serverHashes[hash]) {
if (Nullstack.serverHashes[hash] !== serverHash) {
if (Nullstack.clientPings < Nullstack.serverPings) {
window.location.reload()
} else {
Nullstack.needsReload = true
}
}
Nullstack.clientPings++
}
Nullstack.serverHashes[hash] = serverHashes
Nullstack.serverHashes[hash] = serverHash
client.update()
}
Nullstack.hotReload = function hotReload(klass) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nullstack",
"version": "0.16.3",
"version": "0.16.4",
"description": "Full-stack Javascript Components for one-dev armies",
"main": "nullstack.js",
"author": "Mortaro",
Expand Down