mirror of
https://github.com/penpot/penpot.git
synced 2025-05-22 13:06:12 +02:00
♻️ Make the namespacing independent of the branding.
This commit is contained in:
parent
aaf8b71837
commit
6c67c3c71b
305 changed files with 2399 additions and 2580 deletions
65
frontend/src/app/util/object.cljs
Normal file
65
frontend/src/app/util/object.cljs
Normal file
|
@ -0,0 +1,65 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2020 UXBOX Labs SL
|
||||
|
||||
(ns app.util.object
|
||||
"A collection of helpers for work with javascript objects."
|
||||
(:refer-clojure :exclude [set! get get-in assoc!])
|
||||
(:require
|
||||
[cuerdas.core :as str]
|
||||
[goog.object :as gobj]
|
||||
["lodash/omit" :as omit]))
|
||||
|
||||
(defn get
|
||||
([obj k]
|
||||
(when-not (nil? obj)
|
||||
(unchecked-get obj k)))
|
||||
([obj k default]
|
||||
(or (get obj k) default)))
|
||||
|
||||
(defn get-in
|
||||
[obj keys]
|
||||
(loop [key (first keys)
|
||||
keys (rest keys)
|
||||
res obj]
|
||||
(if (nil? key)
|
||||
res
|
||||
(if (nil? res)
|
||||
res
|
||||
(recur (first keys)
|
||||
(rest keys)
|
||||
(unchecked-get res key))))))
|
||||
|
||||
(defn without
|
||||
[obj keys]
|
||||
(let [keys (cond
|
||||
(vector? keys) (into-array keys)
|
||||
(array? keys) keys
|
||||
:else (throw (js/Error. "unexpected input")))]
|
||||
(omit obj keys)))
|
||||
|
||||
(defn merge!
|
||||
([a b]
|
||||
(js/Object.assign a b))
|
||||
([a b & more]
|
||||
(reduce merge! (merge! a b) more)))
|
||||
|
||||
(defn set!
|
||||
[obj key value]
|
||||
(unchecked-set obj key value)
|
||||
obj)
|
||||
|
||||
(defn- props-key-fn
|
||||
[key]
|
||||
(if (or (= key :class) (= key :class-name))
|
||||
"className"
|
||||
(str/camel (name key))))
|
||||
|
||||
(defn clj->props
|
||||
[props]
|
||||
(clj->js props :keyword-fn props-key-fn))
|
Loading…
Add table
Add a link
Reference in a new issue