Skip to content

Commit

Permalink
fix exception when removing listener during listeners check.
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Dec 7, 2017
1 parent e3e50c6 commit 37897b4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "delta-listener",
"version": "2.1.1",
"version": "2.1.2",
"description": "Deeply compare JavaScript objects and listen to changes.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/DeltaContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class DeltaContainer<T=any> {

for (let j = 0, len = this.listeners.length; j < len; j++) {
let listener = this.listeners[j];
let pathVariables = this.getPathVariables(patches[i], listener);
let pathVariables = listener && this.getPathVariables(patches[i], listener);
if (pathVariables) {
listener.callback({
path: pathVariables,
Expand Down
11 changes: 11 additions & 0 deletions test/delta_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,15 @@ describe("DeltaContainer", () => {
container.set(data);
});

it("should allow removing listeners inside a listener", () => {
let container = new DeltaContainer({});
let listenerToRemove = container.listen("entities/:id", (change: DataChange) => {
container.removeListener(listenerToRemove);
numCalls++;
});
container.listen("players", (change: DataChange) => numCalls++);
container.set(clone(data));
assert.equal(numCalls, 2);
})

})

0 comments on commit 37897b4

Please sign in to comment.