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 moveItem = (el, distance, duration) => { | |
const invokedTime = new Date().getTime(); | |
let delta = distance/duration; | |
let animFrame = null; | |
const doMove = () => { | |
const elapsedTime = (new Date().getTime()) - invokedTime; | |
if (elapsedTime > duration) { | |
cancelAnimationFrame(animFrame); |
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 EventEmitter{ | |
constructor(){ | |
this.events = {} | |
} | |
on(event, callback){ | |
if (!this.events.hasOwnProperty(event)){ | |
this.events[event] = []; | |
} | |
this.events[event].push(callback); | |
} |