Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: add support for a command callback in the update functions #39

Open
tcoopman opened this issue Jul 20, 2021 · 1 comment

Comments

@tcoopman
Copy link
Contributor

Bucklescript-tea has Tea_cmd.call which allows you to enqueue callbacks for example in the update of the model.

This makes handling callbacks from websockets for example much easier. A Ws implementation could look something like this:

let update model = function
  | `Join -> 
    let () = Vdom.Cmd.call (fun callbacks -> Ws.Channel.join model.channel (fun msg -> callbacks.enqueue (`Joined msg)) in
    return model
  | ....
)
@tcoopman
Copy link
Contributor Author

I've found a way to simulate this:

type 'msg Vdom.Cmd.t += Run of (('msg -> unit) -> unit)

let update model = function
  | `Async ->
        return
          model
          ~c:
            [ Run (fun send -> send `Msg)]
						
let cmd_handler ctx = function
  | Run cb ->
      cb (fun x -> Vdom_blit.Cmd.send_msg ctx x) ;
      true
  | _ ->
      false


let () = Vdom_blit.(register (cmd { f = cmd_handler }))

Still it would be nice to have this as a build-in option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant