Hello there. This nessage is kinda old, but I'll leave it here so that maybe will help future readers.
There are a lot of misconceptions on castra, cells, backend and front-end (don't worry, I'm new on this too, and these are normal - the documentations are kinda vague).
Javelin enables a
cell structure. HLisp is the one that allows us to use cells transparently on the UI. Castra is just a "glue" between remote functions (on the backend) and ClojureScript (the frontend).
So, the idea is the following: we have a
So, back to your example: you have a page which have a websocket. This websocket listens to sequence-ids. So, let's imagine your handler for these functions is in some ClojureScript file. What would you need to do is:
- Register, on the backend, a RPC function with defrpc, which will receive the last message id and send a list, or vector of messages. I don't know exactly what is the contents of these events, so let's, for now, imagine that it's a list of operations that need to be performed on the client.
- On the client side, you inform that there's a callable RPC function, with mkremote. The way Castra is developed, you'll need three cells that will be
reset! 'ed when the remote function call is completed.
- Still on the client side, you'll need a way to react to this result. The way that I see, it'll be a cell operation.
So, on the server-side:
(:require [castra.core :refer [defrpc]]))
(defrpc get-msgs-since [last-id]
; -- your code here --
Then, on the client-side:
[javelin.core :refer [defc defc=]])
[castra.core :refer [mkremote]]))
(defc messages )
(defc loading )
(defc error nil)
(def get-msgs-since (mkremote 'backend.api/get-msgs-since messages error loading))
; Callback that you, somehow, registered to the websocked
(defn listen-to-server-push [msg-id]
(get-msgs-since msg-id)) ; <-- This will update the "messages" cell.
; This code is a "cell operation" that will listen to changes in the messages:
(doseg [msg messages] (do-whatever-you-want-with msg)))
I really hope that in the future, the way we call remote functions in castra is changed so that we can pass a function and not worry about which cells are updated, but for now, this is the way I use Castra.