Skip to content

Commit

Permalink
feat: allow registering a hook without showing deprecated message
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Sep 2, 2022
1 parent 526e4dc commit 0fcd787
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/hookable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class Hookable <
this.callHookWith = this.callHookWith.bind(this)
}

hook<NameT extends HookNameT> (name: NameT, fn: InferCallback<HooksT, NameT>) {
hook<NameT extends HookNameT> (name: NameT, fn: InferCallback<HooksT, NameT>, opts: { allowDeprecated?: boolean } = {}) {
if (!name || typeof fn !== 'function') {
return () => {}
}
Expand All @@ -40,7 +40,7 @@ export class Hookable <
dep = this._deprecatedHooks[name]
name = dep.to as NameT
}
if (dep) {
if (dep && !opts.allowDeprecated) {
let message = dep.message
if (!message) {
message = `${originalName} hook has been deprecated` +
Expand Down
7 changes: 7 additions & 0 deletions test/hookable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ describe('core: hookable', () => {
])
})

test('allow hiding deprecation warns', () => {
const hook = createHooks()
hook.deprecateHook('a', 'b')
hook.hook('a', () => {}, { allowDeprecated: true })
expect(console.warn).toBeCalledTimes(0)
})

test('should handle deprecation after registering', () => {
const hook = createHooks()
hook.hook('a', () => { })
Expand Down

0 comments on commit 0fcd787

Please sign in to comment.