Skip to content

Commit

Permalink
Added jsdoc on historysize variable
Browse files Browse the repository at this point in the history
  • Loading branch information
duart38 committed Aug 5, 2020
1 parent 81f0ede commit 7a2bee5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Observe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export default class Observe<T> {
private history: Array<T> = [];
private eventID: string;
private currentEvent: CustomEvent<T> = new CustomEvent("");
/**
* Used to control how far back you can track updates.
* Lower this value to reduce memory footprint
*/
public maxHistorySize = 1000;
private lastNestedBound: EventListener | EventListenerObject = () => {};
/**
Expand Down Expand Up @@ -68,9 +72,7 @@ export default class Observe<T> {
this.updateHistory(value);
this.emit(value);
} else if (value instanceof Observe) {
let lh = this.getHistory()[this.history.length - 1] as unknown as Observe<
any
>;
let lh = this.getHistory()[this.history.length - 1] as unknown as Observe<any>;
lh.unBind(this.lastNestedBound); // unbind the last bound to
this.lastNestedBound = value.bind((d: T) => this.emit(value)); // bind to new value and store its cb
this.updateHistory(value);
Expand All @@ -79,7 +81,7 @@ export default class Observe<T> {
}

private updateHistory(value: T) {
this.history.push(value); //
this.history.push(value);
if (this.history.length > this.maxHistorySize) {
this.history.splice(1, 1);
}
Expand Down

0 comments on commit 7a2bee5

Please sign in to comment.