Very rough sketch of a beginning, not even nearly doing anything interesting.

This commit is contained in:
Simon Brooke 2016-02-15 14:53:33 +00:00
parent 9fe52661f7
commit 1e989616d7
45 changed files with 1230 additions and 329 deletions

View file

@ -1,18 +1,70 @@
(ns mw3.core
(ns ^:figwheel-always mw3.core
(:require [om.core :as om :include-macros true]
[om.dom :as dom :include-macros true]))
[om.dom :as dom :include-macros true]
[cljs.core.async :refer [put! chan <!]]
[clojure.string :as string]))
(enable-console-print!)
(defonce app-state (atom {:text "Hello Chestnut!"}))
;; The state of the application.
;; NOTE that app-state can contain vectors and maps only, not lists.
(defonce app-state (atom {:available-tabs {:#home-tab :#home-content
:#params-tab :#params-content
:#rules-tab :#rules-content
:#world-tab :#world-content
:#docs-tab :#docs-content}
:selected-tab :#home-tab
:text "Welcome to MicroWorld!"
:rules []
:params {:available-rulesets []
:available-heightmaps []
:ruleset ""
:heightmap ""}
:world []}))
(defn root-component [app owner]
(deref app-state)
(:available-tabs (deref app-state))
(defn root-component [data owner]
(reify
om/IRender
(render [_]
(dom/div nil (dom/h1 nil (:text app))))))
(dom/div nil (dom/h1 nil (:text data))))))
(defn tab-bar [data owner]
(reify
om/IInitState
(init-state [_]
{:selected-tab :#home-tab
:selected-content :#home-content})
om/IRender
(render [this]
(dmu/ul nil
)))
(def pages [:#home-content :#params-content :#rules-content :#world-content :#docs-content])
(defn onclick-handler
"Handles a click on the specified `tab` and reveals the specified `content`."
[tab content]
(doseq [page pages]
(dommy/hide!(sel page)))
(dommy/show! content))
;; NASTY! Javascript interprets hyphens as subtraction operators, so function names
;; exposed to raw Javascript (e.g. onclick event handlers) must not contain hyphens.
(defn ^:export home []
(onclick-handler :#home-tab :#home-content))
(defn ^:export params []
(onclick-handler :#params-tab :#params-content))
(om/root
root-component
app-state
{:target (. js/document (getElementById "app"))})
{:target (. js/document (getElementById "world-content"))})