Skip to content

Commit 1998542

Browse files
rauno56dyladan
andauthored
feat: unify the signatures of bind and with (#2247)
Co-authored-by: Daniel Dyla <[email protected]>
1 parent 0141897 commit 1998542

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

packages/opentelemetry-context-async-hooks/src/AbstractAsyncHooksContextManager.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ export abstract class AbstractAsyncHooksContextManager
5959
*/
6060
bind<T>(context: Context, target: T): T {
6161
if (target instanceof EventEmitter) {
62-
return this._bindEventEmitter(target, context);
62+
return this._bindEventEmitter(context, target);
6363
}
6464

6565
if (typeof target === 'function') {
66-
return this._bindFunction(target, context);
66+
return this._bindFunction(context, target);
6767
}
6868
return target;
6969
}
7070

71-
private _bindFunction<T extends Function>(target: T, context: Context): T {
71+
private _bindFunction<T extends Function>(context: Context, target: T): T {
7272
const manager = this;
7373
const contextWrapper = function (this: never, ...args: unknown[]) {
7474
return manager.with(context, () => target.apply(this, args));
@@ -91,12 +91,12 @@ export abstract class AbstractAsyncHooksContextManager
9191
* By default, EventEmitter call their callback with their context, which we do
9292
* not want, instead we will bind a specific context to all callbacks that
9393
* go through it.
94-
* @param ee EventEmitter an instance of EventEmitter to patch
9594
* @param context the context we want to bind
95+
* @param ee EventEmitter an instance of EventEmitter to patch
9696
*/
9797
private _bindEventEmitter<T extends EventEmitter>(
98-
ee: T,
99-
context: Context
98+
context: Context,
99+
ee: T
100100
): T {
101101
const map = this._getPatchMap(ee);
102102
if (map !== undefined) return ee;

packages/opentelemetry-context-async-hooks/test/AsyncHooksContextManager.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ for (const contextManagerClass of [
367367
contextManager.bind(context, () => {
368368
assert.strictEqual(contextManager.active(), context);
369369
assert.strictEqual(otherContextManager.active(), otherContext);
370-
}));
370+
})
371+
);
371372
fn();
372373
});
373374
});

packages/opentelemetry-context-zone-peer-dep/src/ZoneContextManager.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ export class ZoneContextManager implements ContextManager {
5050
}
5151

5252
/**
53-
* @param target Function to be executed within the context
5453
* @param context A context (span) to be executed within target function
54+
* @param target Function to be executed within the context
5555
*/
56-
private _bindFunction<T extends Function>(target: T, context: Context): T {
56+
private _bindFunction<T extends Function>(context: Context, target: T): T {
5757
const manager = this;
5858
const contextWrapper = function (this: any, ...args: unknown[]) {
5959
return manager.with(context, () => target.apply(this, args));
@@ -68,10 +68,10 @@ export class ZoneContextManager implements ContextManager {
6868
}
6969

7070
/**
71-
* @param obj target object on which the listeners will be patched
7271
* @param context A context (span) to be bind to target
72+
* @param obj target object on which the listeners will be patched
7373
*/
74-
private _bindListener<T>(obj: T, context: Context): T {
74+
private _bindListener<T>(context: Context, obj: T): T {
7575
const target = (obj as unknown) as TargetWithEvents;
7676
if (target.__ot_listeners !== undefined) {
7777
return obj;
@@ -212,9 +212,9 @@ export class ZoneContextManager implements ContextManager {
212212
context = this.active();
213213
}
214214
if (typeof target === 'function') {
215-
return this._bindFunction(target, context);
215+
return this._bindFunction(context, target);
216216
} else if (isListenerObject(target)) {
217-
this._bindListener(target, context);
217+
this._bindListener(context, target);
218218
}
219219
return (target as unknown) as T;
220220
}

packages/opentelemetry-web/src/StackContextManager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ export class StackContextManager implements ContextManager {
3333

3434
/**
3535
*
36-
* @param target Function to be executed within the context
3736
* @param context
37+
* @param target Function to be executed within the context
3838
*/
3939
private _bindFunction<T extends Function>(
40-
target: T,
41-
context = ROOT_CONTEXT
40+
context = ROOT_CONTEXT,
41+
target: T
4242
): T {
4343
const manager = this;
4444
const contextWrapper = function (this: unknown, ...args: unknown[]) {
@@ -72,7 +72,7 @@ export class StackContextManager implements ContextManager {
7272
context = this.active();
7373
}
7474
if (typeof target === 'function') {
75-
return this._bindFunction(target, context);
75+
return this._bindFunction(context, target);
7676
}
7777
return target;
7878
}

0 commit comments

Comments
 (0)