Skip to content

Commit

Permalink
clear nextTick once it triggered - #712
Browse files Browse the repository at this point in the history
  • Loading branch information
Gcaufy committed Jan 2, 2018
1 parent 5c9f6b2 commit 1211b1e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/wepy/src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,23 +561,25 @@ export default class {
if (Object.keys(readyToSet).length) {
this.setData(readyToSet, () => {
if (this.$$nextTick) {
if (this.$$nextTick.promise) {
this.$$nextTick();
let $$nextTick = this.$$nextTick;
this.$$nextTick = null;
if ($$nextTick.promise) {
$$nextTick();
} else {
this.$$nextTick.call(this);
$$nextTick.call(this);
}
}
this.$$nextTick = null;
});
} else {
if (this.$$nextTick) {
if (this.$$nextTick.promise) {
this.$$nextTick();
let $$nextTick = this.$$nextTick;
this.$$nextTick = null;
if ($$nextTick.promise) {
$$nextTick();
} else {
this.$$nextTick.call(this);
$$nextTick.call(this);
}
}
this.$$nextTick = null;
}
this.$$phase = (this.$$phase === '$apply') ? '$digest' : false;
}
Expand Down
17 changes: 17 additions & 0 deletions packages/wepy/test/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,23 @@ describe('component.js', () => {
});


it('$nextTick do apply', function (done) {
//this.timeout(1500);
com.a = +new Date();
com.$nextTick(function () {
assert.strictEqual(this, com, 'setData callback use this');
com.a = +new Date();
com.$apply();
com.$nextTick(function () {
assert.strictEqual(this, com, 'setData callback use this');
com.a = +new Date();
com.$apply();
done();
});
});
com.$apply();
});

it('computed test', () => {
com.num = 11;
com.$apply();
Expand Down

0 comments on commit 1211b1e

Please sign in to comment.