ivanvmat / color-picker

:droplet: Flat and simple color-picker library. No dependencies, no jquery.
https://ivanvmat.github.io/color-picker/
MIT License
20 stars 5 forks source link

Fix bug that prevents using it with code from README #4

Closed relistan closed 3 years ago

relistan commented 3 years ago

On startup the following code from the README does not work with the current master branch:

const picker = new ColorPickerControl({ 
    container: document.body, 
    theme: 'light' 
});

picker.on('init', (instance) => {
    console.log('Event: "init"', instance);
});
picker.on('open', (instance) => {
    console.log('Event: "open"', instance);
});
picker.on('change', (color) => {
    console.log('Event: "change"', color);
});
picker.on('close', (instance) => {
    console.log('Event: "close"', instance);
});

This is because eventListeners[event] is not initialized and so the push operation fails. This change lazily initializes the event type in eventListeners and resolves the issue without having to explicitly initialize each event.