Skip to content

Commit

Permalink
fix(fileActions): improve typing and add silent actions
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Apr 19, 2023
1 parent 2114236 commit 37a3596
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions __tests__/fileAction.spec.ts
Expand Up @@ -201,8 +201,8 @@ describe('FileActions creation', () => {
expect(action.id).toBe('test')
expect(action.displayName([], {})).toBe('Test')
expect(action.iconSvgInline([], {})).toBe('<svg></svg>')
await expect(action.exec({} as any, {})).resolves.toBe(true)
await expect(action.execBatch?.([], {})).resolves.toStrictEqual([true])
await expect(action.exec({} as any, {}, '/')).resolves.toBe(true)
await expect(action.execBatch?.([], {}, '/')).resolves.toStrictEqual([true])
expect(action.enabled?.({} as any, {})).toBe(true)
expect(action.order).toBe(100)
expect(action.default).toBe(true)
Expand Down
10 changes: 6 additions & 4 deletions lib/fileAction.ts
Expand Up @@ -34,16 +34,18 @@ interface FileActionData {
enabled?: (files: Node[], view) => boolean
/**
* Function executed on single file action
* @returns true if the action was executed, false otherwise
* @returns true if the action was executed successfully,
* false otherwise and null if the action is silent/undefined.
* @throws Error if the action failed
*/
exec: (file: Node, view) => Promise<boolean>,
exec: (file: Node, view, dir: string) => Promise<boolean|null>,
/**
* Function executed on multiple files action
* @returns true if the action was executed, false otherwise
* @returns true if the action was executed successfully,
* false otherwise and null if the action is silent/undefined.
* @throws Error if the action failed
*/
execBatch?: (files: Node[], view) => Promise<boolean[]>
execBatch?: (files: Node[], view, dir: string) => Promise<(boolean|null)[]>
/** This action order in the list */
order?: number,
/** Make this action the default */
Expand Down

0 comments on commit 37a3596

Please sign in to comment.