Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gtarpenning committed Nov 7, 2024
1 parent cbcdd33 commit 91ea1fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TraceRefsReadBatchReq,
TraceRefsReadBatchRes,
} from './traceServerClientTypes';
import { DirectTraceServerClient } from './traceServerDirectClient';
import {DirectTraceServerClient} from './traceServerDirectClient';

const DEFAULT_BATCH_INTERVAL = 150;
const MAX_REFS_PER_BATCH = 1000;
Expand All @@ -25,9 +25,9 @@ export class TraceServerClient extends DirectTraceServerClient {
}> = [];
private onDeleteListeners: Array<() => void>;
private onRenameListeners: Array<() => void>;
// weave_ref -> feedback_ref -> callback
// For feedback without a feedback_ref, (the default case)
// the key is the empty string (this.FEEDBACK_REF_DEFAULT).
// weave_ref -> feedback_type -> callback
// For feedback without a feedback_type, (the default case)
// the key is the empty string (this.FEEDBACK_TYPE_DEFAULT).
private onFeedbackListeners: Record<
string,
Record<string, Array<() => void>>
Expand All @@ -42,7 +42,7 @@ export class TraceServerClient extends DirectTraceServerClient {
this.onFeedbackListeners = {};
}

private FEEDBACK_REF_DEFAULT = '';
private FEEDBACK_TYPE_DEFAULT = '';

/**
* Registers a callback to be called when a delete operation occurs.
Expand Down Expand Up @@ -71,24 +71,24 @@ export class TraceServerClient extends DirectTraceServerClient {
public registerOnFeedbackListener(
weaveRef: string,
callback: () => void,
feedbackRef?: string
feedbackType?: string
): () => void {
const feedbackRefResolved = feedbackRef ?? this.FEEDBACK_REF_DEFAULT;
if (!(feedbackRefResolved in this.onFeedbackListeners)) {
this.onFeedbackListeners[feedbackRefResolved] = {};
const feedbackTypeResolved = feedbackType ?? this.FEEDBACK_TYPE_DEFAULT;
if (!(feedbackTypeResolved in this.onFeedbackListeners)) {
this.onFeedbackListeners[feedbackTypeResolved] = {};
}
if (!(weaveRef in this.onFeedbackListeners[feedbackRefResolved])) {
this.onFeedbackListeners[feedbackRefResolved][weaveRef] = [];
if (!(weaveRef in this.onFeedbackListeners[feedbackTypeResolved])) {
this.onFeedbackListeners[feedbackTypeResolved][weaveRef] = [];
}
this.onFeedbackListeners[feedbackRefResolved][weaveRef].push(callback);
this.onFeedbackListeners[feedbackTypeResolved][weaveRef].push(callback);
return () => {
const newListeners = this.onFeedbackListeners[feedbackRefResolved][
const newListeners = this.onFeedbackListeners[feedbackTypeResolved][
weaveRef
].filter(listener => listener !== callback);
if (newListeners.length) {
this.onFeedbackListeners[feedbackRefResolved][weaveRef] = newListeners;
this.onFeedbackListeners[feedbackTypeResolved][weaveRef] = newListeners;
} else {
delete this.onFeedbackListeners[feedbackRefResolved][weaveRef];
delete this.onFeedbackListeners[feedbackTypeResolved][weaveRef];
}
};
}
Expand All @@ -109,10 +109,10 @@ export class TraceServerClient extends DirectTraceServerClient {

public feedbackCreate(req: FeedbackCreateReq): Promise<FeedbackCreateRes> {
const res = super.feedbackCreate(req).then(createRes => {
const feedbackRefResolved =
req.annotation_ref ?? this.FEEDBACK_REF_DEFAULT;
const feedbackTypeResolved =
req.feedback_type ?? this.FEEDBACK_TYPE_DEFAULT;
const listeners =
this.onFeedbackListeners[feedbackRefResolved][req.weave_ref] ?? [];
this.onFeedbackListeners[feedbackTypeResolved][req.weave_ref] ?? [];
listeners.forEach(listener => listener());
return createRes;
});
Expand All @@ -135,10 +135,10 @@ export class TraceServerClient extends DirectTraceServerClient {

public feedbackReplace(req: FeedbackReplaceReq): Promise<FeedbackReplaceRes> {
const res = super.feedbackReplace(req).then(replaceRes => {
const feedbackRefResolved =
req.annotation_ref ?? this.FEEDBACK_REF_DEFAULT;
const feedbackTypeResolved =
req.feedback_type ?? this.FEEDBACK_TYPE_DEFAULT;
const listeners =
this.onFeedbackListeners[feedbackRefResolved][req.weave_ref] ?? [];
this.onFeedbackListeners[feedbackTypeResolved][req.weave_ref] ?? [];
listeners.forEach(listener => listener());
return replaceRes;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Query } from './traceServerClientInterface/query';
import {Query} from './traceServerClientInterface/query';
type ExtraKeysAllowed = {
[key: string]: any;
};
Expand Down

0 comments on commit 91ea1fb

Please sign in to comment.