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.61 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),u=require("lodash"),d=require("deep-object-diff"),f=require("zustand"),p=["last_changed","last_updated","context"],l=(t,e=p)=>Object.fromEntries(Object.entries(t).map(([n,s])=>[n,Object.fromEntries(Object.entries(s).filter(([r])=>!e.includes(r)))])),a={xxs:600,xs:900,sm:1200,md:1536,lg:1700,xlg:1701},C=f.create(t=>({routes:[],setRoutes:e=>t(()=>({routes:e})),entities:{},setHassUrl:e=>t({hassUrl:e}),hassUrl:null,hash:"",locales:null,setLocales:e=>t({locales:e}),setHash:e=>t({hash:e}),setPortalRoot:e=>t({portalRoot:e}),windowContext:window,setWindowContext:e=>t({windowContext:e}),setEntities:e=>t(n=>{const s=d.diff(l(n.entities),l(e));if(!u.isEmpty(s)){const r=Object.keys(s).reduce((o,i)=>({...o,[i]:e[i]}),{});return Object.keys(r).forEach(o=>{n.entities[o]={...n.entities[o],...e[o]}}),n.ready?{lastUpdated:new Date,entities:n.entities}:{ready:!0,lastUpdated:new Date,entities:n.entities}}return n}),connection:null,setConnection:e=>t({connection:e}),cannotConnect:!1,setCannotConnect:e=>t({cannotConnect:e}),ready:!1,setReady:e=>t({ready:e}),lastUpdated:new Date,setLastUpdated:e=>t({lastUpdated:e}),auth:null,setAuth:e=>t({auth:e}),config:null,setConfig:e=>t({config:e}),error:null,setError:e=>t({error:e}),breakpoints:a,setBreakpoints:e=>t({breakpoints:{...e,xlg:e.lg+1}}),globalComponentStyles:{},setGlobalComponentStyles:e=>t(()=>({globalComponentStyles:e}))})),b=c.createContext({});exports.DEFAULT_BREAKPOINTS=a;exports.HassContext=b;exports.useStore=C; //# sourceMappingURL=HassContext.js.map