MVCoconut / coconut.vdom

Coconut rendering through virtual-dom.
The Unlicense
19 stars 8 forks source link

Can't use vdom.Foreign in new version #8

Closed kevinresol closed 5 years ago

kevinresol commented 6 years ago
package;

import tink.state.*;
import coconut.Ui.*;
import js.Browser.*;

class Main {
    static var key = {};
    static function main()
        hxx('<Editor key=${key} onChange=${onChange}/>');

    static function onChange(v:String)
        trace(v);
}

typedef Data = {
    @:optional var onChange(default, never):String->Void;
}

class Editor extends vdom.Foreign {

    public function new(data:Observable<Data>) {
        super(document.createDivElement());
    }
}

src/Main.hx:9: characters 15-21 : <Editor/> must have exactly one spread and no other attributes

back2dos commented 6 years ago

Hmm. Ok, I can see why. The following should work:

typedef Data = {
    @:optional var onChange(default, never):coconut.data.Value<String->Void>;
}

class Editor extends vdom.Foreign {

    public function new(data:Data) {
        super(document.createDivElement());
    }
}

But I can see how that can be a little awkward. I'll probably just reintroduce treatment of Observable<T> as single constructor argument.

kevinresol commented 6 years ago

But then I couldn't watch for changes in the Foreign?

kevinresol commented 6 years ago

Argh, ignore me, I see the Value thingy now

back2dos commented 5 years ago

Closing this as I'm not sure it's needed anymore.