This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-06
Channels
- # admin-announcements (1)
- # alda (2)
- # beginners (5)
- # boot (59)
- # clara (6)
- # cljs-dev (40)
- # cljsrn (32)
- # clojure (28)
- # clojure-austin (1)
- # clojure-belgium (67)
- # clojure-greece (60)
- # clojure-ireland (1)
- # clojure-japan (1)
- # clojure-russia (55)
- # clojure-spain (14)
- # clojure-spec (39)
- # clojure-uk (26)
- # clojurescript (152)
- # clojurewerkz (1)
- # cursive (21)
- # datomic (3)
- # dirac (15)
- # emacs (7)
- # events (2)
- # funcool (4)
- # hoplon (43)
- # immutant (1)
- # lambdaisland (1)
- # lein-figwheel (6)
- # leiningen (1)
- # off-topic (1)
- # om (23)
- # onyx (67)
- # other-languages (6)
- # pedestal (7)
- # planck (13)
- # proton (3)
- # protorepl (2)
- # re-frame (6)
- # reagent (5)
- # ring-swagger (6)
- # spacemacs (1)
- # specter (2)
- # yada (27)
@mhr i can help you get datascript working in hoplon if you want
here’s a datascript database as a cell, with a query in cell=
(def schema {})
(def conn (datascript.javelin/conn-cell schema))
(def not-seen (j/cell= (d/q '[:find ?e ?c :where [?e :message/content ?c]
[?e :message/seen false]]
conn)))
you can transact as normal
(defn seen!
[id]
{:pre [(integer? id)]}
(d/transact! conn [{:db/id id
:message/seen true}]))
this is all the “magic” you need
(defn- conn-cell-from-db
"Mimics datascript conn-from-db but builds a compatible javelin cell"
[db]
{:pre [(d/db? db)]
:post [(d/conn? %) (j/cell? %)]}
(j/cell db :meta { :listeners (atom {})}))
(defn conn-cell
"Builds a fresh conn cell wrapping an empty db"
([]
(conn-cell {}))
([schema]
{:pre [(map? schema)]
:post [(d/conn? %) (j/cell? %) (= {} (-> % meta :listeners deref))]}
(conn-cell-from-db (d/empty-db schema))))
you can hook it into your dom something like this
(h/defelem messages
[_ _]
(h/if-tpl (j/cell= (seq system-message.state/not-seen))
(h/div
:id "system-message"
(h/for-tpl [[id content] system-message.state/not-seen]
(h/div
:class "message"
(h/span
:class "message-text"
content)
(h/a
:class "message-close"
:click #(system-message.state/seen! @id)
:href "#"
" "))))))
and that’s datascript + hoplon...
Hey guys! I’m just getting started with this whole Hoplon/Javelin/Castra thing… 😁 I wonder what’s the preferred way to make HTTP requests to REST-ish endpoints and how to use returned data in JSON format. I’d be grateful for any help, advice, or internet resources. Thanks!
@beatngu13: I assume you mean to non castra backends?
I use http-kit
http://www.http-kit.org/client.html
you can make requests from the client or server to other endpoints
Yep! Found the following question from Jun '14 and started looking at the mentioned examples: http://hoplon.discoursehosting.net/t/how-to-make-http-requests/151
what I did in my case was use hoplon/castra in the usual way then from the server handle the request to the other servers, that let me use javelin/castra the usual way as well, where castra’s return value is placed into cells
but you could also do it straight from the client and skip your server, depending on your needs
Are there any best practices how to do this without a server at all? Making HTTP requests from the browser with Hoplon.
I started to play around with cljs-http
. What I really like is that it uses core.async
channels, but since I’m new to Hoplon I’m not sure if those two things fit together.
is that necessary? Personally (and probably because im missing something) I dont like using async channels
if you just want a simple json request you can use jquery
(js->clj (.. js/jQuery (get "
Well, not necessary. But I do this as an university project as part of a series about JS alternatives and I wanted to show the CSP way… 😉
@beatngu13: I’m using jQuery getJSON to grab data from a http://Prismic.io content repository and deposit the results into a cell. The library is open source and you could have a look at it here https://github.com/phalanxsystems/coci-prismic-api
@raywillig Prismic seems interesting!
@raywillig: Can you use it as a DB?
Their API doesn’t allow you to write to it. You can only do CUD from their writing room web app
I still haven't found the time to start playing around with clojure, cljs, and hoplon yet. I'm very interested in trying out figwheel. Does figwheel work well with hoplon? (Keep in mind I've not used figwheel nor hoplon so this may be a silly question.)
also thank you @thedavidmeister
I don't see any reason why it wouldn't, but if you use the boot-hoplon task you'd need to use boot not lein
so I should look at it in terms of boot vs. figwheel to achieve that same live interactivity?