<commit_before>(ns conedit.main
  (:require [goog.dom :as gdom]
            [om.next :as om :refer-macros [defui]]
            [om.dom :as dom]))


(def app-state
  (atom {
         :resources
         [{:name "pivnet-master"}
          {:name "pivnet-develop"}
          ]}))

(declare reconciler)


(defui ResourceItem
  Object
  (render [this]
    (dom/li nil (:name (om/props this)))))

(def resource-item (om/factory ResourceItem {:keyfn :name}))

(defui ResourceList
  Object
  (render [this]
    (dom/ul nil
      (map resource-item (om/props this))
      (dom/button
        #js {:onClick #(om/transact! reconciler '[(add-resource)])}
        "Add"))))

(def resource-list (om/factory ResourceList))

(defui App
  static om/IQuery
  (query [this]
    [:resources])
  Object
  (render [this]
    (dom/div nil (resource-list (:resources (om/props this))))))

; env is more than just the app-atom
(defn read [{:keys [state] :as env} key params]
  (let [data @state]
    (if-let [[_ resources] (find data key)]
      {:value resources}
      {:value :not-found})))

(defn mutate [{:keys [state] :as env} key params]
  {:action #(swap! state update-in [:resources] conj {:name "New!"})}
  )

(def reconciler
  (om/reconciler {:state  app-state
                  :parser (om/parser {:read read :mutate mutate})}))

(om/add-root! reconciler
  App (gdom/getElement "app"))


(comment
<commit_msg>Trying to nest queries.. a little hard<commit_after>(ns conedit.main
  (:require [goog.dom :as gdom]
            [om.next :as om :refer-macros [defui]]
            [om.dom :as dom]))

(enable-console-print!)


(def app-state
  (atom {
         :resources
         [{:name "pivnet-master"}
          {:name "pivnet-develop"}
          ]}))

(defui ResourceItem
  static om/IQuery
  (query [this]
    [:name])
  Object
  (render [this]
    (dom/li nil (str (:name (om/props this)) " " (:foo (om/props this))))))

(def resource-item (om/factory ResourceItem {:keyfn :name}))

(defui ResourceList
  static om/IQuery
  (query [this]
    [{:resources (om/get-query ResourceItem)}])
  Object
  (render [this]
    (dom/ul nil
      (map resource-item (:resources (om/props this)))
      (dom/button
        #js {:onClick #(om/transact! reconciler '[(add-resource)])}
        "Add"))))

(def resource-list (om/factory ResourceList))

(defui App
  static om/IQuery
  (query [this]
    [{:root-resources (om/get-query ResourceList)}])
  Object
  (render [this]
    (dom/div nil (resource-list (:root-resources (om/props this))))))


(defmulti read (fn [env key params] key))

(defmethod read :default [{:keys [state] :as env} key params]
  (let [data @state]
    (if-let [[_ value] (find data key)]
      {:value value}
      {:value :not-found})))

(defmethod read :root-resources [{:keys [state] :as env} key params]
  {:value {:resources (:value (read env :resources params))}})


(defn mutate [{:keys [state] :as env} key params]
  {:action #(swap! state update-in [:resources] conj {:name "New!"})}
  )

(def reconciler
  (om/reconciler {:state  app-state
                  :parser (om/parser {:read read :mutate mutate})}))

(om/add-root! reconciler
  App (gdom/getElement "app"))


(comment

{'fraction_non_alphanumeric': 0.16870876531573986, 'fraction_numerical': 0.0, 'mean_word_length': 2.9651307596513075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2236828', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1109, 'n_words': 317}