Skip to content

Commit c4f2ec3

Browse files
Merge branch 'on'
2 parents ba9d1f4 + 3730117 commit c4f2ec3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/utils/api/pub_sub.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ Pub_Sub.prototype.off = function (publisherName, fn) {
2323
};
2424
//subscribe
2525
Pub_Sub.prototype.on = function (publisherName, fn) {
26-
if (typeof fn === 'function' && Object.prototype.hasOwnProperty.call(this._publishers, publisherName))
27-
this._publishers[publisherName].push(fn);
26+
if (typeof fn === 'function' && Object.prototype.hasOwnProperty.call(this._publishers, publisherName)) {
27+
// check if it has not existed
28+
if (this._publishers[publisherName].indexOf(fn) === -1) {
29+
this._publishers[publisherName].push(fn);
30+
}
31+
}
2832
return this;
2933
};
3034
//oneSubscribe

0 commit comments

Comments
 (0)