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

How to handle websocket push events in om.next #22

Closed
favetelinguis opened this issue Jan 27, 2016 · 3 comments
Closed

How to handle websocket push events in om.next #22

favetelinguis opened this issue Jan 27, 2016 · 3 comments

Comments

@favetelinguis
Copy link

From your turtorial my guess it that the way to handle websockets push messages is to use om/transact! in the websocket eventhandler?

However in the following youtube video:
https://www.youtube.com/watch?v=IlNrmKYA7Ig

There is a comment about handling websockets push messages but im not understanding what that comment actually is.

@artemyarulin
Copy link

Not the author, but after discussion with David on slack I've implemented it like that:

  1. Add :merge-tree merger to the reconciler
  2. merger defined as (defn merger [state new-item] which should merge new data to the state
  3. Call om/merge! from the outside (webSocker handler, etc.) like
(.setTimeout js/window #(om/merge! rec {:new "data"}) 3000)

@favetelinguis
Copy link
Author

Nice, thanks! Might be a good input for the turtorial...

@awkay
Copy link
Owner

awkay commented Jan 27, 2016

Steps 1/2 are optional (though the default merge-tree is just merge). merge! is the standard way to put new stuff into your app database. merge! accepts a query, so if you have new data and a query (for normalization), then you can simply merge it in. You might want/need to call om/force-root-render! to rerender everything.

@awkay awkay closed this as completed Jan 27, 2016
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

3 participants