From 8b0c52a4a68d70b9165ac4c33df65e6936249f69 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 20 Jul 2023 12:42:38 -0400 Subject: [PATCH] refactor: on setAuthStatus, conditionally get a diff of the object changed, and emit it on authStatus event --- src/vars.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/vars.ts b/src/vars.ts index 3df5d2e..28cb434 100644 --- a/src/vars.ts +++ b/src/vars.ts @@ -1,6 +1,8 @@ import type { KernelAuthStatus } from "@lumeweb/libweb"; import defer, { DeferredPromise } from "p-defer"; import Emittery from "emittery"; +import objectDiff from "object-diff"; + let queriesNonce = 1; let queries: any = {}; let portsNonce = 0; @@ -27,7 +29,15 @@ export function getAuthStatus(): KernelAuthStatus { } export function setAuthStatus(status: KernelAuthStatus) { + let diff; + if (!authStatus) { + diff = status; + } else { + diff = objectDiff(authStatus, status); + } + authStatus = status; + events.emit("authStatus", diff); } export function getQueriesNonce(): number {