We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents ba9d1f4 + 3730117 commit c4f2ec3Copy full SHA for c4f2ec3
src/utils/api/pub_sub.js
@@ -23,8 +23,12 @@ Pub_Sub.prototype.off = function (publisherName, fn) {
23
};
24
//subscribe
25
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);
+ if (typeof fn === 'function' && Object.prototype.hasOwnProperty.call(this._publishers, publisherName)) {
+ // check if it has not existed
28
+ if (this._publishers[publisherName].indexOf(fn) === -1) {
29
+ this._publishers[publisherName].push(fn);
30
+ }
31
32
return this;
33
34
//oneSubscribe
0 commit comments