Skip to content

Instantly share code, notes, and snippets.

View wilkerlucio's full-sized avatar

Wilker Lúcio wilkerlucio

View GitHub Profile
@wilkerlucio
wilkerlucio / pathom-fulcro3.cljs
Created July 30, 2020 14:03
Example of Pathom with Fulcro 3
(defn pathom-remote [parser]
{:transmit! (fn transmit! [_ {::txn/keys [ast result-handler]}]
(let [edn (eql/ast->query ast)
ok-handler (fn [result]
(try
(result-handler (assoc result :status-code 200))
(catch :default e
(js/console.error e "Result handler for remote failed with an exception."))))
error-handler (fn [error-result]
(try
@wilkerlucio
wilkerlucio / pathom-persistent-cache.clj
Last active March 3, 2020 13:42
Pathom cache extension example
(defn cache-resolver [resolver]
(update resolver ::pc/resolve
(fn [resolve]
(fn [{::keys [persistent-cache*] :as env} input]
(let [cache-key [(::pc/sym resolver) input (p/params env)]]
(if-let [[_ v] (find @persistent-cache* cache-key)]
v
(let [response (resolve env input)]
(swap! persistent-cache* assoc cache-key response)
response)))))))
@wilkerlucio
wilkerlucio / check-component.cljs
Created November 2, 2018 02:12
Generative testing for fulcro components
(ns your-ns
(:require [clojure.test.check.properties :as prop]
[com.wsscode.pathom.gen :as sgen]
[cljs.test :refer [is]]
[clojure.test.check.generators :as gen :include-macros true]
[fulcro.client.primitives :as fp]
[clojure.test.check :as tc]
[fulcro.client.mutations :as fm]
[clojure.data :as data]))
/*! tether 1.4.4 */
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root.Tether = factory();
}
[{:com.wsscode.pathom.trace/event
:com.wsscode.pathom.parser/parse-loop,
:com.wsscode.pathom.trace/timestamp-leave 1535741953047,
:com.wsscode.pathom.trace/timestamp 1535741952740,
:com.wsscode.pathom.core/path [],
:com.wsscode.pathom.trace/relative-timestamp 0,
:com.wsscode.pathom.trace/duration 307}
{:key :fulcro.inspect.workspaces.ui.pathom-trace-cards/color,
:com.wsscode.pathom.trace/event
:com.wsscode.pathom.parser/process-key,
(om/defui ^:once QueuedVideo
static uc/InitialAppState
(initial-state [_ title] {::video/id (random-uuid)
::video/title title})
static om/IQuery
(query [_] [::video/id
::video/watched?
{::video/snippet
[::video/title
(om/defui ^:once QueuedVideo
static uc/InitialAppState
(initial-state [_ title] {::video/id (random-uuid)
::video/title title})
static om/IQuery
(query [_] [::video/id
::video/watched?
{::video/snippet
[::video/title
(ns ygq.background.main
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [cljs.core.async :as async :refer [<!]]
[chrome.rpc :as rpc]
[ygq.background.parser :as p]
[google.api :as g]))
(defonce comm-listener
(go
(let [rpc (rpc/listen (async/chan 10))
(ns ygq.popup.core
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [untangled.client.core :as uc]
[cljs.core.async :as async :refer [<!]]
[chrome.rpc :as rpc]
[google.api :refer [get-auth-token]]
[untangled.client.network :as un]))
(defrecord Network [complete-app]
un/NetworkBehavior
(ns common-spec.coerce
(:refer-clojure :exclude [def])
(:require [clojure.spec.alpha :as s]
[clojure.walk :as walk])
(:import (java.util UUID)))
(s/def ::coerce-fn
(s/fspec :args (s/cat :x string?) :ret any?))
(defonce ^:private registry-ref (atom {}))