Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this._changeHandlers was undefined when calling cancel() #1178

Merged
merged 3 commits into from
Feb 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions store.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,13 @@ assign(Store.prototype, {

onchange: function(callback) {
this._changeHandlers.push(callback);

var store = this;

return {
cancel: function() {
var index = this._changeHandlers.indexOf(callback);
if (~index) this._changeHandlers.splice(index, 1);
var index = store._changeHandlers.indexOf(callback);
if (~index) store._changeHandlers.splice(index, 1);
}
};
},
Expand Down Expand Up @@ -163,4 +166,4 @@ assign(Store.prototype, {
}
});

export { Store };
export { Store };
9 changes: 9 additions & 0 deletions test/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ describe('store', () => {
});
});

it('allows user to cancel state change callback', () => {
const store = new Store();
const handler = store.onchange(() => {});

assert.doesNotThrow(() => {
handler.cancel();
}, TypeError, 'this._changeHandlers is undefined');
});

describe('computed', () => {
it('computes a property based on data', () => {
const store = new Store({
Expand Down