Fork me on GitHub
#fulcro
<
2017-11-27
>
LL00:11:54

@currentoor Thanks, In fact, I had firstly found your blog post, then untangled and the Slack channel of it. There, some people told me you had moved to a new channel "fulcro", So I came here.😀

currentoor00:11:41

Oh lol, maybe I should update it then 😅

LL02:11:21

@tony.kay @currentoor Need help. when I added the websockets component into the system, get an error:

ExceptionInfo Missing dependency :handler of fulcro.websockets.components.channel_server.ChannelServer expected in system at :handler  clojure.core/ex-info (core.clj:4739)

LL02:11:16

(defn make-channel-server
  "Creates `ChannelServer`.
  Params:
  - `handshake-data-fn` (Optional) - Used by sente for adding data at the handshake.
  - `server-adapter` (Optional) - adapter for handling servers implemented by sente. Default is http-kit.
  - `client-id-fn` (Optional) - returns a client id from the request.
  - `dependencies` (Optional) - adds dependecies to the fulcro handler.
  - `valid-client-id-fn` (Optional) - Function for validating websocket clients. Expects a client-id.
  - `transit-handlers` (Optional) - Expects a map with `:read` and/or `:write` key containing a map of transit handlers,
  "
  [& {:keys [handshake-data-fn server-adapter client-id-fn dependencies valid-client-id-fn transit-handlers]}]
  (when valid-client-id-fn
    (reset! valid-client-id-atom valid-client-id-fn))
  (component/using
    (map->ChannelServer {:handshake-data-fn (or handshake-data-fn (fn [ring-req]
                                                                    (get (:headers ring-req) "Authorization")))
                         :server-adapter    (or server-adapter sente-web-server-adapter)
                         :client-id-fn      (or client-id-fn (fn [request]
                                                               (:client-id request)))
                         :transit-handlers  transit-handlers})
    (into [] (cond-> [:handler]
               dependencies (concat dependencies)))))

LL02:11:11

in

fulcro.websockets.components.channel-server

LL02:11:26

I think the example code in "fulcro/src/demos/cards/websocket_cards.cljs"

LL02:11:50

