home-assistant-js-websocket
Advanced tools
Comparing version 8.0.1 to 8.1.0
@@ -17,3 +17,5 @@ import { Store } from "./store.js"; | ||
*/ | ||
export declare const getCollection: <State>(conn: Connection, key: string, fetchCollection: ((conn: Connection) => Promise<State>) | undefined, subscribeUpdates?: ((conn: Connection, store: Store<State>) => Promise<UnsubscribeFunc>) | undefined) => Collection<State>; | ||
export declare const getCollection: <State>(conn: Connection, key: string, fetchCollection: ((conn: Connection) => Promise<State>) | undefined, subscribeUpdates?: ((conn: Connection, store: Store<State>) => Promise<UnsubscribeFunc>) | undefined, options?: { | ||
unsubGrace: boolean; | ||
}) => Collection<State>; | ||
export declare const createCollection: <State>(key: string, fetchCollection: (conn: Connection) => Promise<State>, subscribeUpdates: ((conn: Connection, store: Store<State>) => Promise<UnsubscribeFunc>) | undefined, conn: Connection, onChange: (state: State) => void) => UnsubscribeFunc; |
@@ -13,3 +13,3 @@ import { createStore } from "./store.js"; | ||
*/ | ||
export const getCollection = (conn, key, fetchCollection, subscribeUpdates) => { | ||
export const getCollection = (conn, key, fetchCollection, subscribeUpdates, options = { unsubGrace: true }) => { | ||
if (conn[key]) { | ||
@@ -67,2 +67,3 @@ return conn[key]; | ||
}); | ||
store.clearState(); | ||
conn.removeEventListener("ready", refresh); | ||
@@ -112,3 +113,5 @@ conn.removeEventListener("disconnected", handleDisconnect); | ||
if (!active) { | ||
scheduleTeardownUpdateSubscription(); | ||
options.unsubGrace | ||
? scheduleTeardownUpdateSubscription() | ||
: teardownUpdateSubscription(); | ||
} | ||
@@ -115,0 +118,0 @@ }; |
@@ -775,2 +775,5 @@ (function (global, factory) { | ||
setState, | ||
clearState() { | ||
state = undefined; | ||
}, | ||
/** | ||
@@ -806,3 +809,3 @@ * Register a listener function to be called whenever state is changed. Returns an `unsubscribe()` function. | ||
*/ | ||
const getCollection = (conn, key, fetchCollection, subscribeUpdates) => { | ||
const getCollection = (conn, key, fetchCollection, subscribeUpdates, options = { unsubGrace: true }) => { | ||
if (conn[key]) { | ||
@@ -851,2 +854,3 @@ return conn[key]; | ||
}); | ||
store.clearState(); | ||
conn.removeEventListener("ready", refresh); | ||
@@ -887,3 +891,5 @@ conn.removeEventListener("disconnected", handleDisconnect); | ||
if (!active) { | ||
scheduleTeardownUpdateSubscription(); | ||
options.unsubGrace | ||
? scheduleTeardownUpdateSubscription() | ||
: teardownUpdateSubscription(); | ||
} | ||
@@ -890,0 +896,0 @@ }; |
@@ -9,2 +9,3 @@ import { UnsubscribeFunc } from "./types.js"; | ||
setState(update: Partial<State>, overwrite?: boolean): void; | ||
clearState(): void; | ||
subscribe(listener: Listener<State>): UnsubscribeFunc; | ||
@@ -11,0 +12,0 @@ }; |
@@ -59,2 +59,5 @@ export const createStore = (state) => { | ||
setState, | ||
clearState() { | ||
state = undefined; | ||
}, | ||
/** | ||
@@ -61,0 +64,0 @@ * Register a listener function to be called whenever state is changed. Returns an `unsubscribe()` function. |
@@ -101,2 +101,5 @@ export type Error = 1 | 2 | 3 | 4; | ||
}; | ||
response?: { | ||
optional: boolean; | ||
}; | ||
}; | ||
@@ -103,0 +106,0 @@ export type HassDomainServices = { |
@@ -5,3 +5,3 @@ { | ||
"sideEffects": false, | ||
"version": "8.0.1", | ||
"version": "8.1.0", | ||
"description": "Home Assistant websocket client", | ||
@@ -8,0 +8,0 @@ "source": "lib/index.ts", |
Sorry, the diff of this file is not supported yet
175038
3696