Skip to content

Commit

Permalink
feat(off): allow removing all listeners of all events
Browse files Browse the repository at this point in the history
just off(name) will remove all "name" listeners; off() with no arguments will reset the store to be
empty
  • Loading branch information
tunnckoCore committed Mar 19, 2017
1 parent 923391d commit 095140f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 8 deletions.
6 changes: 4 additions & 2 deletions dist/dush.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function dush () {
*/

on: function on (name, handler, once) {
var e = all[name] || (all[name] = []);
var e = app.all[name] || (app.all[name] = []);

function func () {
if (!func.called) {
Expand Down Expand Up @@ -217,8 +217,10 @@ function dush () {
if (handler && all[name]) {
var fnStr = handler.toString();
all[name] = all[name].filter(function (func) { return func.sourceString !== fnStr; });
} else {
} else if (name) {
all[name] = [];
} else {
app.all = Object.create(null);
}

return app
Expand Down
6 changes: 4 additions & 2 deletions dist/dush.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function dush () {
*/

on: function on (name, handler, once) {
var e = all[name] || (all[name] = []);
var e = app.all[name] || (app.all[name] = []);

function func () {
if (!func.called) {
Expand Down Expand Up @@ -215,8 +215,10 @@ function dush () {
if (handler && all[name]) {
var fnStr = handler.toString();
all[name] = all[name].filter(function (func) { return func.sourceString !== fnStr; });
} else {
} else if (name) {
all[name] = [];
} else {
app.all = Object.create(null);
}

return app
Expand Down
2 changes: 1 addition & 1 deletion dist/dush.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/dush.umd.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/dush.umd.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 095140f

Please sign in to comment.