-
-
Save ahmed1hsn/7351ae6e1edaa64b9109ed19c8776af6 to your computer and use it in GitHub Desktop.
hello world demo keechma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns my.app | |
(:require [keechma.app-state :as app-state] | |
[keechma.ui-component :as ui] | |
[router.core :as router] | |
[keechma.controller :as controller])) | |
;; not used yet. | |
(def edb-schema | |
{:user {:id :username} | |
:description {:id :description}}) | |
(defn hello-renderer [ctx] | |
[:div | |
[:h1 "hello World"]]) | |
(def hello-component | |
(ui/constructor | |
{:renderer hello-renderer | |
:topic :hello})) | |
(defrecord HelloController []) | |
(defmethod controller/params HelloController [_ _] | |
(get-in [:data :hello])) | |
(def routes [["" {:hello "hello"}] | |
["login" {:page "new"}]]) | |
;; (def expanded-routes (router/expand-routes routes)) | |
;; (router/map->url expanded-routes {}) | |
;; (router/url->map expanded-routes "login") | |
;; (router/url->map expanded-routes "") | |
(def app-definition | |
{:components {:main hello-component} | |
:controllers {:hello HelloController} | |
:routes routes | |
:html-element (.getElementById js/document "app")}) | |
(defonce running-app (clojure.core/atom nil)) | |
(defn start-app! [] | |
(when-not @running-app | |
(reset! running-app (app-state/start! app-definition)))) | |
(defn stop-app! [] | |
(let [current @running-app] | |
(if current | |
(app-state/stop! current start-app!)))) | |
(defn stop [] | |
(stop-app!) | |
(. js/console log "stopped")) | |
(defn start [] | |
(start-app!) | |
(. js/console log "started")) | |
(js/console.log "mounting") | |
(.addEventListener js/document "DOMContentLoaded" | |
(start-app!)) | |
(js/console.log "mounted") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment