@glasshome/sync-layer 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/solid/index.js +18 -6
- package/dist/solid/indices.d.ts +1 -1
- package/package.json +1 -1
package/dist/solid/index.js
CHANGED
|
@@ -145,14 +145,26 @@ function groupBy(items, keyFn) {
|
|
|
145
145
|
}
|
|
146
146
|
return result;
|
|
147
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Create a lazily-initialized memo. The actual createMemo runs on first
|
|
150
|
+
* access, inside whichever Solid root is current at that point.
|
|
151
|
+
* This avoids top-level createMemo calls that execute outside any root.
|
|
152
|
+
*/
|
|
153
|
+
function lazyMemo(fn) {
|
|
154
|
+
let memo;
|
|
155
|
+
return () => {
|
|
156
|
+
if (!memo) memo = createMemo(fn);
|
|
157
|
+
return memo();
|
|
158
|
+
};
|
|
159
|
+
}
|
|
148
160
|
/** Entity IDs grouped by domain (e.g., "light" -> ["light.living_room", ...]) */
|
|
149
|
-
const byDomain =
|
|
161
|
+
const byDomain = lazyMemo(() => groupBy(Object.keys(state.entities), (id) => extractDomain(id)));
|
|
150
162
|
/** Entity IDs grouped by area (via entity registry area_id) */
|
|
151
|
-
const byArea =
|
|
163
|
+
const byArea = lazyMemo(() => groupBy(Object.keys(state.entityRegistry), (id) => state.entityRegistry[id]?.area_id ?? null));
|
|
152
164
|
/** Entity IDs grouped by device (via entity registry device_id) */
|
|
153
|
-
const byDevice =
|
|
165
|
+
const byDevice = lazyMemo(() => groupBy(Object.keys(state.entityRegistry), (id) => state.entityRegistry[id]?.device_id ?? null));
|
|
154
166
|
/** Entity IDs grouped by floor (device -> area -> floor chain) */
|
|
155
|
-
const byFloor =
|
|
167
|
+
const byFloor = lazyMemo(() => {
|
|
156
168
|
const result = {};
|
|
157
169
|
for (const [entityId, reg] of Object.entries(state.entityRegistry)) if (reg.device_id) {
|
|
158
170
|
const device = state.devices[reg.device_id];
|
|
@@ -164,13 +176,13 @@ const byFloor = createMemo(() => {
|
|
|
164
176
|
return result;
|
|
165
177
|
});
|
|
166
178
|
/** Entity IDs grouped by label */
|
|
167
|
-
const byLabel =
|
|
179
|
+
const byLabel = lazyMemo(() => {
|
|
168
180
|
const result = {};
|
|
169
181
|
for (const [entityId, reg] of Object.entries(state.entityRegistry)) for (const label of reg.labels ?? []) (result[label] ??= []).push(entityId);
|
|
170
182
|
return result;
|
|
171
183
|
});
|
|
172
184
|
/** All entity IDs currently in the store */
|
|
173
|
-
const allEntityIds =
|
|
185
|
+
const allEntityIds = lazyMemo(() => Object.keys(state.entities));
|
|
174
186
|
|
|
175
187
|
//#endregion
|
|
176
188
|
export { allEntityIds, byArea, byDevice, byDomain, byFloor, byLabel, useArea, useAreas, useCamera, useConnection, useEntities, useEntity, useEntityHistory, useEntityState, useForecast, useService, useStore, useToggle, useTurnOff, useTurnOn };
|
package/dist/solid/indices.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Reactive derived entity indices
|
|
1
|
+
/** Reactive derived entity indices — lazily created inside the caller's root. */
|
|
2
2
|
import type { Accessor } from "solid-js";
|
|
3
3
|
/** Entity IDs grouped by domain (e.g., "light" -> ["light.living_room", ...]) */
|
|
4
4
|
export declare const byDomain: Accessor<Record<string, string[]>>;
|