Clojurians
#hoplon
<
2016-05-14
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

leontalbot00:05:00

Hello! I made my hoplon page use castra to ask server to fetch a third party db. Could it be faster if the server could fetch db when the page is requested (before hoplon client even ask) and push it asynchroniously to hoplon when ready? If so how would you do it??? Thanks!

leontalbot01:05:06

Oh... hoplon/notify...

leontalbot02:05:21

@jumblerg: I read this in slack log "jumblerg 03:06:40 i do, however, have a branch of castra i’m hacking for the purpose of supporting “push", if that’s what you’re looking for"

leontalbot02:05:25

I would be interested in trying that out. Where can I find this? Do you have a minimal example? Much thanks in advance !

leontalbot03:05:54

@jumberg Can it speed up initial data loading from db to client?

piotrek08:05:49

Hi, I am using semantic-ui and trying to get the following to work:

piotrek08:05:42

but I am getting: Uncaught TypeError: jQuery(...).popup is not a function

piotrek08:05:19

I have tried to put (.popup (js/jQuery elem)) into with-init! or with-dom or just on itself but the issue persists

piotrek08:05:22

any hints?

dm308:05:33

are you sure the popup javascript is included?

piotrek08:05:05

I have it in my head of my page: (script :src ")

piotrek08:05:10

so I guess I do

piotrek09:05:25

that js file defines popup function

piotrek09:05:02

When I select my div and type jQuery($0).popup() in console it works fine

leontalbot09:05:21

@piotrek: what if you use this?

piotrek09:05:52

@leontalbot: I will try it, thanks

piotrek11:05:49

@leontalbot: it worked! yey!

leontalbot11:05:39

@piotrek really cool!!

leontalbot11:05:21

We love cljsjs cljs

jumblerg16:05:48

@leontalbot: the state-fn pr (which @micha assures me he’s going to review and merge in alongside @raywillig`s someday) is a step towards “push"

jumblerg16:05:47

they way i use it is like this

jumblerg16:05:27

(wrap-castra {:state-fn #(q/model *db*)} ‘myapp.service.command ‘myapp.service.query)

jumblerg17:05:45

where the model fn returns whatever data the client needs in the request, alongside the result of the function that was explicitly called from the client

jumblerg17:05:25

the state function becomes the target for any short polling, long polling, http streaming combination that takes place to create the effect of “push”, hence the quotes

jumblerg17:05:10

the idea is to further separate/segregate the command and query sides of the application such that commands can be called from castra and return their own results (may be nil in most cases), while the state-fn can return whatever data is needed by the application model to create the effect of a binding between the client’s data model in the cell and the data/db on the server.

jumblerg17:05:49

the state function won’t speed anything up on its own, but it will create a significant optimization if it takes advantage of versioned data: requests to the state-fn should include an as-of parameter so that it will only return those facts that have been written to the database since the client last requested or subscribed to the dataset of interest

jumblerg17:05:38

this assumes the client implements some sort of explicit caching strategy where data accumulates with each request; it can then request only the additional data that was written to the db since its last request instead of reloading all the things every time.

jumblerg17:05:30

the state-fn also frees you from having to explicitly return the state at the end of each rpc fn

jumblerg17:05:06

basically, the client calls an rpc fn/command, the result of that call is returned at the same call site, and the application state returned by the state-fn just happens to hitchhike/piggyback along the same http response, but gets placed in the associated cell instead once it makes it to the client.

leontalbot17:05:21

The client doesn't need to reask for update

jumblerg17:05:08

correct, up to a point, the client will automatically update itself whenever a command is called.

leontalbot17:05:01

so if command is called by server, server could say get data updates every 5 minutes...

leontalbot17:05:22

If there is a change push back to client?

jumblerg17:05:46

not yet, i’ve yet to commit the “push” implementation that makes use of the state-fn so that the client will update without a command being called.

jumblerg17:05:20

however, if you build your app this way, you’ll get push for free whenever i do 🙂

jumblerg17:05:14

(and @micha merges it)

jumblerg17:05:28

no good deed goes unpunished in open source

leontalbot17:05:38

that is a "promise" 😉

jumblerg17:05:40

yeah, exactly, a “promise”. 6 months from now you can heckle me about it the same way i’m pestering @micha right now.

leontalbot17:05:08

you should call "deliver" now...

leontalbot17:05:44

So, for now, the difference between the result and the state is the thing that is implemented, is that right?

jumblerg17:05:53

i’m not sure what your case is so maybe this doesn’t apply, but i can tell you that, in practice, i haven’t really needed the “push” yet, so that’s why it has slipped a bit on my priority list.

leontalbot17:05:46

State is an atom?

jumblerg17:05:49

a data structure

leontalbot17:05:18

so I a have a state like this

leontalbot17:05:23

[{:id "1" :text "hello"} {:id "2" :text "world"}]

leontalbot17:05:40

and it changes to [{:id "1" :text "hello"} {:id "2" :text "my world"}]

leontalbot17:05:54

what will be the "result?"

jumblerg17:05:18

it depends on how you write your state-fn

jumblerg17:05:35

the simplest way would be to have the state-fn return the entire thing on the back of each http request

jumblerg17:05:58

as your state/model grows larger, you might want to introduce some optimizations

jumblerg17:05:41

you could put that in an atom and your state fn is basically deref

leontalbot17:05:12

I am starting to understand why do this

jumblerg17:05:43

i didn’t quite understand castra (specifically, how it tied into a cqrs architecture when the commands were in the business of returning query results), until he explained to me that, conceptually, this was just an implementation detail that took advantage of the way http works.

jumblerg17:05:43

i guess the general idea behind the state-fn is to make the http implementation leak a little bit less

leontalbot17:05:45

Can't hoplon/notify achieve just this (push)

jumblerg17:05:14

make castra behave more like an mvcqrsish thing would if it the application lived entirely on one side of the wire

jumblerg17:05:30

i don’t know much about notify

jumblerg17:05:58

but it looks like it could. my goal is to build this capability into castra without any interface changes

lspector23:05:27

Super newbie question: How do I deploy? I've done the "Getting Started" address-book exercise and it works locally. What do I have to put on my server for this to work for users browsing there? (Probably obvious: I don't do much web programming... but I'm a long time Lisper hoping hoplon is the way to do more on the web.)