Skip to content

Instantly share code, notes, and snippets.

@geraldodev
Created January 19, 2014 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldodev/8512669 to your computer and use it in GitHub Desktop.
Save geraldodev/8512669 to your computer and use it in GitHub Desktop.
(defn concat-korks
[korks k2orks]
(if-not (sequential? korks)
(if-not (sequential? k2orks)
[korks k2orks]
(if (list? k2orks)
(conj k2orks korks)
(into [korks] k2orks)))
(if (list? korks)
(if-not (sequential? k2orks)
(into (list k2orks) korks)
(if (list? k2orks)
(into k2orks korks)
(into (seq k2orks) korks)))
(if-not (sequential? k2orks)
(conj korks k2orks)
(into korks k2orks)))))
;Test:)
(defn test-concat-korks
[]
(is (= [:one :two] (concat-korks :one :two)))
(is (= [:one :two] (concat-korks [:one] [:two])))
(is (= [:one :two] (concat-korks [:one] '(:two))))
(is (= [:one :two] (concat-korks [:one] :two)))
(is (= [:one :two] (concat-korks :one [:two])))
(is (= '(:one :two) (concat-korks :one '(:two))))
(is (= '(:one :two) (concat-korks '(:one) :two)))
(is (= '(:one :two) (concat-korks '(:one) '(:two))))
(is (= '(:one :two) (concat-korks '(:one) [:two]))))
(defn get-state
"Takes a pure owning component and sequential list of keys and
returns a property in the component local state if it exists. Will
never return pending state values."
([owner] (aget (.-state owner) "__om_state"))
([owner korks]
(cond
(not (sequential? korks))
(get (aget (.-state owner) "__om_state") korks)
(empty? korks)
(get-state owner)
:else
(get-in (aget (.-state owner) "__om_state") korks)))
([owner korks k2orks]
(get-state owner (concat-korks korks k2orks))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment