Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
yisar committed Oct 22, 2022
1 parent 403e22d commit 98c00da
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 22 deletions.
3 changes: 3 additions & 0 deletions demo/public/client.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { resume } from '../resume.mjs'

resume(document.body)
24 changes: 24 additions & 0 deletions demo/public/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"title": "Can You Escape VintageBungalow 封测国际服",
"rate": "8.4",
"comments": [
{
"name": "阿呆",
"avatar": "https://img3.tapimg.com/default_avatars/755e9ca449be08245191a743a128a8df.jpg?imageMogr2/auto-orient/strip/thumbnail/!300x300r/gravity/Center/crop/300x300/format/jpg/interlace/1/quality/80",
"content": "bdbnxjcjcjj"
},
{
"name": "迪卢克",
"avatar": "https://img3.tapimg.com/default_avatars/7d713c00e515de52a63c0f51c8697c84.jpg?imageMogr2/auto-orient/strip/thumbnail/!300x300r/gravity/Center/crop/300x300/format/jpg/interlace/1/quality/80",
"content": "Vbjjnnn😂"
}
],
"imgs": [
"https://img.tapimg.com/market/images/de62537f7b8aad4f6b8b53cb968901f0.png?imageView2/2/h/560/w/9999/q/80/format/jpg/interlace/1/ignore-error/1",
"https://img.tapimg.com/market/images/123ec01bb9b5c42de4fa214303cf1383.png?imageView2/2/h/560/w/9999/q/80/format/jpg/interlace/1/ignore-error/1",
"https://img.tapimg.com/market/images/286c9889acad05a6e3ae2f07b5035760.png?imageView2/2/h/560/w/9999/q/80/format/jpg/interlace/1/ignore-error/1",
"https://img.tapimg.com/market/images/ea16c10e162a5b9b2e2fe6746a1de6f3.png?imageView2/2/h/560/w/9999/q/80/format/jpg/interlace/1/ignore-error/1"
],
"info": "Can You Escape VintageBungalow is new android escape game developed by KnfGame.In this game your locked inside a Vintage Bungalow House, the only way to escape from bungalow is to find the hidden key. For that you have click on the useful objects around the house and solve some interesting puzzles to find the hidden key. Good Luck and have fun playing Knf escape games and free online point and click escape games.",
"cover": "https://img.tapimg.com/market/icons/9e99c190fdb4f28136921fcc74a7467f_360.png?imageMogr2/auto-orient/strip"
}
5 changes: 3 additions & 2 deletions demo/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import polka from 'polka'
import chalk from 'chalk'
import sirv from 'sirv'
import fs from 'fs/promises'
import path from 'path'

