Closed alfonsogarciacaro closed 1 year ago
Here's how I do it
[<AutoOpen>]
module SutilExtensions =
open Sutil
type JS.Promise<'T> with
member self.ToObservable() : ObservablePromise<'T> =
let op = ObservablePromise<'T>()
op.Run(self)
op
let view (server : Server) dispatchExternal (setlistId : string) =
Bind.el(
(findCreateSetlist server setlistId).ToObservable(),
fun x ->
match x with
| Waiting ->
Html.div "Loading..."
| State.Error x ->
Html.div (x.Message)
| Result (setlist,songs) ->
viewSetlist server dispatchExternal setlist songs
)
We can make an overload in Bind.el
that accepts a Promise, and does the .ToObservable()
part internally
This works, thank you @davedawkins!
Sorry @davedawkins, haven't checked the whole API but, is there something to bind promise/transform promises into SutilElements? I assume it shouldn't be very difficult as SutilElements are asynchronous by default. Binding promises would enable lazy loading and deferred elements (for fetching data, etc).
The helper should have 3 arguments: