Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ export class ListWatch<T extends KubernetesObject> implements ObjectCache<T>, In
this._stop();
}

public on(verb: 'add' | 'update' | 'delete' | 'change', cb: ObjectCallback<T>): void;
public on(verb: 'error' | 'connect', cb: ErrorCallback): void;
public on(verb: string, cb: any): void {
public on(verb: ADD | UPDATE | DELETE | CHANGE, cb: ObjectCallback<T>): void;
public on(verb: ERROR | CONNECT, cb: ErrorCallback): void;
public on(
verb: ADD | UPDATE | DELETE | CHANGE | ERROR | CONNECT,
cb: ObjectCallback<T> | ErrorCallback,
): void {
if (verb === CHANGE) {
this.on('add', cb);
this.on('update', cb);
this.on('delete', cb);
this.on(ADD, cb);
this.on(UPDATE, cb);
this.on(DELETE, cb);
return;
}
if (this.callbackCache[verb] === undefined) {
Expand Down
24 changes: 16 additions & 8 deletions src/informer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@ export type ListCallback<T extends KubernetesObject> = (list: T[], ResourceVersi
export type ListPromise<T extends KubernetesObject> = () => Promise<KubernetesListObject<T>>;

// These are issued per object
export const ADD: string = 'add';
export const UPDATE: string = 'update';
export const CHANGE: string = 'change';
export const DELETE: string = 'delete';
export const ADD = 'add';
export type ADD = typeof ADD;
export const UPDATE = 'update';
export type UPDATE = typeof UPDATE;
export const CHANGE = 'change';
export type CHANGE = typeof CHANGE;
export const DELETE = 'delete';
export type DELETE = typeof DELETE;

// This is issued when a watch connects or reconnects
export const CONNECT: string = 'connect';
export const CONNECT = 'connect';
export type CONNECT = typeof CONNECT;
// This is issued when there is an error
export const ERROR: string = 'error';
export const ERROR = 'error';
export type ERROR = typeof ERROR;

export interface Informer<T extends KubernetesObject> {
on(verb: string, fn: ObjectCallback<T>): void;
off(verb: string, fn: ObjectCallback<T>): void;
on(verb: ADD | UPDATE | DELETE | CHANGE, cb: ObjectCallback<T>): void;
on(verb: ERROR | CONNECT, cb: ErrorCallback): void;
off(verb: ADD | UPDATE | DELETE | CHANGE, cb: ObjectCallback<T>): void;
off(verb: ERROR | CONNECT, cb: ErrorCallback): void;
start(): Promise<void>;
stop(): Promise<void>;
}
Expand Down