Add load() to subprocess

This commit is contained in:
Daniel Lugo 2021-09-13 09:32:52 -04:00
parent 5e7f025c1a
commit cb2c24d9ed

View file

@ -5,8 +5,8 @@
/// <reference path="Smith.ts" />
/// <reference path="GunT.ts" />
const Gun = require('gun')
// @ts-ignore
require('gun/nts')
require('gun/lib/load')
// @ts-ignore
Gun.log = () => {}
@ -91,6 +91,31 @@ const handleMsg = msg => {
sendMsg(msg)
})
}
if (msg.type === 'load') {
const { id, path } = msg
const [root, ...keys] = msg.path.split('>')
/** @type {GunT.GUNNode} */
let node =
{
$root: gun,
$user: user
}[root] || gun.user(root)
for (const key of keys) {
node = node.get(key)
}
node.load((data, key) => {
/** @type {Smith.GunMsgLoad} */
const res = {
data,
id,
key,
type: 'load'
}
sendMsg(res)
})
}
if (msg.type === 'on') {
const [root, ...keys] = msg.path.split('>')