Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
How to create a message every time an event is emitted

I'm trying to implement an app that creates a ".message" for each lyric every time the beat ticks. However, it seems like I've hit a wall while trying to come up with an algorithm.

My code:

import EventEmitter from "eventemitter3";
import Beat from "./Beat";

export default class Application extends EventEmitter {
  static get events() {
    return {
      READY: "ready",
    };
  }

  constructor() {
    super();
    
    this._beat = new Beat();
    this._create();

    this.emit(Application.events.READY);
  }
  _create() {
    const lyrics = ["Ah", "ha", "ha", "ha", "stayin' alive", "stayin' alive"];
    let count = 0;

    this._beat.on("update", (bit) => {
      const message = document.createElement("div");
      message.classList.add("message");
      message.innerText = lyrics[bit];

      document.querySelector(".main").appendChild(message);
    })
  }
}

Beat interval:

import EventEmitter from "eventemitter3";
export default class Beat extends EventEmitter{
  static get events() {
    return {
      BIT: "bit",
    };
  }

  constructor() {
    super();
    setInterval(() => {
      console.log("bit");
      this.emit(Beat.events.BIT);
    }, 600);
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're subscribing to 'update' event, which is never fired.

Fixed code snippet:

    this._beat.on(Beat.events.BIT, (bit) => {
      const message = document.createElement("div");
      message.classList.add("message");
      message.innerText = lyrics[bit];

      document.querySelector(".main").appendChild(message);
    })
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!