Skip to content

Commit

Permalink
touch up
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank1513 committed Apr 20, 2024
1 parent 722837f commit 3f4ebca
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/r18gs/src/use-rgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,32 @@ type RGS = [unknown, Listener[], SetStateAction<unknown>, Subscriber];

declare global {
// eslint-disable-next-line no-var -- var required for global declaration.
var rgs: Map<string, RGS | undefined>;
var rgs: Record<string, RGS | undefined>;
}

let g = globalThis;
g.rgs = new Map();
let globalRGS = g.rgs;
const globalThisForBetterMinification = globalThis;
globalThisForBetterMinification.rgs = {};
const globalRGS = globalThisForBetterMinification.rgs;

/** Initialize the named store when invoked for the first time. */
function init<T>(key: string, value?: T) {
const listeners: Listener[] = [];
/** setter function to set the state. */
const setter: SetStateAction<T> = val => {
const rgs = globalRGS.get(key) as RGS;
const rgs = globalRGS[key] as RGS;
rgs[VALUE] = val instanceof Function ? val(rgs[VALUE] as T) : val;

Check warning

Code scanning / CodeQL

Prototype-polluting assignment Medium

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
(rgs[LISTENERS] as Listener[]).forEach(listener => listener());
};
/** subscriber function to subscribe to the store. */
const subscriber: Subscriber = listener => {
const rgs = globalRGS.get(key) as RGS;
const rgs = globalRGS[key] as RGS;
const listeners = rgs[LISTENERS] as Listener[];
listeners.push(listener);
return () => {
rgs[LISTENERS] = listeners.filter(l => l !== listener);

Check warning

Code scanning / CodeQL

Prototype-polluting assignment Medium

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
};
};
globalRGS.set(key, [value, listeners, setter as SetStateAction<unknown>, subscriber]);
globalRGS[key] = [value, listeners, setter as SetStateAction<unknown>, subscriber];
}

/**
Expand All @@ -58,9 +58,9 @@ export default function useRGS<T>(
value?: T,
serverValue?: T,
): [T, (val: SetterArgType<T>) => void] {
if (!globalRGS.has(key)) init(key, value);
if (!globalRGS[key]) init(key, value);

const rgs = globalRGS.get(key) as RGS;
const rgs = globalRGS[key] as RGS;

/** Function to set the state. */
const setRGState = rgs[SETTER] as SetStateAction<T>;
Expand Down

0 comments on commit 3f4ebca

Please sign in to comment.