Fork me on GitHub
#fulcro
<
2018-02-09
>
tony.kay03:02:55

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.

tony.kay05:02:42

Developer’s guide updated with new logging and websocket info.

tony.kay05:02:50

2.2.0-SNAPSHOT is on clojars

eric.shao16:02:37

Is there a way to configure co-css by props?🙂

tony.kay17:02:13

no, because the CSS has to be available when things start

tony.kay17:02:10

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

tony.kay17:02:40

you can embed data (e.g. values from atoms), and then re-up your CSS to get dynamic effects

wilkerlucio17:02:57

@eric.shao what you mean by co-css by props? give extra css via props?

tony.kay17:02:33

you could hack it pretty easily, though, now that I think about it.

wilkerlucio17:02:42

I really didn't understand the question

wilkerlucio17:02:03

if it is about adding more css via props, I have some helpers to do that, they are easy to write

tony.kay17:02:20

He’s asking if you can do this:

(defsc [this props]
  {:css [[:.x {:background-color (:color props)}]]} ...)

wilkerlucio17:02:29

I mean, not exactly extra css, I prefer to provide extra classes, and then allow those classes to be added via props

wilkerlucio17:02:40

that's different

wilkerlucio17:02:07

I usually do that indirectly

tony.kay17:02:31

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.

wilkerlucio17:02:35

but for details like this, if it needs to be dynamic, we can just use :style

tony.kay17:02:44

that’s true

tony.kay17:02:12

but what if you wanted to load style info into your app state from a server configuration?

tony.kay17:02:29

you could use styles, but it would be nice if you could inject state data into the css

wilkerlucio17:02:33

well, if you need that level of configuration, just do garden, hehe

tony.kay17:02:50

it’s very true…the fulcro-css library is very tiny

wilkerlucio17:02:17

we could provide some helpers just to do proper namespacing

wilkerlucio17:02:32

but otherwise seems out of fulcro-css scope IMO

tony.kay17:02:20

I think it is perfectly possible to make it work like get-query: works on a class or instance

tony.kay17:02:46

that way the static “startup” would be there, and from there dynamic behavior could be possible.

tony.kay17:02:58

I like it, I just don’t have the time to code it at the moment 🙂

wilkerlucio17:02:16

are you suggesting we might end up with one (or many) css class per instance?

tony.kay17:02:41

that is already there…what do you mean?

tony.kay17:02:08

I’m suggesting that the css method could be real code that could use props/computed (if available).

wilkerlucio17:02:09

now we a relation: many css per fulcro component

wilkerlucio17:02:29

but to do what you are saying, we might end up with a different set of classes, one set of class per instance

wilkerlucio17:02:37

to be able to customize with that instance props

tony.kay17:02:01

I don’t understand what you’re saying

wilkerlucio17:02:09

for example, let's get your code

wilkerlucio17:02:18

(defsc MyItem [this props]
  {:css [[:.x {:background-color (:color props)}]]} ...)

wilkerlucio17:02:42

say I have one component with {:color "red"}, and other with {:color "blue"}

wilkerlucio17:02:18

I can't provide a single css class that will target both

wilkerlucio17:02:25

they would have to be different classes, right?

tony.kay17:02:40

(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} ...))

wilkerlucio17:02:57

yeah, you can't share those dynamic classes

tony.kay17:02:19

correct, in that case you would not be able to pull in the classes from X without them being the “default” (static) version

tony.kay17:02:36

or can you?

tony.kay17:02:42

the classname isn’t changing

wilkerlucio17:02:59

but what that class will contain? what color will be there?

tony.kay17:02:10

the one from the last time the styles were pulled from X itself

wilkerlucio17:02:21

what if I have 2 diferent instances with differnet colors

wilkerlucio17:02:30

the class name will be the same

tony.kay17:02:34

then you’ve coded a bad thing 🙂

tony.kay17:02:47

to-many things should not do this, for sure

wilkerlucio17:02:48

that's what I'm saying, if you allow that I'll assume this is dynamic

wilkerlucio17:02:11

doesn't seem to worth it, a simple :style can solve this very nicely

tony.kay17:02:27

agreed…and atom-based globals for general styles (or shared props that go to style attrs)

tony.kay17:02:03

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 🙂

wilkerlucio17:02:56

no problem, always good to have those chats

wilkerlucio17:02:22

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 🙂

cjmurphy22:02:47

chris@chris-Latitude-E6420 ~/IdeaProjects/websockets2-demo $ npm install --save-dev shadow-cljs ▀ ╢░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟

cjmurphy22:02:52

WARN engine [email protected]: wanted: {"node":">=6.0.0"} (current: {"node":"4.2.6","npm":"3.5.2"})

thheller22:02:09

defintely upgrade 😛

cjmurphy22:02:41

Anyone out there that runs Linux? Seems like I'm going to need to get latest node to run.

thheller22:02:25

I'm running the 9.x version on debian

cjmurphy23:02:26

Or maybe its a slow network (timeout getting resource) problem from my end, and I should just try again..?