backpage
Advanced tools
Comparing version 0.0.1-17 to 0.0.1-18
import { randomUUID } from 'crypto'; | ||
import DiffMatchPatch from 'diff-match-patch'; | ||
import { MultikeyMap } from 'multikey-map'; | ||
import { window } from './@jsdom.js'; | ||
const INITIAL_CONTENT = window.document.createElement('div'); | ||
INITIAL_CONTENT.innerHTML = '<div>BackPage</div>'; | ||
const dmp = new DiffMatchPatch(); | ||
@@ -29,3 +26,3 @@ dmp.Diff_Timeout = 0.05; // seconds | ||
title: 'BackPage', | ||
content: INITIAL_CONTENT, | ||
content: undefined, | ||
} | ||
@@ -74,4 +71,12 @@ }); | ||
if (content !== undefined) { | ||
const patches = cachedDOMPatch(snapshot.content, content); | ||
if (patches.length > 0) { | ||
if (snapshot.content) { | ||
const patches = cachedDOMPatch(snapshot.content, content); | ||
if (patches.length > 0) { | ||
snapshot = { | ||
...snapshot, | ||
content, | ||
}; | ||
} | ||
} | ||
else { | ||
snapshot = { | ||
@@ -156,5 +161,7 @@ ...snapshot, | ||
title: snapshot.title, | ||
content: clientState.content === undefined | ||
? snapshot.content.innerHTML | ||
: cachedDOMPatch(clientState.content, snapshot.content), | ||
content: snapshot.content | ||
? clientState.content | ||
? cachedDOMPatch(clientState.content, snapshot.content) | ||
: snapshot.content.innerHTML | ||
: '', | ||
}; | ||
@@ -161,0 +168,0 @@ clientState.idle = false; |
@@ -7,2 +7,3 @@ import DiffMatchPatch from 'diff-match-patch'; | ||
const RECONNECT_INTERVAL = 1000; | ||
const INITIAL_BODY = document.body.cloneNode(true); | ||
const dmp = new DiffMatchPatch(); | ||
@@ -40,3 +41,8 @@ let pendingNotifications = 0; | ||
latestHTML = content; | ||
document.body.innerHTML = latestHTML; | ||
if (latestHTML === '') { | ||
document.body.replaceWith(INITIAL_BODY.cloneNode(true)); | ||
} | ||
else { | ||
document.body.innerHTML = latestHTML; | ||
} | ||
} | ||
@@ -43,0 +49,0 @@ else if (latestHTML !== undefined) { |
{ | ||
"name": "backpage", | ||
"version": "0.0.1-17", | ||
"version": "0.0.1-18", | ||
"description": "Naive static HTML streaming based on React for Node.js CLI applications.", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/vilicvane/backpage.git", |
@@ -13,8 +13,2 @@ import {randomUUID} from 'crypto'; | ||
import {window} from './@jsdom.js'; | ||
const INITIAL_CONTENT = window.document.createElement('div'); | ||
INITIAL_CONTENT.innerHTML = '<div>BackPage</div>'; | ||
const dmp = new DiffMatchPatch(); | ||
@@ -36,3 +30,3 @@ | ||
title: 'BackPage', | ||
content: INITIAL_CONTENT, | ||
content: undefined, | ||
}; | ||
@@ -68,5 +62,12 @@ | ||
if (content !== undefined) { | ||
const patches = cachedDOMPatch(snapshot.content, content); | ||
if (snapshot.content) { | ||
const patches = cachedDOMPatch(snapshot.content, content); | ||
if (patches.length > 0) { | ||
if (patches.length > 0) { | ||
snapshot = { | ||
...snapshot, | ||
content, | ||
}; | ||
} | ||
} else { | ||
snapshot = { | ||
@@ -189,6 +190,7 @@ ...snapshot, | ||
title: snapshot.title, | ||
content: | ||
clientState.content === undefined | ||
? snapshot.content.innerHTML | ||
: cachedDOMPatch(clientState.content, snapshot.content), | ||
content: snapshot.content | ||
? clientState.content | ||
? cachedDOMPatch(clientState.content, snapshot.content) | ||
: snapshot.content.innerHTML | ||
: '', | ||
}; | ||
@@ -229,3 +231,3 @@ | ||
title: string; | ||
content: HTMLDivElement; | ||
content: HTMLDivElement | undefined; | ||
}; | ||
@@ -232,0 +234,0 @@ |
@@ -18,2 +18,4 @@ import DiffMatchPatch from 'diff-match-patch'; | ||
const INITIAL_BODY = document.body.cloneNode(true); | ||
const dmp = new DiffMatchPatch(); | ||
@@ -65,3 +67,7 @@ | ||
document.body.innerHTML = latestHTML; | ||
if (latestHTML === '') { | ||
document.body.replaceWith(INITIAL_BODY.cloneNode(true)); | ||
} else { | ||
document.body.innerHTML = latestHTML; | ||
} | ||
} else if (latestHTML !== undefined) { | ||
@@ -68,0 +74,0 @@ [latestHTML] = dmp.patch_apply(content, latestHTML); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
207779
4749