better code
Massimo Melina committed
Apr 23, 2025 at 17:37 UTC
643f1499be090f220fc6b97a172a081cb85c92b1
3 files changed
+138
-132
dev-plugins.md
+131
-131
@@ -218,10 +218,10 @@ Based on `type`, other properties are supported:
218
- `username`
219
- `groups: undefined | boolean` true if you want only groups, false if you want only users. Default is undefined.
220
- `multiple: boolean` if you set this to true, the field will allow the selection of multiple accounts,
221
- and the resulting value will be array of strings, instead of a string. Default is false.
222
-- `date_time`
223
-- `net_mask`
224
-- `showHtml`
221
+ and the resulting value will be an array of strings, instead of a string. Default is false.
222
+- `date_time` a string in the form yyyy-mm-ddThh:mm:ss.cccZ
223
+- `net_mask` a string
224
+- `showHtml` not a real field, but let you display some static content
225
- `html: string` HTML code to display.
226
227
## api object
@@ -836,131 +836,131 @@ If you want to override a text regardless of the language, use the special langu
836
837
## API version history
838
839
-- 12.2 (v0.57.0)
840
- - backend event: finalizingLogin, httpsServerOptions, clearTextLogin
841
- - frontend events: beforeLoginSubmit, loginUsernameField, loginPasswordField
842
- - exports.changelog
843
- - automatic unload of api.events listeners
844
- - removed DirEntry.t
845
- - api.setInterval, setTimeout
846
- - HFS.Btn
847
- - HFS.watchState added third parameter
848
- - frontend events: async for fileMenu and html-producers
849
- - config.type: date_time, net_mask
850
- - config.getError
851
-- 11.6 (v0.56.0)
852
- - api.setError
853
- - frontend events: afterBreadcrumbs, afterFolderStats, afterFilter
854
- - config.type.vfs_path: folders, files
855
- - api.subscribeConfig supports multiple keys
856
- - api.getAccount, addAccount, delAccount, updateAccount, renameAccount, getUsernames
857
- - automatic unload of api.subscribeConfig
858
- - api._
859
- - config.type=showHtml
860
-- 10.3 (v0.55.0)
861
- - HFS.copyTextToClipboard
862
- - HFS.urlParams
863
- - exports.beforePlugin + afterPlugin
864
- - config.type: color
865
- - config.showIf
866
- - init can now return directly the unload function
867
- - api.i18n
868
- - frontend event: newListEntries
869
- - HFS.fileShowComponents
870
- - api.ctxBelongsTo
871
- - api.getCurrentUsername
872
-- 9.6 (v0.54.0)
873
- - frontend event: showPlay
874
- - api.addBlock
875
- - api.misc
876
- - frontend event: paste
877
- - exports.customRest + HFS.customRestCall
878
- - config.type: vfs_path
879
- - frontend event: sortCompare
880
- - HFS.userBelongsTo
881
- - HFS.DirEntry
882
- - frontend event: appendMenuBar
883
- - config.helperText: basic md formatting
884
- - HFS.onEvent.setOrder
885
- - backend event: newSocket
886
-- 8.891 (v0.53.0)
887
- - api.openDb
888
- - frontend event: menuZip
889
- - config.type:username
890
- - api.events class has changed
891
- - frontend event "fileMenu": changed props format
892
- - api.getConfig() without parameters
893
- - api.notifyClient + HFS.getNotifications
894
- - HFS.html
895
- - HFS.useSnapState
896
- - HFS.debounceAsync
897
- - HFS.loadScript
898
- - HFS.iconBtn
899
- - middleware: ctx.stop()
900
- - the old way of returning true is now deprecated
901
- - exports.customHtml
902
- - more functions in HFS.misc
903
- - frontend event 'entry' can now ask to skip an entry
904
- - backend events: login attemptingLogin failedLogin
905
-- 8.72 (v0.52.0)
906
- - HFS.toast
907
- - HFS.misc functions
908
- - HFS.state.uri
909
- - ~~frontend event: uriChanged~~
910
-- 8.65 (v0.51.0)
911
- - plugin's own hfs-lang files
912
- - HFS.state.props.can_overwrite
913
- - ctx.state.considerAsGui
914
- - frontend event: userPanelAfterInfo
915
- - breaking: moved custom properties from ctx to ctx.state
916
- - HFS.navigate
917
- - internationalization
918
-- 8.5 (v0.49.0)
919
- - frontend event: entry
920
- - exports.onDirEntry: entry.icon
921
- - customApiCall supports any number of parameters
922
-- 8.4 (v0.48.2)
923
- - HFS.fileShow
924
- - api.Const (api.const is now deprecated)
925
-- 8.3 (v0.47.0)
926
- - HFS.useBatch
927
- - FileMenuEntry.id, .subLabel
928
-- 8.23 (v0.46.0)
929
- - entry.getNext, getPrevious, getNextFiltered, getPreviousFiltered, getDefaultIcon
930
- - platform-dependent distribution
931
- - HFS.watchState, emit, useApi
932
- - api.storageDir, customApiCall
933
- - exports.depend
934
- - frontend event: fileShow
935
-- 8.1 (v0.45.0) should have been 0.44.0 but forgot to update number
936
- - full URL support for frontend_js and frontend_css
937
- - custom.html
938
- - entry.cantOpen, ext, isFolder
939
- - HFS.apiCall, reloadList, logout, h, React, state, t, _, dialogLib, Icon, getPluginPublic
940
- - second parameter of onEvent is now deprecated
941
- - renamed: additionalEntryProps > additionalEntryDetails & entry-props > entry-details
942
- - frontend event: entryIcon
943
-- 8 (v0.43.0)
944
- - entry.name & .uri
945
- - tools.dialogLib
946
- - HFS.getPluginConfig()
947
-- 7 (v0.42.0)
948
- - frontend event: fileMenu
949
- - HFS.SPECIAL_URI, PLUGINS_PUB_URI, FRONTEND_URI,
950
-- 6 (v0.38.0)
951
- - config.frontend
952
-- 5 (v0.33.0)
953
- - frontend event: afterEntryName
954
-- 4.1 (v0.23.4)
955
- - config.type:array added $width, $column and fixed height
956
-- 4 (v0.23.0)
957
- - config.type:real_path
958
- - api.subscribeConfig
959
- - api.setConfig
960
- - api.getHfsConfig
961
-- 3 (v0.21.0)
962
- - config.defaultValue
963
- - async for init/unload
964
- - api.log
839
- 2
966
- - config.type:array
840
+ - config.type:array
841
+- 3 (v0.21.0)
842
+ - config.defaultValue
843
+ - async for init/unload
844
+ - api.log
845
+- 4 (v0.23.0)
846
+ - config.type:real_path
847
+ - api.subscribeConfig
848
+ - api.setConfig
849
+ - api.getHfsConfig
850
+- 4.1 (v0.23.4)
851
+ - config.type:array added $width, $column and fixed height
852
+- 5 (v0.33.0)
853
+ - frontend event: afterEntryName
854
+- 6 (v0.38.0)
855
+ - config.frontend
856
+- 7 (v0.42.0)
857
+ - frontend event: fileMenu
858
+ - HFS.SPECIAL_URI, PLUGINS_PUB_URI, FRONTEND_URI,
859
+- 8 (v0.43.0)
860
+ - entry.name & .uri
861
+ - tools.dialogLib
862
+ - HFS.getPluginConfig()
863
+- 8.1 (v0.45.0) should have been 0.44.0 but forgot to update number
864
+ - full URL support for frontend_js and frontend_css
865
+ - custom.html
866
+ - entry.cantOpen, ext, isFolder
867
+ - HFS.apiCall, reloadList, logout, h, React, state, t, _, dialogLib, Icon, getPluginPublic
868
+ - second parameter of onEvent is now deprecated
869
+ - renamed: additionalEntryProps > additionalEntryDetails & entry-props > entry-details
870
+ - frontend event: entryIcon
871
+- 8.23 (v0.46.0)
872
+ - entry.getNext, getPrevious, getNextFiltered, getPreviousFiltered, getDefaultIcon
873
+ - platform-dependent distribution
874
+ - HFS.watchState, emit, useApi
875
+ - api.storageDir, customApiCall
876
+ - exports.depend
877
+ - frontend event: fileShow
878
+- 8.3 (v0.47.0)
879
+ - HFS.useBatch
880
+ - FileMenuEntry.id, .subLabel
881
+- 8.4 (v0.48.2)
882
+ - HFS.fileShow
883
+ - api.Const (api.const is now deprecated)
884
+- 8.5 (v0.49.0)
885
+ - frontend event: entry
886
+ - exports.onDirEntry: entry.icon
887
+ - customApiCall supports any number of parameters
888
+- 8.65 (v0.51.0)
889
+ - plugin's own hfs-lang files
890
+ - HFS.state.props.can_overwrite
891
+ - ctx.state.considerAsGui
892
+ - frontend event: userPanelAfterInfo
893
+ - breaking: moved custom properties from ctx to ctx.state
894
+ - HFS.navigate
895
+ - internationalization
896
+- 8.72 (v0.52.0)
897
+ - HFS.toast
898
+ - HFS.misc functions
899
+ - HFS.state.uri
900
+ - ~~frontend event: uriChanged~~
901
+- 8.891 (v0.53.0)
902
+ - api.openDb
903
+ - frontend event: menuZip
904
+ - config.type:username
905
+ - api.events class has changed
906
+ - frontend event "fileMenu": changed props format
907
+ - api.getConfig() without parameters
908
+ - api.notifyClient + HFS.getNotifications
909
+ - HFS.html
910
+ - HFS.useSnapState
911
+ - HFS.debounceAsync
912
+ - HFS.loadScript
913
+ - HFS.iconBtn
914
+ - middleware: ctx.stop()
915
+ - the old way of returning true is now deprecated
916
+ - exports.customHtml
917
+ - more functions in HFS.misc
918
+ - frontend event 'entry' can now ask to skip an entry
919
+ - backend events: login attemptingLogin failedLogin
920
+- 9.6 (v0.54.0)
921
+ - frontend event: showPlay
922
+ - api.addBlock
923
+ - api.misc
924
+ - frontend event: paste
925
+ - exports.customRest + HFS.customRestCall
926
+ - config.type: vfs_path
927
+ - frontend event: sortCompare
928
+ - HFS.userBelongsTo
929
+ - HFS.DirEntry
930
+ - frontend event: appendMenuBar
931
+ - config.helperText: basic md formatting
932
+ - HFS.onEvent.setOrder
933
+ - backend event: newSocket
934
+- 10.3 (v0.55.0)
935
+ - HFS.copyTextToClipboard
936
+ - HFS.urlParams
937
+ - exports.beforePlugin + afterPlugin
938
+ - config.type: color
939
+ - config.showIf
940
+ - init can now return directly the unload function
941
+ - api.i18n
942
+ - frontend event: newListEntries
943
+ - HFS.fileShowComponents
944
+ - api.ctxBelongsTo
945
+ - api.getCurrentUsername
946
+- 11.6 (v0.56.0)
947
+ - api.setError
948
+ - frontend events: afterBreadcrumbs, afterFolderStats, afterFilter
949
+ - config.type.vfs_path: folders, files
950
+ - api.subscribeConfig supports multiple keys
951
+ - api.getAccount, addAccount, delAccount, updateAccount, renameAccount, getUsernames
952
+ - automatic unload of api.subscribeConfig
953
+ - api._
954
+ - config.type=showHtml
955
+- 12.2 (v0.57.0)
956
+ - backend event: finalizingLogin, httpsServerOptions, clearTextLogin
957
+ - frontend events: beforeLoginSubmit, loginUsernameField, loginPasswordField
958
+ - exports.changelog
959
+ - automatic unload of api.events listeners
960
+ - removed DirEntry.t
961
+ - api.setInterval, setTimeout
962
+ - HFS.Btn
963
+ - HFS.watchState added third parameter
964
+ - frontend events: async for fileMenu and html-producers
965
+ - config.type: date_time, net_mask
966
+ - config.getError
\ No newline at end of file
dev.md
+2
@@ -61,6 +61,8 @@ Additionally, you have the following folders:
61
- All parameters that contain a *uri* should have a name that starts with `uri`.
62
- React parts don't use JSX. I used JSX for a couple of years before deciding that it is not good enough to pay the
63
price of using an extra language that is also necessary to switched in and out multiple times when stuff is nested.
64
+- All calls to async functions that don't want/need to "await" should be using the "void" operator to clarify it's
65
+ intentional and not that you just forgot to await. Don't confuse the void operator with the void type.
66
67
# Project design
68
src/cross.ts
+5
-1
@@ -359,11 +359,15 @@ export async function asyncGeneratorToArray<T>(generator: AsyncIterable<T>): Pro
359
return ret
360
}
361
362
+// like setInterval but: async executions don't overlap AND the first execution is immediate
363
export function repeat(everyMs: number, cb: Callback<Callback>): Callback {
364
let stop = false
365
;(async () => {
365
- while (!stop && await Promise.allSettled([cb(stopIt)]))
366
+ while (!stop) {
367
+ try { await cb(stopIt) } // you can use stopIt passed as a parameter or the returned value, whatever makes you happy
368
+ catch {}
369
await wait(everyMs)
370
+ }
371
})()
372
return stopIt
373
function stopIt() {