mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 08:50:57 -05:00
29 lines
572 B
Text
29 lines
572 B
Text
|
(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)))
|