Skip to content

Commit

Permalink
fix(engine): PR 1038 feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
caridy committed Feb 13, 2019
1 parent 92ba93c commit 793e88c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
1 change: 0 additions & 1 deletion packages/@lwc/engine/src/framework/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export function linkComponent(vm: VM) {

function getObservingTemplateRecord(vm: VM): ObservingRecord {
return {
vm,
listeners: [],
notify() {
if (process.env.NODE_ENV !== 'production') {
Expand Down
21 changes: 11 additions & 10 deletions packages/@lwc/engine/src/framework/decorators/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,25 +104,26 @@ function createPublicPropertyDescriptor(proto: ComponentConstructor, key: Proper
}

interface ObservingAccessorRecord extends ObservingRecord {
value?: any;
debounced: boolean;
value: any;
debouncing: boolean;
}

function getObservingAccessorRecord(vm: VM, set: (v: any) => void): ObservingAccessorRecord {
return {
vm,
value: undefined,
listeners: [],
notify(this: ObservingAccessorRecord) {
if (isFalse(this.debounced)) {
this.debounced = true;
if (isFalse(this.debouncing)) {
this.debouncing = true;
addCallbackToNextTick(() => {
if (isTrue(this.debounced)) {
if (isTrue(this.debouncing)) {
const { isDirty: dirtyStateBeforeSetterCall } = vm;
set.call(vm.component, this.value);
// debouncing after the call to the original setter to prevent
// de-bouncing after the call to the original setter to prevent
// infinity loop if the setter itself is mutating things that
// were accessed during the previous invocation.
this.debounced = false;
this.debouncing = false;
if (isTrue(vm.isDirty) && isFalse(dirtyStateBeforeSetterCall) && vm.idx > 0) {
// immediate rehydration due to a setter driven mutation, otherwise
// the component will get rendered on the second tick, which it is not
Expand All @@ -133,7 +134,7 @@ function getObservingAccessorRecord(vm: VM, set: (v: any) => void): ObservingAcc
});
}
},
debounced: false,
debouncing: false,
} as ObservingAccessorRecord;
}

Expand Down Expand Up @@ -191,11 +192,11 @@ function createPublicAccessorDescriptor(Ctor: ComponentConstructor, key: Propert
}
setCurrentObservingRecord(oRecord);
// every time we invoke this setter from outside (thru this wrapper setter)
// we should reset the value and the debounced just in case there is a pending
// we should reset the value and then debounce just in case there is a pending
// invocation the next tick that is not longer relevant since the value is changing
// from outside.
(oRecord as ObservingAccessorRecord).value = v;
(oRecord as ObservingAccessorRecord).debounced = false;
(oRecord as ObservingAccessorRecord).debouncing = false;
try {
set.call(this, v);
} catch (e) {
Expand Down
5 changes: 1 addition & 4 deletions packages/@lwc/engine/src/framework/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ const TargetToReactiveRecordMap: WeakMap<object, ReactiveRecord> = new WeakMap()
* - Accessor Invocation Phase
*/
export interface ObservingRecord {
readonly vm: VM;
readonly listeners: ObservedMemberPropertyRecords[];
notify(): void;
}

/**
* An Observed Membre Property Record represents the list of all Observing Records,
* An Observed MemberProperty Record represents the list of all Observing Records,
* if any, where the member property of an observable membrane proxy was accessed,
* while an Observing Record was active.
*/
Expand Down Expand Up @@ -105,5 +104,3 @@ export function resetObservingRecord(oRecord: ObservingRecord) {
listeners.length = 0;
}
}

import { VM } from "./vm";

0 comments on commit 793e88c

Please sign in to comment.