From 4a07d98fe9d4d442642a4886d497d73628be734a Mon Sep 17 00:00:00 2001 From: Nicholas Kariniemi Date: Mon, 21 Oct 2013 23:39:46 +0300 Subject: [PATCH] Refactor recipe view - remove dommy dependence --- src/cljs/grub/view/dom.cljs | 14 ++++++++++++++ src/cljs/grub/view/recipe.cljs | 20 +++++--------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/cljs/grub/view/dom.cljs b/src/cljs/grub/view/dom.cljs index a72d330..b6d0d89 100644 --- a/src/cljs/grub/view/dom.cljs +++ b/src/cljs/grub/view/dom.cljs @@ -104,12 +104,18 @@ (def new-recipe (make-recipe-node "new-recipe" "" "" true)) +(def new-recipe-done-btn + (sel1 new-recipe ".recipe-done-btn")) + (defn recipes-selector [] [(sel1 :#recipe-list) :.recipe-panel]) (defn recipe-done-btns-selector [] [(sel1 :body) :.recipe-done-btn]) +(defn recipe-done-btn-selector [recipe-elem] + (sel1 recipe-elem :.recipe-done-btn)) + (defn recipe-add-grubs-btns-selector [] [(sel1 :body) :.recipe-add-grubs-btn]) @@ -147,6 +153,14 @@ (defn clear-add-grub-text [] (dommy/set-value! add-grub-text "")) +(defn get-recipe-add-grubs-clicks [] + (->> (:chan (listen (recipe-add-grubs-btns-selector) :click)) + (a/map< #(dommy/closest (.-selectedTarget %) :.recipe-panel)))) + +(defn get-edit-recipe-input-click [] + (->> (:chan (listen-once (recipes-selector) :click)) + (a/filter< #(not (dommy/has-class? (.-selectedTarget %) :btn))) + (a/map< #(.-selectedTarget %)))) (defprotocol IHideable (-hide! [this]) diff --git a/src/cljs/grub/view/recipe.cljs b/src/cljs/grub/view/recipe.cljs index 8957c33..58ad4bd 100644 --- a/src/cljs/grub/view/recipe.cljs +++ b/src/cljs/grub/view/recipe.cljs @@ -1,9 +1,7 @@ (ns grub.view.recipe (:require [grub.view.dom :as dom] - [dommy.core :as dommy] [cljs.core.async :as a :refer [! chan]]) (:require-macros [grub.macros :refer [log logs and-let]] - [dommy.macros :refer [sel1]] [cljs.core.async.macros :refer [go go-loop]])) (defn wait-for-new-recipe-input-click [] @@ -26,9 +24,7 @@ {away-clicks :chan away-clicks-unlisten :unlisten} (dom/get-away-clicks dom/new-recipe) {done-clicks :chan - done-clicks-unlisten :unlisten} (dom/listen - (sel1 dom/new-recipe ".recipe-done-btn") - :click)] + done-clicks-unlisten :unlisten} (dom/get-clicks dom/new-recipe-done-btn)] (go (a/alts! [ctrl-enters away-clicks done-clicks]) (ctrl-enters-unlisten) (away-clicks-unlisten) @@ -51,9 +47,7 @@ out)) (defn wait-for-edit-recipe-input-click [] - (->> (:chan (dom/listen-once (dom/recipes-selector) :click)) - (a/filter< #(not (dommy/has-class? (.-selectedTarget %) :btn))) - (a/map< #(.-selectedTarget %)))) + (dom/get-edit-recipe-input-click)) (defn parse-update-recipe-event [elem] (let [id (.-id elem) @@ -72,9 +66,7 @@ {away-clicks :chan away-clicks-unlisten :unlisten} (dom/get-away-clicks elem) {done-clicks :chan - done-clicks-unlisten :unlisten} (dom/listen - (sel1 elem ".recipe-done-btn") - :click)] + done-clicks-unlisten :unlisten} (dom/get-clicks (dom/recipe-done-btn-selector elem))] (go (a/alts! [ctrl-enters away-clicks done-clicks]) (ctrl-enters-unlisten) (away-clicks-unlisten) @@ -97,11 +89,9 @@ (defn get-add-grub-events [] (let [out (chan) - clicks (:chan (dom/listen (dom/recipe-add-grubs-btns-selector) :click))] + recipe-add-grubs-clicks (dom/get-recipe-add-grubs-clicks)] (go-loop [] - (let [e (