Skip to content

Commit

Permalink
feat(executeCommand): add setCustomExecuteCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Corentin Poupry committed Sep 18, 2018
1 parent 5b7ef96 commit b78f5cb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,19 @@ export class Dispatcher {
next()
}

/**
* Set custom executeCommand function
* @param fn custom executeCommand function
*/
public setCustomExecuteCommand(fn: IDispatcher.middleware) {
this.throwIfAlreadyStarted('cannot set custom function')
ow(fn, ow.function.label('custom executeCommand'))

this.executeCommand = fn

return this
}

/**
* Throw if dispatcher is already started
* @param msg message to throw
Expand Down
10 changes: 10 additions & 0 deletions test/functions/executeCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,13 @@ test('should verify if `.action` exist on command object', async t => {
})
)
})

test('set custom execute command function', t => {
const dispatcher = new Dispatcher()

const noop = () => {}
dispatcher.setCustomExecuteCommand(noop)

// @ts-ignore
t.is(dispatcher.executeCommand, noop)
})

0 comments on commit b78f5cb

Please sign in to comment.