Fork me on GitHub
#fulcro
<
2017-12-13
>
wilkerlucio00:12:17

@roklenarcic if you want to do that now, just create this om.next namespace on your project (importing pathom and Fulcro 2.0, but not om.next)

wilkerlucio00:12:36

(ns om.next
  (:require [fulcro.client.primitives :as fp]))

; pathom depends on some om.next functions, since Fulcro 2.0 removed the om.next namespaces
; this ns makes the linkage back so pathom keep compatibility

(def parser fp/parser)
(def ast->query fp/ast->query)
(def get-query fp/get-query)
(def tree->db fp/tree->db)
(def query->ast fp/query->ast)
(def tempid? fp/tempid?)

wilkerlucio00:12:49

^^^ those are enough to make pathom happy

LL09:12:09

@tony.kay I had read the sections (H02_Making_An_Easy_Server, H45, and I), but sorry, I cannot found any info about websocket channel server. I had read the code of the fulcro.websockets.components.channel-server, but cannot get any idea how to inject db component into env. Could you gave me tips?

piotrek14:12:47

@tpliliang I think you need to setup the component for your Datomic connection similarly to https://github.com/fulcrologic/fulcro/blob/901f58f2fe0bd784fd9b8463aeb03f628a53ccc7/src/devguide/fulcro_devguide/H45_Customizing_Easy_Server.cljs#L71-L91 and include that component under a key in your system map. Then you need to add your Datomic connection component key to parser-injections in make-fulcro-server

piotrek14:12:21

This is an example of a database seeder component you can modify to create a Datomic one:

(defrecord Seeder [databases]
  component/Lifecycle
  (start [this]
    (if-let [people-db (sql/get-dbspec databases :people)]
      (jdbc/with-db-transaction [db people-db]
        (let [nrows (jdbc/query db ["SELECT COUNT(*) AS cnt FROM person"] {:row-fn :cnt :result-set-fn first})]
          (when (zero? nrows)
            (timbre/info "People database is empty. Seeding some initial data")
            (sql/seed! people-db schema
              [(sql/seed-row :duty {:id :id/sweep :name "Sweep"})
               (sql/seed-row :duty {:id :id/mop :name "Mop"})
               (sql/seed-row :duty {:id :id/code :name "Code"})
               (sql/seed-row :duty {:id :id/drink-beer :name "Drink Beer"})
               (sql/seed-row :job {:id :id/janitor :title "Janitor"})
               (sql/seed-row :job {:id :id/programmer :title "Programmer"})
               (sql/seed-row :job_duties {:id :join-1 :job_id :id/janitor :duty_id :id/mop})
               (sql/seed-row :job_duties {:id :join-2 :job_id :id/janitor :duty_id :id/sweep})
               (sql/seed-row :job_duties {:id :join-3 :job_id :id/programmer :duty_id :id/drink-beer})
               (sql/seed-row :job_duties {:id :join-4 :job_id :id/programmer :duty_id :id/code})
               (sql/seed-row :person {:id :sally :name "Sally" :age 41 :person/current_job_id :id/janitor})
               (sql/seed-row :person {:id :renee :name "Renee" :age 28 :person/current_job_id :id/programmer})]))))
      (timbre/error "Unable to get injected database :people"))
    this)
  (stop [this] this))

(defn build-server
  [{:keys [config] :or {config "config/dev.edn"}}]
  (make-fulcro-server
    :parser-injections #{:config :databases}
    :components {:databases (component/using (sql/build-db-manager {})
                              [:config])}
    :config-path config))

LL01:12:11

Thanks, but I need use the websocket channel. I think make-fulcro-server make itself component/system-map, which has a component "handler".

LL01:12:48

there is a custom "handler", I don't know if the two "handler" can work together and how?

tony.kay16:12:04

@tpliliang If you're using websockets you have two choices: easy server with components and parser injections, or what I did in the websockets demo. The websockets demo leaves it up to you to create and pass in things in the env, however you see fit. If you're using the simple channel server, then this line of code is where it is making the env for parsing: https://github.com/fulcrologic/fulcro/blob/develop/src/main/fulcro/websockets/components/channel_server.clj#L283 You can either custom build your own channel server code, OR, more easily, tack your extra stuff onto the Ring request (since it is already being plugged into the env). In the websockets demo, you could do that here: https://github.com/fulcrologic/websocket-demo/blob/master/src/main/websocket_demo/server.clj#L31

tony.kay16:12:57

actually, in any scenario where you build onto the Ring stack you can add to the request, and the request will be in the parsing env.

tony.kay17:12:07

Fulcro-css 2.0.0 (final) released on clojars. It really didn't have changes other than deps, so it should be solid and stable.

tony.kay18:12:33

Fulcro 2.0.0-beta7 on clojars. There was a somewhat intrusive addition around mutation return value on the new mutation join support that allows you to target the result of the mutation (like load targeting). It is pretty heavily tested by @wilkerlucio, but it does touch the parser code...so there is a chance it could break something completely unrelated...doubtful, but always possible. Please let us know if it does.

wilkerlucio18:12:28

cool, I'll start using that in prod soon, if there are regressions we should find out soon enough, if other can try too would be great 🙂

tony.kay18:12:48

I'm planning on cutting an RC this week. Everything I set out to do with 2.0 is pretty much done, and the docs are updated. Forms are stable, but the docs do mention I'm exploring a new simpler approach. No guarantees on the new one, but the old one works and will be supported into the forseeable future.

tony.kay19:12:36

The templates are all updated. Spec works as well as it ever did. Dependent libraries all have updated versions. I'll try to release them all as RC1 together if they are in beta.

tony.kay19:12:40

NOTE: I tried to do the Om Compat library this morning. Protocols make it impossible for a truly general case as far as I can tell. If you want to use an Om Next library that does not use protocols, then you can simple create the om next namespaces with the functions you need and proxy them over to primitives.

tony.kay19:12:51

Technically, if you use fulcro's new namespaces in standard Om Next examples, I think they should actually work just fine...thus, any library can be pretty trivially forked/ported with the rename-ns script I think (in the 2.0 README)...

tony.kay19:12:15

I don't think there is too much in the Om Next ecosystem. It is too hard to write something because of all of the options/knobs. The libraries can't easily be full-stack. UI libraries can't really rely on parser details...etc.

wilkerlucio20:12:01

hey, question

wilkerlucio20:12:13

do you use the regular parser on your fulcro server backend?

wilkerlucio20:12:37

I just notice that results of mutations from there are not wrapped on the :result key, but on my pathom parser they are

wilkerlucio20:12:57

are you doing something special around the mutation returns?

mitchelkuijpers20:12:33

I have one question, when I do server reads should the form state query keys be excluded automatically?

mitchelkuijpers20:12:09

Had to add them to exclusions manually today not sure if that's intentionally

claudiu20:12:56

https://clojureverse.org/t/on-meteor-and-clojure/1189 seems like a scenario where fulcro shines. Added my 2 cents, but haven't built stuff that advanced with fulcro yet, really curious how this thread evolves 🙂

adamvh22:12:46

is there a way to use component-local state with defsc?

wilkerlucio23:12:29

@tony.kay I was implementing my error story with the new mutation target, but soon I noticed that without the refs on the mutations it would get very annoying to do (because without ref I can't use my generic mutation operations, they need a target). so I made this PR to start remembering the ref on all the transactions in ptransact! https://github.com/fulcrologic/fulcro/pull/98