Merge pull request #1178 from GarethOates/storeCancelScope

this._changeHandlers was undefined when calling cancel()
pull/1186/head
Rich Harris 7 years ago committed by GitHub
commit fba8a9479b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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);
}
};
},
@ -163,4 +166,4 @@ assign(Store.prototype, {
}
});
export { Store };
export { Store };

@ -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({

Loading…
Cancel
Save