(core/make-fulcro-server
    ; provides the URI on which you've configured the client to connect:
    :extra-routes {:routes   [" " {[\"/chsk\"] :web-socket}]
                   :handlers {:web-socket cs/route-handlers}}
    ; Adds the components needed in order to establish and work with clients on persistent sockets
    :components {:channel-server   (cs/make-channel-server)
                 :channel-listener (wsdemo/make-channel-listener)}))

LL02:11:09

miss a

:components {:handler (easy-server/handler)....

LL02:11:03

I think this maybe come from the difference between new "fulcro-system" and old "make-fulcro-server".

LL02:11:03

Do the websockets component only work with easy-server?

tony.kay04:11:06

@tpliliang The websockets component is just a component. There IS an extra step that might not be in the docs correctly

tony.kay04:11:20

You should look at the demos…there is a websocket example that is working.

tony.kay04:11:39

The trick is that you have to post-initialize the websocket networking with the running app

tony.kay04:11:25

On the server side, basically you have to build the component as seen here: https://github.com/fulcrologic/fulcro/blob/develop/src/demos/recipes/websockets_server.clj

tony.kay04:11:12

And you need a server and listener

tony.kay04:11:53

The server comes from the library…you need both components in your components map

LL04:11:14

(defrecord ChannelServer [handler

LL04:11:37

ChannelServer needs a handler dependency.

tony.kay04:11:13

Oh, I see…yes, that is the API handler

tony.kay04:11:36

easy server makes that for you.

tony.kay04:11:48

modular server you build it your own server, you also build it

tony.kay04:11:55

that should be better documented 😕

tony.kay04:11:40

hmmm…I didn’t write the websockets support. To be honest I don’t remember what it uses out of the handler

LL04:11:33

this error is the sever side thing, I have written the channel listener, but the demo is just for easy-server/make-fulcro-system.

tony.kay04:11:00

hm. Yes, actually, now that I read the code, it seems to be pegged to easy-server

tony.kay04:11:11

it calls pre-hook, which isn’t available elsewhere

LL04:11:45

@tony.kay How I can modified the websockets channel server's code to make it work with core/fulro-server?

tony.kay04:11:00

So, here’s what I’d do… 1. open an issue so I don’t forget that it is outdated 🙂 2. Read this updated doc. It is in the 2.0 branch, but it is true for 1.x https://github.com/fulcrologic/fulcro/blob/2.0/src/devguide/fulcro_devguide/I_Building_A_Server.cljs (2) will tell you how to handle the API calls.

tony.kay04:11:26

Then you can kind of copy the code out of the channel server, and hook it up yourself, without all of the extra stuff

LL04:11:27

I think the :hander is moved to APIModule, when using fulro-server.

tony.kay04:11:04

unfortunately it is worse than that…handler as websockets is viewing it is a big thing that lets you hook components into the parsing env

tony.kay04:11:21

it’s trying to make sure parser injections work

tony.kay04:11:46

I think most of the code in channel server is what you want

tony.kay04:11:24

Yeah…I can probably make you something in a just a few minutes…hold on…

LL04:11:49

I added a new issue.

LL04:11:24

@tony.kay Thanks a lot.

tony.kay04:11:34

well, you’re testing it 😉

tony.kay04:11:06

@tpliliang ok, let me see if it compiles…

tony.kay04:11:30

ok, it compiles…that means it works, right? 😄

tony.kay04:11:11

I’m going to deploy it as 1.2.1-SNAPSHOT on clojars

tony.kay04:11:58

done….here is the new code:

tony.kay04:11:22

it makes a component that no longer depends on handler. Instead it uses the default fulcro server parser…meaning you use defmutation, defquery-root, etc. to handle API requests from the client

tony.kay04:11:38

The push behavior should not change

tony.kay05:11:05

oh wait…that can’t work 😞

tony.kay05:11:17

there’s nowhere to hook it into your ring stack…

LL05:11:23

@tony.kay I will read the code and document fisrt, Thanks for your help.

tony.kay05:11:47

I’m working on a demo so I can test it

tony.kay05:11:54

almost done

tony.kay05:11:19

the docs won’t get you there…Im having to read source code a bit

tony.kay05:11:11

well, almost done with the server-side..the demo will need a client side too…

tony.kay06:11:53

I need to update the readme and make it do more interesting things…but it’s a start, and it is connected via ws

tony.kay06:11:21

it shows you how to hook it into your own ring stack, and kind of bypasses both methods of constructing servers.

tony.kay06:11:18

it doesn’t do much but look for config and middleware, and start http-kit server

tony.kay06:11:35

handler is an unfortunate misnomer for a component that wraps a middleware function

LL06:11:59

@tony.kay Thanks, I will learn them now.

tony.kay06:11:07

@tpliliang the documentation about push in the guide should work. I just didn’t add any client stuff (or server stuff) to exercise it.

LL06:11:22

@tony.kay Got, I will try.

LL09:11:37

Is there the server side routing things in FulcroApiHandler?

claudiu09:11:12

@tpliliang by server side routing do you mean for SSR or custom handlers ? 🙂

LL09:11:34

routes for a Ring handler. @claudiu

LL10:11:27

@claudiu Yes, I had read them all, the wrap-api is come from FulcroApiHandler finally, https://github.com/fulcrologic/fulcro/blob/develop/src/main/fulcro/server.clj#L364

mitchelkuijpers15:11:34

I am running into this issue when trying to use fulcro-inspect:

events.cljs:83 Uncaught TypeError: Cannot read property 'addEventListener' of undefined
    at fulcro$inspect$ui$events$KeyListener.componentDidMount (events.cljs:83)
Any idea why @wilkerlucio? I am using shadow-cljs not sure if that is related

wilkerlucio15:11:02

hello Mitchel, I never tried it outside of figwheel and lein cljsbuild, can you try on figwheel and see if works there?

wilkerlucio15:11:54

but looking at the line, looks strange

wilkerlucio15:11:01

(componentDidMount [this]
    (if-let [matcher (parse-keystroke (-> this om/props ::keystroke))]
      (let [handler #(handle-event this %)
            {::keys [target event]} (om/props this)
            target (or target js/document.body)
            event  (or event "keydown")]
        (gobj/set this "matcher" {:handler handler
                                  :matcher matcher})
        (.addEventListener target event handler))))

wilkerlucio15:11:06

line 83 is the last one

wilkerlucio15:11:37

but there is an or that before (for target) should fallback to js/document.body, it's strange that you are seeing undefined there @mitchelkuijpers

wilkerlucio15:11:42

@mitchelkuijpers just came to my mind one thing, where are you putting your script inclusion on the HTML? it's on the <head> or at the end of <body>?

mitchelkuijpers15:11:19

I think undefined will not be false in clojurescript

mitchelkuijpers15:11:41

Hmm yes that works

mitchelkuijpers15:11:11

I have put the JS in the body tag btw

mitchelkuijpers15:11:28

at the end of the <body> tag

mitchelkuijpers15:11:57

@wilkerlucio it should be (.-body js/document) I think

wilkerlucio15:11:26

js/document.body works for sure (I use that syntax for a lot of things), which version of cljs are you using?

mitchelkuijpers15:11:44

That is weird because body is not a function

mitchelkuijpers15:11:58

Oh lol you are right

wilkerlucio15:11:06

if you look at my code, I'm not calling it

wilkerlucio15:11:16

just getting the value, there are no parentesis around

mitchelkuijpers15:11:31

Yes you are right

wilkerlucio15:11:17

glad in the body works 🙂

mitchelkuijpers15:11:32

But fulcro-inspect still fails 😞

wilkerlucio15:11:35

we could add code to wait for the dom to be ready, but I think just dropping on the body is simpler and faster

wilkerlucio15:11:50

what is happening now?

wilkerlucio15:11:55

still the same error?

wilkerlucio15:11:52

if you can try on figwheel, just so we know if is something related to shadow-cljs

mitchelkuijpers15:11:04

In another project we have figwheel and there it works

mitchelkuijpers15:11:16

I cannot build this project with figwheel because of the npm-deps

wilkerlucio15:11:55

I can't debug shadow-cljs now, but if you can figure it out I'll be happy to take a PR

mitchelkuijpers15:11:03

Ok thnx, no problem

mitchelkuijpers15:11:23

Ah this is interesting in firefox it works

wilkerlucio15:11:29

:thinking_face:

wilkerlucio15:11:15

so chrome is the one failing?

mitchelkuijpers15:11:05

Yes but i think I enabled a flag for async loading

mitchelkuijpers15:11:22

Not sure if true lol

mitchelkuijpers15:11:40

No firefox is also failing sorry for the noise I'll investigate further

tony.kay19:11:39

@tpliliang Ring routing is a ring issue. You build that yourself.

mitchelkuijpers19:11:45

@wilkerlucio It was a false alarm, shadow-cljs issue 😅

wilkerlucio20:11:31

@mitchelkuijpers thanks for the update, is there a way to make it work?

mitchelkuijpers20:11:54

Update shadow-cljs it was a regression. It would not put a return statement in certain cases