plugins: api.subscribeConfig supports multiple keys
Massimo Melina committed
Feb 5, 2025 at 23:54 UTC
7a35db8ac62f908be99aa14211a203e6a378d409
3 files changed
+12
-7
dev-plugins.md
+5
-2
@@ -173,6 +173,7 @@ A FieldDescriptor is an object and can be empty. Currently, these optional prope
173
Based on `type`, other properties are supported:
174
- `string`
175
- `multiline: boolean`. Default is `false`.
176
+ - to make it a password field, use this property `inputProps: { type: 'password' }`; valid also for other standard html input types.
177
- `number`
178
- `min: number`
179
- `max: number`
@@ -210,8 +211,9 @@ The `api` object you get as parameter of the `init` contains the following:
211
212
- `setConfig(key: string, value: any)` set plugin's config value.
213
213
-- `subscribeConfig(key: string, callback: (value: any) => void): Unsubscriber`
214
+- `subscribeConfig(key: string | string[], callback: (value: any) => void): Unsubscriber`
215
will call `callback` with initial value and then at each change.
216
+ Passing an array of keys, the `value` parameter becomes an object with the specified keys and respective values.
217
218
- `getHfsConfig(key: string): any` similar to getConfig, but retrieves HFS' config instead.
219
@@ -733,10 +735,11 @@ If you want to override a text regardless of the language, use the special langu
735
736
## API version history
737
736
-- 11.2 (v0.56.0)
738
+- 11.3 (v0.56.0)
739
- api.setError
740
- frontend events: afterBreadcrumbs, afterFolderStats, afterFilter
741
- config.type.vfs_path: folders, files
742
+ - api.subscribeConfig supports multiple keys
743
- 10.3 (v0.55.0)
744
- HFS.copyTextToClipboard
745
- HFS.urlParams
src/const.ts
+1
-1
@@ -9,7 +9,7 @@ import { formatTimestamp } from './cross'
9
import { argv } from './argv'
10
export * from './cross-const'
11
12
-export const API_VERSION = 11.2
12
+export const API_VERSION = 11.3
13
export const COMPATIBLE_API_VERSION = 1 // while changes in the api are not breaking, this number stays the same, otherwise it is made equal to API_VERSION
14
15
// you can add arguments with this file, currently used for the update process on mac/linux
src/plugins.ts
+6
-4
@@ -10,7 +10,7 @@ import * as Const from './const'
10
import Koa from 'koa'
11
import {
12
adjustStaticPathForGlob, callable, Callback, CFG, debounceAsync, Dict, getOrSet, objSameKeys, onlyTruthy,
13
- PendingPromise, pendingPromise, Promisable, same, tryJson, wait, waitFor, wantArray, watchDir
13
+ PendingPromise, pendingPromise, Promisable, same, tryJson, wait, waitFor, wantArray, watchDir, objFromKeys
14
} from './misc'
15
import * as misc from './misc'
16
import { defineConfig, getConfig } from './config'
@@ -495,11 +495,13 @@ function watchPlugin(id: string, path: string) {
495
},
496
setConfig: (cfgKey: string, value: any) =>
497
setPluginConfig(id, { [cfgKey]: value }),
498
- subscribeConfig(cfgKey: string, cb: Callback<any>) {
499
- let last = this.getConfig(cfgKey)
498
+ subscribeConfig(cfgKey: string | string[], cb: Callback<any>) {
499
+ const get = () => Array.isArray(cfgKey) ? objFromKeys(cfgKey, k => this.getConfig(k))
500
+ : this.getConfig(cfgKey)
501
+ let last = get()
502
cb(last)
503
return pluginsConfig.sub(() => {
502
- const now = this.getConfig(cfgKey)
504
+ const now = get()
505
if (same(now, last)) return
506
try { cb(last = now) }
507
catch(e){ this.log(String(e)) }