Skip to content
This repository was archived by the owner on Nov 10, 2022. It is now read-only.

Commit c31b6c2

Browse files
committed
feat: update tests and NoopContextManager
Leave checking special cases for the actual ContextManager and remove the short-circuit from the API implementation.
1 parent 4e2d434 commit c31b6c2

File tree

4 files changed

+5
-8
lines changed

4 files changed

+5
-8
lines changed

src/api/context.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ export class ContextAPI {
8383
* @param target function or event emitter to bind
8484
*/
8585
public bind<T>(context: Context, target: T): T {
86-
if (context === undefined) {
87-
return target;
88-
}
89-
return this._getContextManager().bind(target, context);
86+
return this._getContextManager().bind(context, target);
9087
}
9188

9289
private _getContextManager(): ContextManager {

src/context/NoopContextManager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class NoopContextManager implements types.ContextManager {
3131
return fn.call(thisArg, ...args);
3232
}
3333

34-
bind<T>(target: T, _context?: types.Context): T {
34+
bind<T>(_context: types.Context, target: T): T {
3535
return target;
3636
}
3737

src/context/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export interface ContextManager {
6565
* @param target Any object to which a context need to be set
6666
* @param [context] Optionally specify the context which you want to assign
6767
*/
68-
bind<T>(target: T, context?: Context): T;
68+
bind<T>(context: Context, target: T): T;
6969

7070
/**
7171
* Enable context management

test/context/NoopContextManager.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ describe('NoopContextManager', () => {
119119
describe('.bind()', () => {
120120
it('should return the same target (when enabled)', () => {
121121
const test = { a: 1 };
122-
assert.deepStrictEqual(contextManager.bind(test), test);
122+
assert.deepStrictEqual(contextManager.bind(contextManager.active(), test), test);
123123
});
124124

125125
it('should return the same target (when disabled)', () => {
126126
contextManager.disable();
127127
const test = { a: 1 };
128-
assert.deepStrictEqual(contextManager.bind(test), test);
128+
assert.deepStrictEqual(contextManager.bind(contextManager.active(), test), test);
129129
contextManager.enable();
130130
});
131131
});

0 commit comments

Comments
 (0)