Simplify
This commit is contained in:
parent
58c3c73497
commit
70adbecc5a
1 changed files with 16 additions and 15 deletions
|
|
@ -301,24 +301,25 @@ function createReplica(path, afterMap = false) {
|
||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
once(cb, opts = { wait: 500 }) {
|
once(cb, opts = { wait: 500 }) {
|
||||||
|
// We could use this.on() but then we couldn't call .off()
|
||||||
const tmp = createReplica(path, afterMap)
|
const tmp = createReplica(path, afterMap)
|
||||||
if (afterMap) {
|
if (afterMap) {
|
||||||
// TODO
|
throw new Error('Cannot call once() after map() on a GunSmith node')
|
||||||
} else {
|
|
||||||
/** @type {GunT.ListenerData} */
|
|
||||||
let lastVal = null
|
|
||||||
|
|
||||||
tmp.on(data => {
|
|
||||||
lastVal = data
|
|
||||||
})
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
if (cb) {
|
|
||||||
cb(lastVal, path.split('>')[path.split('>').length - 1])
|
|
||||||
}
|
|
||||||
tmp.off()
|
|
||||||
}, opts.wait)
|
|
||||||
}
|
}
|
||||||
|
/** @type {GunT.ListenerData} */
|
||||||
|
let lastVal = null
|
||||||
|
|
||||||
|
tmp.on(data => {
|
||||||
|
lastVal = data
|
||||||
|
})
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (cb) {
|
||||||
|
cb(lastVal, path.split('>')[path.split('>').length - 1])
|
||||||
|
}
|
||||||
|
tmp.off()
|
||||||
|
}, opts.wait)
|
||||||
|
|
||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
put(data, cb) {
|
put(data, cb) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue