plugins: lodash exposed

Massimo Melina committed Mar 18, 2023 at 16:59 UTC a12a4df899e5ca996398301552c598ab42e5f838
2 files changed +6 -4
dev-plugins.md
+4 -3
@@ -156,10 +156,11 @@ HFS.onEvent(eventName, callback)
156 Parameters of your callback and meaning of returned value varies with the event name.
157 Refer to the specific event for further information.
158 Tools are extra data and functions to help you:
159 -- `React` whole React object, as for require('react')
159 +- `React` whole React object, as for `require('react')` (JSX syntax is not supported here)
160 - `h` shortcut for React.createElement
161 -- `state` object with many values in it. [Refer here for details](https://github.com/rejetto/hfs/blob/main/frontend/src/state.ts).
162 -- `t` translator function
161 +- `state` [object with many values in it](https://github.com/rejetto/hfs/blob/main/frontend/src/state.ts)
162 +- `t` [translator function](https://github.com/rejetto/hfs/blob/main/frontend/src/i18n.ts)
163 +- `_` [lodash library](https://lodash.com/docs/)
164
165 Some frontend-events can return Html, which can be expressed in several ways
166 - as string, containing markup
frontend/src/misc.ts
+2 -1
@@ -7,6 +7,7 @@ import { Icon } from './icons'
7 import { Dict } from '@hfs/shared'
8 import { state } from './state'
9 import { t } from './i18n'
10 +import _ from 'lodash'
11 export * from '@hfs/shared'
12
13 export const ERRORS: Record<number, string> = {
@@ -58,7 +59,7 @@ export function hfsEvent(name: string, params?:Dict) {
59
60 Object.assign((window as any).HFS ||= {}, {
61 onEvent(name: string, cb: (params:any, tools: any, output:any) => any) {
61 - const tools = { h, React, state, t }
62 + const tools = { h, React, state, t, _ }
63 document.addEventListener('hfs.' + name, ev => {
64 const { params, output } = (ev as CustomEvent).detail
65 const res = cb(params, tools, output)