A sample gist that can be loaded into the SCI Playground.
DON'T DELETE! - referred to by the playground.
A sample gist that can be loaded into the SCI Playground.
DON'T DELETE! - referred to by the playground.
Code related to my live coding recording, Fulcro live coding 3 - Simplify with UISM.
;; Based on https://github.com/borkdude/fly_io_clojure | |
(ns build | |
(:require [clojure.tools.build.api :as b])) | |
(def lib 'cz.holyjak.rohan-erp/app) | |
(def version "0.0.1") | |
(def class-dir "target/classes") | |
(def basis (b/create-basis {:project "deps.edn"})) | |
(def uber-file (format "target/%s-%s-standalone.jar" (name lib) version)) | |
(def jar-file (format "target/%s-%s.jar" (name lib) version)) |
## | |
## Install FE dependencies ## | |
## | |
FROM node:19.4.0 AS npm | |
WORKDIR /opt | |
COPY package.json yarn.lock ./ | |
RUN yarn install | |
## | |
## BUILD BE ## |
Various, unsorted notes from using and struggling with Pathom 3 with Fulcro.
When something doesn’t work, I try to simplify it as much as possible. Often it starts working at some point. Then I try to find the exact point where it starts/stop working by bringing the broken and working alternatives closer together. And this is exactly what I did when my auto-generated RAD id-resolver did not return the expected data. It might be useful to know the steps along this path for any future troubleshooting.
This problem has two dimensions - the parser and the resolver. Here I move mostly along the parser dimension, while in the end I discovered the problem was with the resolver. Still, it is a valuable knowledge.
Complexity is the root of all evil. So how do we make simple webapps in Fulcro?
The key here is I think a good separation of concerns. In particular:
Separate rendering and business logic. Render functions (i.e. defsc
bodies) contain no or minimal logic, ideally at most simple conditionals or applications of external, pure functions that produce in-line derived data (that is not worth pre-computing externally). This is partially enabled by the fact that props are optimized for the UI, i.e. they contain exactly the data the components need. Pathom is the "backend for frontend" responsible for returning the data in the optimal tree shape but also with the optimal content, adapting from the general domain data (as stored in a database) to the specific UI needs. Changes to the state and side-effects are triggered from the UI but defined and processed externally. They are defined by Fulcro mutations, "transacted" as data, and processed separately, with hooks for customization of the process. Finally, any
;; Example of using forwardRef and passing the result to a HoC JS component | |
;; ... | |
(defn shallow-js->clj [^js obj] | |
(persistent! | |
(reduce (fn [r k] (assoc! r (keyword k) (gobj/get obj k))) | |
(transient {}) (js-keys obj)))) | |
;; My Fulcro component that needs a DOMElement ref and is passed to the JS HoC | |
(defsc MyDropdownList [this {:dropdown/keys [text] :as props}] ; Fulcro props |
;; A macro to create a decorator (wrapper) for a objects implementing a Java interface | |
;; Disclaimer: The code most certainly is not perfect and does not handle some corner cases | |
;; License: The Unlicense http://unlicense.org/ | |
(require '[clojure.string :as str]) | |
(defn type->tag [parameter-type] | |
(let [array? (-> parameter-type name (str/ends-with? "<>")) | |
primitive? '#{int long float double short boolean byte char} | |
type (if array? | |
(-> parameter-type name (str/replace #"<>$" "") symbol) |
Many thanks to Francis Avila (favila) and others.
The on-prem docs recommend to use idents to represent enums though this advice likely dates from before d/pull and attribute+entity predicates.
Ident