Skip to content

Commit 2f6a3b4

Browse files
committed
Adds log option
1 parent d9c90d7 commit 2f6a3b4

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

rollup.config.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@ export default [
99
name: 'pubsub',
1010
file: pkg.main
1111
},
12-
plugins: [buble()]
12+
plugins: [
13+
buble({
14+
objectAssign: 'Object.assign'
15+
})
16+
]
1317
},
1418
{
1519
input: 'src/pubsub.js',
1620
output: {
1721
format: 'es',
1822
file: pkg.module
1923
},
20-
plugins: [buble()]
24+
plugins: [
25+
buble({
26+
objectAssign: 'Object.assign'
27+
})
28+
]
2129
}
2230
];

src/pubsub.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
class pubsub {
2-
constructor(options = {}) {
3-
this.options = options;
2+
constructor(options) {
3+
this.options = {
4+
/*
5+
Enables strict mode (shows more warnings)
6+
*/
7+
strict: false,
8+
9+
/*
10+
Accepts a custom logger
11+
*/
12+
log: false,
13+
14+
...options
15+
};
416
this._pubsubEvents = {};
517
this._pubsubHappened = {};
618
}
@@ -31,6 +43,11 @@ class pubsub {
3143
for (j = 1; j < arguments.length; j++) {
3244
args.push(arguments[j]);
3345
}
46+
47+
if (this.options.log) {
48+
this.options.log(event, args);
49+
}
50+
3451
for (j = 0, jlen = eventArray.length; j < jlen; j++) {
3552
subscriber = eventArray[j];
3653
ret = subscriber[0].apply(subscriber[1] || this, args);

0 commit comments

Comments
 (0)