mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 03:36:01 +00:00
command enabling refactor
This commit is contained in:
30
packages/web/src/commands/invalidateCommands.ts
Normal file
30
packages/web/src/commands/invalidateCommands.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { tick } from 'svelte';
|
||||
import { commands } from '../stores';
|
||||
|
||||
let isInvalidated = false;
|
||||
|
||||
export default async function invalidateCommands() {
|
||||
if (isInvalidated) return;
|
||||
isInvalidated = true;
|
||||
await tick();
|
||||
|
||||
isInvalidated = false;
|
||||
|
||||
commands.update(dct => {
|
||||
let res = null;
|
||||
for (const key of Object.keys(dct)) {
|
||||
const command = dct[key];
|
||||
const { testEnabled } = command;
|
||||
let enabled = command.enabled;
|
||||
if (testEnabled) enabled = testEnabled();
|
||||
if (enabled != command.enabled) {
|
||||
if (!res) res = { ...dct };
|
||||
res[key] = {
|
||||
...command,
|
||||
enabled,
|
||||
};
|
||||
}
|
||||
}
|
||||
return res || dct;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user