Skip to content

Commit

Permalink
parallel cursor, test sql join
Browse files Browse the repository at this point in the history
  • Loading branch information
leonoel committed Jan 26, 2024
1 parent 3da6758 commit 6ed375f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/hyperfiddle/electric_de.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,17 @@
`(ctor
(let [~@(interleave bs (eduction (map #(list ::lang/lookup %)) (range)))]
~@body)))
(defmacro cursor [[sym v] & body] `(call (r/bind-args (fn [~sym] ~@body) (r/fixed-signals (join (i/items (pure ~v)))))))

(defmacro diff-by [f xs] `(join (i/diff-by ~f (join (i/items (pure ~xs))))))
;; (defmacro drain [expr] `(join (i/drain (pure ~expr))))
(defmacro client [& body] `(::lang/site :client ~@body))
(defmacro server [& body] `(::lang/site :server ~@body))

(defmacro cursor [bindings & body]
(case bindings
[] `(do ~@body)
(let [[args exprs] (apply map vector (partition-all 2 bindings))]
`(call (r/bind-args (fn ~args ~@body)
~@(map (clojure.core/fn [expr]
`(r/fixed-signals (join (i/items (pure ~expr)))))
exprs))))))
25 changes: 25 additions & 0 deletions test/hyperfiddle/electric/impl/runtime_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,28 @@
% := {:degree 21, :permutation {}, :grow 1, :shrink 0, :change {20 [21 "Fizz"]}, :freeze #{}}
(reset! !fizz "Fuzz")
% := {:degree 21, :permutation {}, :grow 0, :shrink 0, :change {20 [21 "Fuzz"], 2 [3 "Fuzz"], 5 [6 "Fuzz"], 8 [9 "Fuzz"], 11 [12 "Fuzz"], 14 [15 "FuzzBuzz"], 17 [18 "Fuzz"]}, :freeze #{}})

(tests
(def !animals
(atom [{:name "betsy" :owner "brian" :kind "cow"}
{:name "jake" :owner "brian" :kind "horse"}
{:name "josie" :owner "dawn" :kind "cow"}]))
(def !personalities
(atom [{:kind "cow" :personality "stoic"}
{:kind "horse" :personality "skittish"}]))
(on-diff! rcf/tap
(root-frame
(let [ks #{:kind}]
(e/cursor [animal (e/diff-by identity (e/watch !animals))
personality (e/diff-by identity (e/watch !personalities))]
(if (= (select-keys animal ks) (select-keys personality ks))
(merge animal personality) (e/amb))))))
% := {:degree 3, :permutation {}, :grow 3, :shrink 0, :freeze #{},
:change {0 {:name "betsy", :owner "brian", :kind "cow", :personality "stoic"},
1 {:name "jake", :owner "brian", :kind "horse", :personality "skittish"},
2 {:name "josie", :owner "dawn", :kind "cow", :personality "stoic"}}}
(swap! !animals conj {:name "bob" :owner "jack" :kind "horse"})
% := {:degree 4, :permutation {}, :grow 1, :shrink 0, :freeze #{},
:change {3 {:name "bob", :owner "jack", :kind "horse", :personality "skittish"}}}
(swap! !animals pop)
% := {:degree 4, :permutation {}, :grow 0, :shrink 1, :change {}, :freeze #{}})

0 comments on commit 6ed375f

Please sign in to comment.