Skip to content

Commit

Permalink
Fixes unsubscribe on multiple subscribers after destroy (#32)
Browse files Browse the repository at this point in the history
* Fixes unsubscribe on multiple subscribers after destroy

Fixes #31

* Updated with semicolon (:
  • Loading branch information
reaktivo authored and fahad19 committed Sep 5, 2018
1 parent 9e506df commit ab13619
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions packages/proppy/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ function notify(callbacks, props) {
callbacks.forEach(cb => cb(props));
}

function removeCallback(callbacks, cb = null) {
for (let i = 0; i < callbacks.length; i++) {
if (cb && callbacks[i] === cb) {
callbacks.splice(i, 1);
break;
} else {
callbacks.splice(i, 1);
}
}
}

function defaultParentHandler() {
this.set.apply(this, arguments);
}
Expand All @@ -43,7 +32,7 @@ function getParentHandler(parent: null|Proppy, options: ProppyFactoryOptions) {

export function create(options: ProppyFactoryOptions): ProppyFactory {
return function (providers = {}, parent): Proppy {
const callbacks = [];
let callbacks = [];
let hasSubscribed = false;
const parentHandler = getParentHandler(parent, options);
let parentSubscription;
Expand Down Expand Up @@ -77,7 +66,7 @@ export function create(options: ProppyFactoryOptions): ProppyFactory {
cb(p.props);

return function () {
removeCallback(callbacks, cb);
callbacks = callbacks.filter(callback => cb !== callback);
};
};

Expand All @@ -91,7 +80,7 @@ export function create(options: ProppyFactoryOptions): ProppyFactory {
parent.destroy();
}

removeCallback(callbacks);
callbacks = [];
};

if (options.initialize) {
Expand Down

0 comments on commit ab13619

Please sign in to comment.