Skip to content

Commit

Permalink
cleanup and refactor to follow code conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
limemloh committed Sep 4, 2019
1 parent 3a3cfd0 commit f22b3af
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
19 changes: 8 additions & 11 deletions src/behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,22 @@ export abstract class Behavior<A> extends Reactive<A, BListener>
}
abstract update(t: number): A;
pushB(t: number): void {
if (this.changedAt === t) {
// This prevents a second push with same timestamp, to be further pushed
return;
}
this.pull(t);
if (this.changedAt === t && this.state === State.Push) {
pushToChildren(t, this);
if (this.pulledAt !== t) {
this.pull(t);
if (this.changedAt === t && this.state === State.Push) {
pushToChildren(t, this);
}
}
}
pull(t: number): void {
if (this.pulledAt === undefined || this.pulledAt < t) {
this.pulledAt = t;
let shouldRefresh = this.changedAt === undefined;
for (const parent of this.parents) {
if (!isBehavior(parent)) {
continue;
if (isBehavior(parent)) {
parent.pull(t);
shouldRefresh = shouldRefresh || this.changedAt < parent.changedAt;
}
parent.pull(t);
shouldRefresh = shouldRefresh || this.changedAt < parent.changedAt;
}
if (shouldRefresh) {
refresh(this, t);
Expand Down
8 changes: 2 additions & 6 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ export class PushOnlyObserver<A> implements BListener, SListener<A> {
}
}
pushB(t: number): void {
const b = <Behavior<A>>this.source;
b.pull(t);
this.callback(b.last);
this.callback((<Behavior<A>>this.source).last);
}
pushS(t: number, value: A): void {
this.callback(value);
Expand Down Expand Up @@ -147,9 +145,7 @@ export class CbObserver<A> implements BListener, SListener<A> {
}
}
pushB(t: number): void {
const b = <Behavior<A>>this.source;
b.pull(t);
this.callback(b.last);
this.callback((<Behavior<A>>this.source).last);
}
pushS(t: number, value: A): void {
this.callback(value);
Expand Down
1 change: 0 additions & 1 deletion src/placeholder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class Placeholder<A> extends Behavior<A> {
if (this.source !== undefined) {
this.source.addListener(this.node, t);
if (isBehavior(this.source)) {
this.pull(t);
this.last = this.source.last;
this.changedAt = this.source.changedAt;
this.pulledAt = this.source.pulledAt;
Expand Down

0 comments on commit f22b3af

Please sign in to comment.