Skip to content

Commit

Permalink
some size optimizations (#69)
Browse files Browse the repository at this point in the history
* -4 bytes optimization

* -16 bytes optimization

---------

Co-authored-by: Igor Mitusov <igi.sev@gmail.com>
  • Loading branch information
igisev and Igor Mitusov authored Nov 23, 2023
1 parent 6aa2539 commit f9ae537
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
export let createNanoEvents = () => ({
emit(event, ...args) {
let callbacks = this.events[event] || []
for (let i = 0, length = callbacks.length; i < length; i++) {
for (let i = 0, callbacks = this.events[event] || [], length = callbacks.length; i < length; i++) {
callbacks[i](...args)
}
},
events: {},
on(event, cb) {
this.events[event]?.push(cb) || (this.events[event] = [cb])
(this.events[event]||=[]).push(cb);
return () => {
this.events[event] = this.events[event]?.filter(i => cb !== i)
}
Expand Down

0 comments on commit f9ae537

Please sign in to comment.