);
+ if (i > -1) this.hub[event].splice(i, 1);
+ if (this.hub[event].length === 0) delete this.hub[event];
}
});
const handler = data => console.log(data);
diff --git a/docs/function.html b/docs/function.html
index efccc0759..2b9ef5087 100644
--- a/docs/function.html
+++ b/docs/function.html
@@ -155,6 +155,7 @@ console.log<
+
const lengthIs4 = checkProp(l => l === 4, 'length');
lengthIs4([]);
lengthIs4([1,2,3,4]);
diff --git a/snippets/checkProp.md b/snippets/checkProp.md
index 391d872d6..3262f3969 100644
--- a/snippets/checkProp.md
+++ b/snippets/checkProp.md
@@ -20,6 +20,7 @@ const checkProp = (predicate, prop) => obj => !!predicate(obj[prop]);
+
const lengthIs4 = checkProp(l => l === 4, 'length');
lengthIs4([]); // false
lengthIs4([1,2,3,4]); // true
diff --git a/test/_30s.js b/test/_30s.js
index 4151e82bd..2c0a2ba21 100644
--- a/test/_30s.js
+++ b/test/_30s.js
@@ -205,6 +205,7 @@ const createEventHub = () => ({
off(event, handler) {
const i = (this.hub[event] || []).findIndex(h => h === handler);
if (i > -1) this.hub[event].splice(i, 1);
+ if (this.hub[event].length === 0) delete this.hub[event];
}
});
const currentURL = () => window.location.href;
diff --git a/vscode_snippets/snippets.json b/vscode_snippets/snippets.json
index 103e9be86..6f634e58e 100644
--- a/vscode_snippets/snippets.json
+++ b/vscode_snippets/snippets.json
@@ -423,7 +423,7 @@
" off(event, handler) {",
" const i = (this.hub[event] || []).findIndex(h => h === handler);",
" if (i > -1) this.hub[event].splice(i, 1);",
- " if (this.hub[event].length === 0) delete this.hub[event];",
+ " if (this.hub[event].length === 0) delete this.hub[event]",
" }",
"});"
],