Created
May 17, 2015 03:42
-
-
Save geraldodev/8cc13737f6574c900ec2 to your computer and use it in GitHub Desktop.
playing with passing the value of get and get-in as a vector where [slice-of-the-value keys-used]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns manutencao.core | |
(:require [brutha.core :as br] | |
[flupot.dom :as dom])) | |
(def state (atom {:some-context {:client {:name "geraldo"}}})) | |
(def input-widget | |
(br/component | |
(fn [[value ks]] | |
(dom/input {:value value | |
:onChange | |
(fn [e] | |
(swap! state assoc-in ks (.-value (.-target e))))})))) | |
(defn slice | |
([value k ks] | |
(if (sequential? k) | |
[(get-in value k) (into ks k)] | |
[(get value k) (into ks [k])])) | |
([value k] | |
(slice value k []))) | |
(def client-widget | |
(br/component | |
(fn [[client ks]] | |
(dom/div | |
(dom/div "Name" | |
(input-widget (slice client :name ks))) | |
(dom/div "Address" | |
(input-widget (slice client :address ks))))))) | |
(let [app-el (js/document.getElementById "app")] | |
(defn app [] | |
(br/mount (client-widget (slice @state [:some-context :client])) app-el) | |
(js/setTimeout app 16))) | |
(app) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment