Skip to content

Commit

Permalink
voltei pra utilizar estado local no input ... solucionei o problema a…
Browse files Browse the repository at this point in the history
…tualizando o campo com r/with-let ... outra formatacao
  • Loading branch information
interstar committed Jul 5, 2018
1 parent 7660ff3 commit 883a514
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 44 deletions.
7 changes: 5 additions & 2 deletions resources/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
<html lang="en">
<head>
<meta charset='utf-8'>


<style>
.negative {color: red;}
body {font-family : Impact, Charcoal, sans-serif; }
</style>

</head>
<body>
<div id="app"></div>
Expand Down
3 changes: 1 addition & 2 deletions src/cljs/contascalangos/db.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns contascalangos.db)

(def default-db
{:name "re-frame"
:tmp-val ""
{:name "Contas do Calango"
:orcamento '(100 -20 120 -30 -40 -15 20)})
13 changes: 3 additions & 10 deletions src/cljs/contascalangos/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,11 @@
(assoc db :active-panel active-panel)))

(re-frame/reg-event-db
:adicionar
(fn [coeffects event]
:adicionar
(fn [coeffects event]
(let [db (:db coeffects)
novo-valor (:tmp-nova db)
novo-valor (second event)
itens (:orcamento db)]
{:db (assoc db :orcamento (cons novo-valor itens))}
)
))

(re-frame/reg-event-db
:tmp-nova
(fn [coeffects event]
(let [db (:db coeffects)]
{:db (assoc db :tmp-nova (second event))}
)) )
8 changes: 2 additions & 6 deletions src/cljs/contascalangos/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@
(fn [db]
(:name db)))

(re-frame/reg-sub
::orc
(re-frame/reg-sub
::orc
(fn [db] (:orcamento db))
)

(re-frame/reg-sub
::active-panel
(fn [db _]
(:active-panel db)))

(re-frame/reg-sub
::tmp-nova
(fn [db] (:tmp-nova db)))
58 changes: 34 additions & 24 deletions src/cljs/contascalangos/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,46 @@
;; home

(defn home-panel []
(let [name (re-frame/subscribe [::subs/name])
orcamento (re-frame/subscribe [::subs/orc])
nova (re-frame/subscribe [::subs/tmp-nova])]
[:div
[:h1 (str "Olá Calangos do " @name)]

[:div
[:ul
(for [item @orcamento] [:li item])
]
]

[:div (apply + @orcamento)]

[:div
(let [name (re-frame/subscribe [::subs/name])
orcamento (re-frame/subscribe [::subs/orc]) ]
(r/with-let [nova (r/atom 0)]
[:div
[:h2 (str @name)]

[:div
[:table
[:tr [:td "Receita"] [:td "Gasta"]]

(for [item @orcamento]
(if (< 0 item)
[:tr
[:td item] [:td] ]
[:tr
[:td]
[:td
[:span {:class "negative"} item]]]))
]
]


[:div [:h3 "Total : " (apply + @orcamento)]]

[:div
[:input {:type "text"
:value @nova
:on-change #(re-frame/dispatch [:tmp-nova (-> % .-target .-value)] )
}]
:value @nova
:on-change #(reset! nova (-> % .-target .-value))
}]

[:button {:on-click #(re-frame/dispatch [:adicionar ])} "Adicionar" ]
[:button {:on-click #(re-frame/dispatch [:adicionar (int @nova)])} "Adicionar" ]

]
]


[:div
[:a {:href "#/about"}
"go to About Page"]]
[:div
[:a {:href "#/about"}
"go to About Page"]]

]))
])))


;; about
Expand Down

0 comments on commit 883a514

Please sign in to comment.