0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 00:40:30 -05:00
penpot/frontend/uxbox/util/lens.cljs
2015-12-30 00:19:47 +02:00

28 lines
572 B
Clojure

(ns uxbox.util.lens
(:refer-clojure :exclude [derive])
(:require [cats.labs.lens :as l]))
(defn dep-in
[where link]
{:pre [(vector? where) (vector? link)]}
(l/lens
(fn [s]
(let [value (get-in s link)
path (conj where value)]
(get-in s path)))
(fn [s f]
(throw (ex-info "Not implemented" {})))))
(defn getter
[f]
(l/lens f #(throw (ex-info "Not implemented" {}))))
(defn derive
[a path]
(l/focus-atom (l/in path) a))
(defn focus
([state]
(l/focus-atom l/id state))
([lens state]
(l/focus-atom lens state)))