export default function serve(options) {
console.log(options)
Expand All @@ -26,11 +27,11 @@ export default function serve(options) {
<script>
window.__state = ${JSON.stringify(state)}
</script>
<script type="module" src="./resume.js"></script></script><body>${html}</body>
<script type="module" src="/public/client.mjs"></script></script><body>${html}</body>
</html>`
res.end(str)
}).get('/data', async (req, res) => {
const json = await fs.readFile('./src/public/data.json')
const json = await fs.readFile(path.join(options.serverOutputDir, 'public/data.json'))
res.end(json)
})
.listen(1234, (err) => {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "SSR resumable framework",
"main": "index.js",
"scripts": {
"start": "node demo/server.mjs",
"start": "node src/cli.mjs -e ./demo -o ./src",
"build": "node src/build.mjs"
},
"bin": {
Expand Down Expand Up @@ -33,6 +33,7 @@
"chalk": "^5.1.2",
"es-module-lexer": "^1.0.3",
"esbuild": "^0.15.10",
"fs-extra": "^10.1.0",
"polka": "^0.5.2",
"sirv": "^2.0.2"
}
Expand Down
12 changes: 5 additions & 7 deletions src/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from 'node:path'
import url from 'node:url'
import { compile } from '../compiler/generate.mjs'
import ScriptParser from '../compiler/acorn-parser.mjs'
import fse from 'fs-extra'

const __filename = url.fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
Expand Down Expand Up @@ -82,7 +83,7 @@ export function pathPlugin(type) {


async function main() {
const res = await esbuild.build({
await esbuild.build({
entryPoints: [path.join(__dirname, '../demo/app.jsx')],
bundle: true,
platform: 'node',
Expand All @@ -96,7 +97,7 @@ async function main() {
watch: process.env.WATCH === 'true',
})

const res2 = await esbuild.build({
await esbuild.build({
entryPoints: [path.join(__dirname, '../demo/app.jsx')],
bundle: true,
platform: 'browser',
Expand All @@ -111,11 +112,8 @@ async function main() {
watch: process.env.WATCH === 'true',
})

await fs.mkdir('./src/action', { recursive: true })
await fs.mkdir('./src/public', { recursive: true })

await fs.copyFile(path.join(__dirname, "../demo/action/count.js"), path.join(__dirname, "./action/count.js"))
await fs.copyFile(path.join(__dirname, "../demo/public/style.css"), path.join(__dirname, "./public/style.css"))
await fse.copy(path.join(process.cwd(), 'demo/public'), path.join(__dirname, 'public'))
await fse.copy(path.join(process.cwd(), 'demo/action'), path.join(__dirname, 'action'))
}

main()
6 changes: 2 additions & 4 deletions src/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ async function start(options) {
const serverEntry = path.join(process.cwd(), options.entryDir, 'server.mjs')
const serverOutputDir = __dirname

import(serverEntry).then(mod => {
console.log(mod)
mod.default({ serverOutput, serverOutputDir })
})
const mod = await import(serverEntry)
mod.default({ serverOutput, serverOutputDir })
}

run(process.argv.slice(2))
3 changes: 3 additions & 0 deletions src/public/client.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { resume } from '../resume.mjs'

resume(document.body)
2 changes: 1 addition & 1 deletion src/public/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
],
"info": "Can You Escape VintageBungalow is new android escape game developed by KnfGame.In this game your locked inside a Vintage Bungalow House, the only way to escape from bungalow is to find the hidden key. For that you have click on the useful objects around the house and solve some interesting puzzles to find the hidden key. Good Luck and have fun playing Knf escape games and free online point and click escape games.",
"cover": "https://img.tapimg.com/market/icons/9e99c190fdb4f28136921fcc74a7467f_360.png?imageMogr2/auto-orient/strip"
}
}
14 changes: 7 additions & 7 deletions src/resume.js → src/resume.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ for (const event of events) {
})
}

function resume(root) {
export function resume(root) {
window.dispatch = (newState) => {
window.__state = { ...window.__state, ...newState }
import('./app.js').then(mod => {
Expand All @@ -36,7 +36,9 @@ function resume(root) {

}

var getKey = (vdom) => (vdom == null ? vdom : vdom.key)
var getKey = (vdom) => {
return vdom == null ? vdom :vdom.getAttribute ? vdom.getAttribute('key') : vdom.key
}


function patch(parent, node, vnode) {
Expand Down Expand Up @@ -120,15 +122,15 @@ function patch(parent, node, vnode) {
patch(node, node.insertBefore(keyed[newKey], oldKids[oldHead]), newKids[newHead])
newKeyed[newKey] = true
} else {
patch(node, oldkids[oldHead], newKids[newHead])
patch(node, oldKids[oldHead], newKids[newHead])
}
}
newHead++
}
}

while (oldHead <= oldTail) {
if (getKey(oldkids[oldHead++]) == null) {
if (getKey(oldKids[oldHead++]) == null) {
node.removeChild(oldKids[oldHead])
}
}
Expand Down Expand Up @@ -161,7 +163,7 @@ function createNode(vdom) {
const dom =
vdom.type === 3
? document.createTextNode('')
: document.createNode(vdom.tag)
: document.createElement(vdom.tag)

for (var i = 0; i < vdom.children.length; i++) {
dom.appendChild(
Expand All @@ -172,5 +174,3 @@ function createNode(vdom) {
}
return dom
}

resume(document.body)
28 changes: 28 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,29 @@ esbuild@^0.15.10:
esbuild-windows-64 "0.15.11"
esbuild-windows-arm64 "0.15.11"

fs-extra@^10.1.0:
version "10.1.0"
resolved "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz#02873cfbc4084dde127eaa5f9905eef2325d1abf"
integrity sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

graceful-fs@^4.1.6, graceful-fs@^4.2.0:
version "4.2.10"
resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c"
integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==

jsonfile@^6.0.1:
version "6.1.0"
resolved "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
dependencies:
universalify "^2.0.0"
optionalDependencies:
graceful-fs "^4.1.6"

matchit@^1.0.0:
version "1.1.0"
resolved "https://registry.npmjs.org/matchit/-/matchit-1.1.0.tgz#c4ccf17d9c824cc1301edbcffde9b75a61d10a7c"
Expand Down Expand Up @@ -210,3 +233,8 @@ trouter@^2.0.1:
integrity sha512-kr8SKKw94OI+xTGOkfsvwZQ8mWoikZDd2n8XZHjJVZUARZT+4/VV6cacRS6CLsH9bNm+HFIPU1Zx4CnNnb4qlQ==
dependencies:
matchit "^1.0.0"

universalify@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==

0 comments on commit 98c00da

Please sign in to comment.