                                              (-> (js* "this")
                                                  .-allNeighborsIndex
                                                  (aget node-id)
-                                                 goog.object/getKeys)) ; The graph keeps the neighbors as properties
+                                                 gobject/getKeys)) ; The graph keeps the neighbors as properties
                                            ))
 
 

(ns tropology.core
  (:require [reagent.core :as reagent :refer [atom]]
            [secretary.core :as secretary]
            [reagent.session :as session]
            [reagent-forms.core :refer [bind-fields]]


    ))

(defn redraw-graph [trope-code]
  (let [current (:sigma @state)]                            ; Must be set by importer on creation
    (if current
      (do
        (.kill current)
        (swap! state assoc :sigma nil)))
    ; (create-graph (-> (.getElementById js/document "trope-code") .-value))
    (create-graph trope-code)
    ))


(defn list-tropes [trope-code]
  (.log js/console trope-code))


(def trope-code-form
  [:div
   (text-input :trope-code "Article code:")])


(defn trope-data []
  (let [form-data (atom {})]
    (fn []
      [:div
       [bind-fields trope-code-form form-data]
       (cond
         (= :home (session/get :page)) [:div
                                        [:input {:type     "button"
                                                 :value    "Graph!"
                                                 :on-click #(redraw-graph (:trope-code @form-data))}]
                                        [:div {:id "graph-container"}]]
         (= :tropes (session/get :page)) [:div
                                          [:input {:type     "button"
                                                   :value    "List tropes"
                                                   :on-click #(list-tropes (:trope-code @form-data))}]
                                          [:div {:id "trope-list-container"}]]
         :else "Nope"
         )])
    ))


(def pages
  {:home   trope-data
   :tropes trope-data
   :about  about-page})


(defn page []
  [(pages (session/get :page))])

(defroute "/" [] (session/put! :page :home))
(defroute "/tropes" [] (session/put! :page :tropes))
(defroute "/about" [] (session/put! :page :about))


