diff --git a/src/api/context.ts b/src/api/context.ts index 34a1b806..19220f25 100644 --- a/src/api/context.ts +++ b/src/api/context.ts @@ -79,11 +79,11 @@ export class ContextAPI { /** * Bind a context to a target function or event emitter * - * @param target function or event emitter to bind * @param context context to bind to the event emitter or function. Defaults to the currently active context + * @param target function or event emitter to bind */ - public bind(target: T, context: Context = this.active()): T { - return this._getContextManager().bind(target, context); + public bind(context: Context, target: T): T { + return this._getContextManager().bind(context, target); } private _getContextManager(): ContextManager { diff --git a/src/context/NoopContextManager.ts b/src/context/NoopContextManager.ts index 54589a06..a62a89d3 100644 --- a/src/context/NoopContextManager.ts +++ b/src/context/NoopContextManager.ts @@ -31,7 +31,7 @@ export class NoopContextManager implements types.ContextManager { return fn.call(thisArg, ...args); } - bind(target: T, _context?: types.Context): T { + bind(_context: types.Context, target: T): T { return target; } diff --git a/src/context/types.ts b/src/context/types.ts index af7a1ee1..19ae6d9d 100644 --- a/src/context/types.ts +++ b/src/context/types.ts @@ -62,10 +62,10 @@ export interface ContextManager { /** * Bind an object as the current context (or a specific one) - * @param target Any object to which a context need to be set * @param [context] Optionally specify the context which you want to assign + * @param target Any object to which a context need to be set */ - bind(target: T, context?: Context): T; + bind(context: Context, target: T): T; /** * Enable context management diff --git a/test/context/NoopContextManager.test.ts b/test/context/NoopContextManager.test.ts index b5da8e6d..8a8a732b 100644 --- a/test/context/NoopContextManager.test.ts +++ b/test/context/NoopContextManager.test.ts @@ -119,13 +119,19 @@ describe('NoopContextManager', () => { describe('.bind()', () => { it('should return the same target (when enabled)', () => { const test = { a: 1 }; - assert.deepStrictEqual(contextManager.bind(test), test); + assert.deepStrictEqual( + contextManager.bind(contextManager.active(), test), + test + ); }); it('should return the same target (when disabled)', () => { contextManager.disable(); const test = { a: 1 }; - assert.deepStrictEqual(contextManager.bind(test), test); + assert.deepStrictEqual( + contextManager.bind(contextManager.active(), test), + test + ); contextManager.enable(); }); });