ArseAssassin / reactive-switchboard

Declarative state handling for React
1 stars 3 forks source link

Should wireState define an interface for updating signals through callbacks? #14

Closed ArseAssassin closed 7 years ago

ArseAssassin commented 7 years ago

Pros:

Cons:

Both:

ArseAssassin commented 7 years ago

Can be implemented in user-space:

    persistentWires: (fn) => (props) => {
        let wires = []

        props.isAlive.filter(r.equals(false)).take(1).onValue(() => {
            wires.forEach((it) => it.end())
        })

        let wire = (arg) => {
            if (typeof arg === 'string') {
                return props.slot(arg).emit
            } else if (arg.emit) {
                return arg.emit
            } else if (arg.call) {
                let emitter = kefir.emitter()
                wires.push(emitter)
                arg(emitter)

                return (value) => {
                    emitter.emit(value)
                }
            }
        }

        return { wires: kefir.constant(fn(r.merge(props, { wire }))) }
    },