refactor: on setAuthStatus, conditionally get a diff of the object changed, and emit it on authStatus event

This commit is contained in:
Derrick Hammer 2023-07-20 12:42:38 -04:00
parent 7e60bea57c
commit 8b0c52a4a6
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 10 additions and 0 deletions

View File

@ -1,6 +1,8 @@
import type { KernelAuthStatus } from "@lumeweb/libweb"; import type { KernelAuthStatus } from "@lumeweb/libweb";
import defer, { DeferredPromise } from "p-defer"; import defer, { DeferredPromise } from "p-defer";
import Emittery from "emittery"; import Emittery from "emittery";
import objectDiff from "object-diff";
let queriesNonce = 1; let queriesNonce = 1;
let queries: any = {}; let queries: any = {};
let portsNonce = 0; let portsNonce = 0;
@ -27,7 +29,15 @@ export function getAuthStatus(): KernelAuthStatus {
} }
export function setAuthStatus(status: KernelAuthStatus) { export function setAuthStatus(status: KernelAuthStatus) {
let diff;
if (!authStatus) {
diff = status;
} else {
diff = objectDiff(authStatus, status);
}
authStatus = status; authStatus = status;
events.emit("authStatus", diff);
} }
export function getQueriesNonce(): number { export function getQueriesNonce(): number {