Skip to content

Create a reactive programming API for controllers #13440

Description

@christophehenry

Feature Description

This is an issue that I've already risen in the past proposing to add ability to pass arbitrary keys engine.setValue and engine.setParameter but this seem to have met some opposition.

So I'd like to start a broader discussion about adding an API to do reactive programming in controller especially now that I started working on ES6+ components JS.

What I propose is to reflect on a standard API for Mixxx, setting aside the implementation. This API could mimic ES Event API with methods like dispatchEvent, addEventListener and removeEventListener a be closer to Qt's signals/slots API (also I'm not sure what this would look like…).

This API could be standard to Component and ComponentContainer.

Regarding the implementation, I propose a first implementation in pure JS using EventTarget, CustomEvent and Proxy (this seem supported by Mixxx' JS engine, also I need to formally check) as follows:

class Component {
        __signals = new (class extends EventTarget {
            constructor() {
                super();
                return new Proxy(this, {
                    set: (target, property, value) => {
                        const previousValue = target[property];
                        target[property] = value;
                        this.dispatchEvent(new CustomEvent(property, { detail: {value, previousValue} }));
                        return true;
                    },
                });
            }
        })();

        connect(name, callback) {
            this.__signals.addEventListener(name, (evt) => {
                callback(name, evt.detail.value, evt.detail.previousValue)
            })
        }
}

that could be transparantly replaced by a C++ implem in the engine namespace thanks to the standard API.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions