Skip to content

Instantly share code, notes, and snippets.

View holyjak's full-sized avatar
💓
Loving Clojure

Jakub Holý holyjak

💓
Loving Clojure
View GitHub Profile
@holyjak
holyjak / about-sci-playground-demo-gist.md
Last active October 3, 2023 07:57
SCI Playground demo gist

A sample gist that can be loaded into the SCI Playground.

DON'T DELETE! - referred to by the playground.

@holyjak
holyjak / about.md
Created March 4, 2023 15:04
Fulcro live coding 3 - Simplify with UISM - files
;; 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 ##
@holyjak
holyjak / pathom3_lab_notes.adoc
Last active April 13, 2024 07:25
Pathom3 + Fulcro Lab Notes - experiences and tips from working with Pathom 3 with Fulcro

Various, unsorted notes from using and struggling with Pathom 3 with Fulcro.

Troubleshooting P3/F

Troubleshooting auto-generated Fulcro RAD id resolvers in Pathom 3

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

@holyjak
holyjak / tmp_fulcro_forwardRef.cljs
Last active July 11, 2022 06:26
TMP: Example of using forwardRef and passing the result to a HoC JS component
;; 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
@holyjak
holyjak / defdecorator.clj
Last active October 15, 2021 13:59
Macro to create a decorator (wrapper) for a objects implementing a Java interface
;; 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)

Notes from playing with Datomic

Many thanks to Francis Avila (favila) and others.

Enums: idents vs. type/keyword

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

@holyjak
holyjak / advanced-minimalist-fulcro-tutorial.adoc
Last active September 17, 2021 21:48
Advanced Minimalist Fulcro Tutorial, a follow-up to the Minimalist Fulcro Tutorial

TODO

  • form state

    • tmpids and entity creation

  • dynamic routing

  • UISM

  • Union, recursive, dynamic query

  • Returning data from mutation

  • component.raw