mirror of https://codeberg.org/pzp/pzp-set.git
Improve types of watch Obz
This commit is contained in:
parent
8983ba29f0
commit
3accb5e3b0
|
@ -3,7 +3,7 @@ node_modules
|
|||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
coverage
|
||||
**/*.d.ts
|
||||
lib/**/*.d.ts
|
||||
*~
|
||||
|
||||
# For misc scripts and experiments:
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
declare module 'obz' {
|
||||
type Remove = () => void
|
||||
export interface Obz<X> {
|
||||
(listener: (value: X) => void): Remove
|
||||
set(value: X): unknown
|
||||
value: X
|
||||
}
|
||||
function createObz(): Obz
|
||||
export = createObz
|
||||
}
|
12
lib/index.js
12
lib/index.js
|
@ -1,4 +1,3 @@
|
|||
// @ts-ignore
|
||||
const Obz = require('obz')
|
||||
const MsgV4 = require('ppppp-db/msg-v4')
|
||||
|
||||
|
@ -24,9 +23,7 @@ const PREFIX = 'set_v1__'
|
|||
* del: Array<string>,
|
||||
* supersedes: Array<MsgID>,
|
||||
* }} SetMsgData
|
||||
* @typedef {{
|
||||
* set: (ev: { event: 'add' | 'del', subdomain: string, value: string }) => void
|
||||
* }} ObzType
|
||||
* @typedef {{ event: 'add' | 'del', subdomain: string, value: string }} Event
|
||||
* @typedef {{
|
||||
* set?: {
|
||||
* ghostSpan?: number
|
||||
|
@ -39,6 +36,11 @@ const PREFIX = 'set_v1__'
|
|||
* @typedef {import('ppppp-db/msg-v4').Msg<T>} Msg<T>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @typedef {import('obz').Obz<T>} ObzType
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @typedef {T extends void ?
|
||||
|
@ -84,7 +86,7 @@ function initSet(peer, config) {
|
|||
let loadedAccountID = /** @type {string | null} */ (null)
|
||||
let loadPromise = /** @type {Promise<void> | null} */ (null)
|
||||
let cancelOnRecordAdded = /** @type {CallableFunction | null} */ (null)
|
||||
const watch = /**@type {ObzType}*/ (Obz())
|
||||
const watch = /**@type {ObzType<Event>}*/ (Obz())
|
||||
const tangles = /** @type {Map<Subdomain, MsgV4.Tangle>} */ (new Map())
|
||||
|
||||
const itemRoots = {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"include": ["lib/**/*.js"],
|
||||
"include": ["declarations", "lib/**/*.js"],
|
||||
"exclude": ["coverage/", "node_modules/", "test/"],
|
||||
"compilerOptions": {
|
||||
"checkJs": true,
|
||||
|
@ -11,6 +11,7 @@
|
|||
"module": "node16",
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"target": "es2022"
|
||||
"target": "es2022",
|
||||
"typeRoots": ["node_modules/@types", "declarations"]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue