davidanthoff / Electron.jl

Julia wrapper for Electron
Other
85 stars 19 forks source link

How do I call sendMessageToJulia from vegaEmbed(...).then? #34

Open tkf opened 4 years ago

tkf commented 4 years ago

In https://github.com/tkf/VegaStreams.jl ("Real-time" plotting with VegaLite.jl and ElectronDisplay.jl), I wanted to call sendMessageToJulia like this:

var VIEW = null;

vegaEmbed('#plotdiv', spec, opt).then(function (result) {
    VIEW = result.view;
    sendMessageToJulia("view-is-ready");
}).catch(console.warn);

However, it looks like sendMessageToJulia is not available here, presumably because it is defined on did-finish-load event which is too late? Can it be defined earlier? Or is there a better JavaScript pattern to do this?

davidanthoff commented 4 years ago

Hm, maybe you have to call vegaEmbed from julia, a la run(win, "vegaEmbed(blabla)")? I would assume that at that stage everything is loaded.

But maybe there is also a different/earlier event than did-finish-load that we could hook into, I'm not sure.

davidanthoff commented 4 years ago

Oh, and bt.w VegaStreams.jl looks awesome!! I've been think about something like that for a while, but always thought I would first try to finish https://github.com/davidanthoff/ObservableInterfaces.jl, which would automatically give us an "observable tables" interface (i.e. an observable of named tuples). But just starting with this the way you did is certainly a better idea, because who knows when I'll find time for the observable story.

tkf commented 4 years ago

maybe you have to call vegaEmbed from julia, a la run(win, "vegaEmbed(blabla)")? I would assume that at that stage everything is loaded.

That makes sense. I'll try that.

Oh, and bt.w VegaStreams.jl looks awesome!!

That's all thanks to ElectronDisplay (and Vega-Lite)! I was very surprised that it can be done with such a small amount of code.

but always thought I would first try to finish https://github.com/davidanthoff/ObservableInterfaces.jl, which would automatically give us an "observable tables" interface (i.e. an observable of named tuples)

BTW, I think it's already (somewhat) usable with iterator-based interface.

vls = vegastream(@vlplot(:line, x=:x, y=:y))
enumerate(randn(100)) |>
    @map({x=_[1], y=_[2]}) |>
    @filter(_.y > 0) |>
    itr -> foldl(push!, itr; init=vls)

For fun, an equivalent implementation in Transducers.jl is:

vls = vegastream(@vlplot(:line, x=:x, y=:y))
xf = Map(NamedTuple{(:x, :y)}) |> Filter(row -> row.y > 0)
foldl(push!, xf, enumerate(randn(100)); init=vls)
davidanthoff commented 4 years ago

Man, I really need to understand transducers. But somehow my brain is just not wired the right way for that...

The nice thing about the ObservableInterface would be that it supports a proper push interface, rather than a pull story.