Skip to content

Commit

Permalink
refactor(bindings): use ??= instead
Browse files Browse the repository at this point in the history
  • Loading branch information
bigopon committed Nov 26, 2020
1 parent 842ab26 commit 830fdf5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
5 changes: 2 additions & 3 deletions packages/runtime-html/src/binding/attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ export class AttributeBinding implements IPartialConnectableBinding {
if (newValue !== this.value) {
this.value = newValue;
if (shouldQueueFlush) {
this.task?.cancel();
this.task = this.$platform.domWriteQueue.queueTask(() => {
this.task ??= this.$platform.domWriteQueue.queueTask(() => {
if (this.isBound) {
interceptor.updateTarget(newValue, flags);
interceptor.updateTarget(this.value, flags);
}
this.task = null;
}, taskOptions);
Expand Down
10 changes: 4 additions & 6 deletions packages/runtime/src/binding/interpolation-binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,10 @@ export class InterpolationBinding implements IBinding {
if (shouldQueueFlush) {
// an optimization: only create & queue a task when there's NOT already a task queued
// inside the lambda, use this.value instead of result, since it would always be the latest value
if (this.task == null) {
this.task = this.taskQueue.queueTask(() => {
targetObserver.setValue(this.value, flags, this.target, this.targetProperty);
this.task = null;
}, queueTaskOptions);
}
this.task ??= this.taskQueue.queueTask(() => {
targetObserver.setValue(this.value, flags, this.target, this.targetProperty);
this.task = null;
}, queueTaskOptions);
} else {
targetObserver.setValue(result, flags, this.target, this.targetProperty);
}
Expand Down
14 changes: 6 additions & 8 deletions packages/runtime/src/binding/property-binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,12 @@ export class PropertyBinding implements IPartialConnectableBinding {
if (shouldQueueFlush) {
// an optimization: only create & queue a task when there's NOT already a task queued
// inside the lambda, use this.value instead of result, since it would always be the latest value
if (this.task == null) {
this.task = this.taskQueue.queueTask(() => {
if (this.isBound) {
interceptor.updateTarget(this.value, flags);
}
this.task = null;
}, updateTaskOpts);
}
this.task ??= this.taskQueue.queueTask(() => {
if (this.isBound) {
interceptor.updateTarget(this.value, flags);
}
this.task = null;
}, updateTaskOpts);
} else {
interceptor.updateTarget(newValue, flags);
}
Expand Down

0 comments on commit 830fdf5

Please sign in to comment.