Skip to content

Commit

Permalink
change readonly to map
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Nov 8, 2021
1 parent 40e266c commit 34f2d40
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/watchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import { logAvgTime } from '~/helpers/profiler';
import { find } from '~/helpers/register';

export const variables = new Map<string, any>();
const readonly: {
[x: string]: any;
} = {};
export const readonly = new Map<string, any>();
let checkInProgress = false;

export const check = async (forceCheck = false) => {
Expand Down Expand Up @@ -60,7 +58,7 @@ export const startWatcher = () => {
export const VariableWatcher = {
add(key: string, value: any, isReadOnly: boolean) {
if (isReadOnly) {
readonly[key] = cloneDeep(value);
readonly.set(key, cloneDeep(value));
} else {
variables.set(key, cloneDeep(value));
}
Expand All @@ -79,7 +77,6 @@ export const VariableWatcher = {
k, variable, value,
}));
}
debug('watcher', JSON.stringify({ value, value2: variables.get(k), variable }));
if (!isEqual(value, variables.get(k))) {
const oldValue = variables.get(k);
variables.set(k, value);
Expand Down Expand Up @@ -111,7 +108,7 @@ export const VariableWatcher = {
}
}
}
for (const k of Object.keys(readonly)) {
for (const k of readonly.keys) {
const [ type, name, ...variableArr ] = k.split('.');
const variable = variableArr.join('.');
const checkedModule = find(type, name);
Expand All @@ -120,9 +117,9 @@ export const VariableWatcher = {
}
const value = cloneDeep(get(checkedModule, variable, undefined));

if (!isEqual(value, readonly[k])) {
if (!isEqual(value, readonly.get(k))) {
error(`Cannot change read-only variable, forcing initial value for ${type}.${name}.${variable}`);
set(checkedModule, variable, readonly[k]);
set(checkedModule, variable, readonly.get(k));
}
}
},
Expand Down

0 comments on commit 34f2d40

Please sign in to comment.