mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 11:16:35 +00:00
Dynamic update panels (#3227)
This commit is contained in:
parent
2b2d2effd2
commit
d94223a61e
@ -1,14 +1,25 @@
|
||||
import { createCollection, Connection } from "home-assistant-js-websocket";
|
||||
import { Panels } from "../types";
|
||||
|
||||
const fetchPanels = (conn) =>
|
||||
conn.sendMessagePromise({
|
||||
type: "get_panels",
|
||||
});
|
||||
|
||||
const subscribeUpdates = (conn, store) =>
|
||||
conn.subscribeEvents(
|
||||
() => fetchPanels(conn).then((panels) => store.setState(panels, true)),
|
||||
"panels_updated"
|
||||
);
|
||||
|
||||
export const subscribePanels = (
|
||||
conn: Connection,
|
||||
onChange: (panels: Panels) => void
|
||||
) =>
|
||||
createCollection<Panels>(
|
||||
"_pnl",
|
||||
() => conn.sendMessagePromise({ type: "get_panels" }),
|
||||
undefined,
|
||||
fetchPanels,
|
||||
subscribeUpdates,
|
||||
conn,
|
||||
onChange
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user