diff --git a/utils/GunSmith/gun.js b/utils/GunSmith/gun.js index 2fb723e7..14d86ace 100644 --- a/utils/GunSmith/gun.js +++ b/utils/GunSmith/gun.js @@ -5,8 +5,8 @@ /// /// 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('>')