This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on(name, listener) { | |
if (!this._events[name]) { | |
this._events[name] = []; | |
} | |
this._events[name].push(listener); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
removeListener(name, listenerToRemove) { | |
if (!this._events[name]) { | |
throw new Error(`Can't remove a listener. Event "${name}" doesn't exits.`); | |
} | |
const filterListeners = (listener) => listener !== listenerToRemove; | |
this._events[name] = this._events[name].filter(filterListeners); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constructor() { | |
this._events = {}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
emit(name, data) { | |
if (!this._events[name]) { | |
throw new Error(`Can't emit an event. Event "${name}" doesn't exits.`); | |
} | |
const fireCallbacks = (callback) => { | |
callback(data); | |
}; | |
this._events[name].forEach(fireCallbacks); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyEventEmitter { | |
constructor() { | |
this._events = {}; | |
} | |
on(name, listener) { | |
if (!this._events[name]) { | |
this._events[name] = []; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyEventEmitter {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const str = fs.readFileSync('./str.txt', 'utf8'); | |
console.log('String length:', str.length); | |
console.log('---------'); | |
function test() { | |
console.time('Split speed'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const str = fs.readFileSync('./str.txt', 'utf8'); | |
console.log('String length:', str.length); | |
console.log('---------'); | |
function test() { | |
console.time('Call speed'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const str = fs.readFileSync('./str.txt', 'utf8'); | |
console.log('String length:', str.length); | |
console.log('---------'); | |
function test() { | |
console.time('Loop speed'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); | |
module.exports = { | |
mode: process.env.NODE_ENV, | |
devtool: 'none', | |
target: 'node', | |
context: path.resolve(__dirname, 'src'), | |
entry: 'index.ts', | |
output: { |
OlderNewer