This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-09
Channels
- # beginners (205)
- # boot (6)
- # cider (22)
- # cljs-dev (41)
- # cljsrn (4)
- # clojure (97)
- # clojure-dev (61)
- # clojure-greece (40)
- # clojure-italy (8)
- # clojure-russia (16)
- # clojure-spec (18)
- # clojure-uk (34)
- # clojurescript (14)
- # community-development (1)
- # cursive (45)
- # datomic (39)
- # fulcro (66)
- # jobs (2)
- # lein-figwheel (1)
- # lumo (9)
- # off-topic (8)
- # parinfer (98)
- # portkey (8)
- # re-frame (81)
- # reagent (54)
- # remote-jobs (17)
- # ring (2)
- # shadow-cljs (217)
- # spacemacs (32)
- # sql (24)
- # test-check (6)
- # unrepl (73)
- # yada (12)
OK, so the current websocket support is very ugly, and I’ve made the time to start re-working it. There’s a new (very simple) demo at https://github.com/fulcrologic/websockets2-demo. I’ll probably be porting the formal websockets-demo to this soon, but the new support is much cleaner, and will be much simpler to tune up to be a really nice API. At the moment, it should be considered alpha quality, and it is currently only available in 2.2.0-SNAPSHOT on clojars. The nicest parts: It’s sooo much easier to use. Easy server setup is just:
(defn build-easy-server [path]
(easy/make-fulcro-server
:config-path path
:components {:websockets (fulcro.websockets/make-websockets (fulcro.server/fulcro-parser))
:ws-adapter (fulcro.websockets/make-easy-server-adapter)}))
and the client no longer needs any wiggy stuff…you pass the network state “watcher” and push handler as functions, so it is much easier too:
(new-fulcro-client
; replace the default remote with websockets
:networking {:remote (fw/make-websocket-networking "/chsk"
:push-handler push-handler
:state-callback state-callback)})
Old version needed core async, did all sorts of weird multimethod backflips, was hard to integrate with any kind of server, and didn’t deal with network errors correctly. It was also quite a bit more code.
Integrating into your own web stack is also a breeze. Just inject the websockets component into your component that builds your ring stack, and then:
(defrecord Middleware [ring-stack websockets]
component/Lifecycle
(start [this]
(assoc this :ring-stack
(-> (not-found-handler)
(fulcro.websockets/wrap-api websockets)
(wrap-keyword-params) ;required
(wrap-params) ; required
...
(wrap-not-modified)
(wrap-gzip))))
(stop [this]))
I’ve also done a first pass at rewriting the internal logging of Fulcro. I don’t recommend it for general use, but I’m trying to get rid of the timbre dependency. The new logging using println (clj) and glog (cljs)…so there’s no real external library overhead. Having a little trouble getting line nubmers to work right…works fine in the tests, but not in the wild. Anyway, it should not break things (the old namespace is still there), but during transition other libraries might continue to use the old namespace, which dynamically loads timbre…so you may still need it as a dep for the time being (e.g. fulcro-datomic still uses it at the moment). I’ll be fixing up other libraries to use the new support as soon as possible.I think it might be possible, now that FUlcro controls the rendering pipeline, to make dynamic updates during rendering possible, but I’ve not researched how I might go about it
you can embed data (e.g. values from atoms), and then re-up your CSS to get dynamic effects
@eric.shao what you mean by co-css by props? give extra css via props?
I really didn't understand the question
if it is about adding more css via props, I have some helpers to do that, they are easy to write
He’s asking if you can do this:
(defsc [this props]
{:css [[:.x {:background-color (:color props)}]]} ...)
I mean, not exactly extra css, I prefer to provide extra classes, and then allow those classes to be added via props
that's different
I usually do that indirectly
The answer at the moment is no, but I’ve kinda wanted something similar (props or computed)…and I think it would be possible with a tweak to the API.
but for details like this, if it needs to be dynamic, we can just use :style
but what if you wanted to load style info into your app state from a server configuration?
you could use styles, but it would be nice if you could inject state data into the css
well, if you need that level of configuration, just do garden, hehe
we could provide some helpers just to do proper namespacing
but otherwise seems out of fulcro-css scope IMO
I think it is perfectly possible to make it work like get-query: works on a class or instance
that way the static “startup” would be there, and from there dynamic behavior could be possible.
are you suggesting we might end up with one (or many) css class per instance?
I’m suggesting that the css method could be real code that could use props/computed (if available).
now we a relation: many css per fulcro component
but to do what you are saying, we might end up with a different set of classes, one set of class per instance
to be able to customize with that instance props
for example, let's get your code
(defsc MyItem [this props]
{:css [[:.x {:background-color (:color props)}]]} ...)
say I have one component with {:color "red"}
, and other with {:color "blue"}
I can't provide a single css class that will target both
they would have to be different classes, right?
(defsc X [this {:keys [a]} {:keys [c]} {:keys [resulting-class]}]
{:css (fn [] [[:.resulting-class {:color (or a "black") :background-color (or c "white")}]])}
(dom/div #js {:className resulting-class} ...))
yeah, you can't share those dynamic classes
correct, in that case you would not be able to pull in the classes from X without them being the “default” (static) version
but what that class will contain? what color will be there?
what if I have 2 diferent instances with differnet colors
the class name will be the same
that's what I'm saying, if you allow that I'll assume this is dynamic
doesn't seem to worth it, a simple :style
can solve this very nicely
agreed…and atom-based globals for general styles (or shared props that go to style attrs)
ok, thanks for talking through that…now we have a good answer to the question…now f only we had time to blog about it 🙂
no problem, always good to have those chats
it's kind fun, someone asks something, and we starting talking all over it (while the questioner is away), it's not the first time 🙂
chris@chris-Latitude-E6420 ~/IdeaProjects/websockets2-demo $ npm install --save-dev shadow-cljs ▀ ╢░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
WARN engine [email protected]: wanted: {"node":">=6.0.0"} (current: {"node":"4.2.6","npm":"3.5.2"})
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions