mirror of https://codeberg.org/pzp/pzp-goals.git
rename listen() to watch()
This commit is contained in:
parent
d9680acd27
commit
49c4e1b280
|
@ -151,7 +151,7 @@ function initGoals(peer, config) {
|
||||||
|
|
||||||
// State:
|
// State:
|
||||||
const goals = /** @type {Map<string, Goal>} */ (new Map())
|
const goals = /** @type {Map<string, Goal>} */ (new Map())
|
||||||
const listen = Obz()
|
const watch = Obz()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
@ -196,7 +196,7 @@ function initGoals(peer, config) {
|
||||||
function set(tangleID, goalDSL) {
|
function set(tangleID, goalDSL) {
|
||||||
const goal = new GoalImpl(tangleID, goalDSL)
|
const goal = new GoalImpl(tangleID, goalDSL)
|
||||||
goals.set(tangleID, goal)
|
goals.set(tangleID, goal)
|
||||||
listen.set(goal)
|
watch.set(goal)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -296,7 +296,7 @@ function initGoals(peer, config) {
|
||||||
get,
|
get,
|
||||||
getMsgPurpose,
|
getMsgPurpose,
|
||||||
list,
|
list,
|
||||||
listen,
|
watch,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ const { isMapIterator } = require('node:util/types')
|
||||||
const p = require('node:util').promisify
|
const p = require('node:util').promisify
|
||||||
const { createPeer } = require('./util')
|
const { createPeer } = require('./util')
|
||||||
|
|
||||||
test('set, getByID, list, listen', async (t) => {
|
test('set, getByID, list, watch', async (t) => {
|
||||||
const alice = createPeer({ name: 'alice' })
|
const alice = createPeer({ name: 'alice' })
|
||||||
|
|
||||||
await alice.db.loaded()
|
await alice.db.loaded()
|
||||||
|
@ -14,16 +14,16 @@ test('set, getByID, list, listen', async (t) => {
|
||||||
})
|
})
|
||||||
const aliceAccountRoot = alice.db.getRecord(aliceID)
|
const aliceAccountRoot = alice.db.getRecord(aliceID)
|
||||||
|
|
||||||
const listened = []
|
const watched = []
|
||||||
const stopListening = alice.goals.listen((goal) => {
|
const stopListening = alice.goals.watch((goal) => {
|
||||||
listened.push(goal)
|
watched.push(goal)
|
||||||
})
|
})
|
||||||
|
|
||||||
{
|
{
|
||||||
assert.strictEqual(listened.length, 0, 'listened goals is empty')
|
assert.strictEqual(watched.length, 0, 'watched goals is empty')
|
||||||
alice.goals.set(aliceID, 'newest-5')
|
alice.goals.set(aliceID, 'newest-5')
|
||||||
assert('set goal done')
|
assert('set goal done')
|
||||||
assert.strictEqual(listened.length, 1, 'listened goals has one')
|
assert.strictEqual(watched.length, 1, 'watched goals has one')
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -51,7 +51,7 @@ test('set, getByID, list, listen', async (t) => {
|
||||||
assert.strictEqual(goal.id, aliceID, 'listed goal id is correct')
|
assert.strictEqual(goal.id, aliceID, 'listed goal id is correct')
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.strictEqual(listened.length, 1, 'total listened goals was one')
|
assert.strictEqual(watched.length, 1, 'total watched goals was one')
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
typeof stopListening,
|
typeof stopListening,
|
||||||
|
|
Loading…
Reference in New Issue