From f22b3af8a36f14098d7fb89df5a81b063226b812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gj=C3=B8rup?= Date: Wed, 4 Sep 2019 16:43:36 +0200 Subject: [PATCH] cleanup and refactor to follow code conventions --- src/behavior.ts | 19 ++++++++----------- src/common.ts | 8 ++------ src/placeholder.ts | 1 - 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/behavior.ts b/src/behavior.ts index e812664..f1f561b 100644 --- a/src/behavior.ts +++ b/src/behavior.ts @@ -69,13 +69,11 @@ export abstract class Behavior extends Reactive } 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 { @@ -83,11 +81,10 @@ export abstract class Behavior extends Reactive 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); diff --git a/src/common.ts b/src/common.ts index 7e5afb8..f6eb7eb 100644 --- a/src/common.ts +++ b/src/common.ts @@ -49,9 +49,7 @@ export class PushOnlyObserver implements BListener, SListener { } } pushB(t: number): void { - const b = >this.source; - b.pull(t); - this.callback(b.last); + this.callback((>this.source).last); } pushS(t: number, value: A): void { this.callback(value); @@ -147,9 +145,7 @@ export class CbObserver implements BListener, SListener { } } pushB(t: number): void { - const b = >this.source; - b.pull(t); - this.callback(b.last); + this.callback((>this.source).last); } pushS(t: number, value: A): void { this.callback(value); diff --git a/src/placeholder.ts b/src/placeholder.ts index 89caed9..c511278 100644 --- a/src/placeholder.ts +++ b/src/placeholder.ts @@ -54,7 +54,6 @@ export class Placeholder extends Behavior { 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;