UNPKG

@hakit/core

Version:

A collection of React hooks and helpers for Home Assistant to easily communicate with the Home Assistant WebSocket API.

3 lines (2 loc) 1.54 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),u=require("zustand"),d=(n,t)=>{const{last_changed:e,last_updated:s,context:c,...o}=n,{last_changed:l,last_updated:a,context:f,...r}=t;return JSON.stringify(o)===JSON.stringify(r)},C=u.create(n=>({routes:[],setRoutes:t=>n(()=>({routes:t})),entities:{},setHassUrl:t=>n({hassUrl:t}),hassUrl:null,hash:"",locales:null,setLocales:t=>n({locales:t}),setHash:t=>n({hash:t}),setPortalRoot:t=>n({portalRoot:t}),windowContext:window,setWindowContext:t=>n({windowContext:t}),setEntities:t=>n(e=>{let s=!1;const c={...e.entities};for(const[o,l]of Object.entries(t)){const a=e.entities[o];if(!a){c[o]=l,s=!0;continue}d(a,l)||(c[o]=l,s=!0)}return s?{entities:c,lastUpdated:Date.now(),ready:!0}:e}),connectionStatus:"pending",setConnectionStatus:t=>n({connectionStatus:t}),connection:null,setConnection:t=>n({connection:t}),cannotConnect:!1,setCannotConnect:t=>n({cannotConnect:t}),ready:!1,setReady:t=>n({ready:t}),auth:null,setAuth:t=>n({auth:t}),config:null,setConfig:t=>n({config:t}),user:null,setUser:t=>n({user:t}),error:null,setError:t=>n({error:t}),globalComponentStyles:{},setGlobalComponentStyles:t=>n(()=>({globalComponentStyles:t})),disconnectCallbacks:[],onDisconnect:t=>n(e=>({disconnectCallbacks:[...e.disconnectCallbacks,t]})),triggerOnDisconnect:()=>n(t=>(t.disconnectCallbacks.forEach(e=>e()),{disconnectCallbacks:[]}))})),g=i.createContext({});exports.HassContext=g;exports.useInternalStore=C; //# sourceMappingURL=HassContext.js.map