Skip to content

Commit

Permalink
chore: build
Browse files Browse the repository at this point in the history
  • Loading branch information
appy-one committed Aug 29, 2022
1 parent 1b573a3 commit 612d1bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
32 changes: 9 additions & 23 deletions dist/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3941,27 +3941,18 @@ class SimpleEventEmitter {
return this;
}
once(event, callback) {
let resolve;
const promise = new Promise(rs => {
if (!callback) {
// No callback used, promise only
resolve = rs;
return new Promise(resolve => {
const ourCallback = (data) => {
resolve(data);
callback === null || callback === void 0 ? void 0 : callback(data);
};
if (this._oneTimeEvents.has(event)) {
runCallback(ourCallback, this._oneTimeEvents.get(event));
}
else {
// Callback used, maybe also returned promise
resolve = (data) => {
rs(data); // resolve promise
callback(data); // trigger callback
};
this._subscriptions.push({ event, callback: ourCallback, once: true });
}
});
if (this._oneTimeEvents.has(event)) {
runCallback(resolve, this._oneTimeEvents.get(event));
}
else {
this._subscriptions.push({ event, callback: resolve, once: true });
}
return promise;
}
emit(event, data) {
if (this._oneTimeEvents.has(event)) {
Expand All @@ -3972,12 +3963,7 @@ class SimpleEventEmitter {
if (s.event !== event) {
continue;
}
try {
s.callback(data);
}
catch (err) {
console.error('Error in subscription callback', err);
}
runCallback(s.callback, data);
if (s.once) {
this._subscriptions.splice(i, 1);
i--;
Expand Down
2 changes: 1 addition & 1 deletion dist/browser.min.js

Large diffs are not rendered by default.

0 comments on commit 612d1bc

Please sign in to comment.