Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Make all event names exportable #139

Open
yvesgurcan opened this issue Jan 30, 2020 · 0 comments
Open

Feature: Make all event names exportable #139

yvesgurcan opened this issue Jan 30, 2020 · 0 comments
Labels
📈 optimization Refactors or improves existing code 🎩 enhancement New feature or request

Comments

@yvesgurcan
Copy link
Owner

yvesgurcan commented Jan 30, 2020

Problem

Describe the problem related to this feature request.

Right now, the logic to process which events are sent by the player requires comparisons of the event names with a string or variables created by the user.

See the React example into this repository:

const MIDI_PLAY = 'MIDI_PLAY';
const MIDI_PAUSE = 'MIDI_PAUSE';
const MIDI_END = 'MIDI_END';
const MIDI_ERROR = 'MIDI_ERROR';

if (payload.event === MIDI_ERROR) {

Strings like 'MIDI_PLAY' or 'MIDI_ERROR' have to be typed or created by the user instead of imported as variables from web-midi-player.

Solution

What solution do you suggest to solve this problem?

Export all event names so that comparing which events are being fired is easier. Something like this:

import MidiPlayer, { EVENTS } from 'web-midi-player';
const { MIDI_PLAY, MIDI_PAUSE, MIDI_STOP, MIDI_ERROR } = EVENTS;

const eventLogger = (payload) => {
  if (payload.event === MIDI_PLAY) {
    console.log('playing');
  }
};

const midiPlayer = new MidiPlayer({ eventLogger });
midiPlayer.play({ url: 'some_file.mid' });
@yvesgurcan yvesgurcan added the 🎩 enhancement New feature or request label Jan 30, 2020
@yvesgurcan yvesgurcan added the 📈 optimization Refactors or improves existing code label Feb 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📈 optimization Refactors or improves existing code 🎩 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant