Skip to content

Instantly share code, notes, and snippets.

@ahmed1hsn
Created June 24, 2019 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmed1hsn/7351ae6e1edaa64b9109ed19c8776af6 to your computer and use it in GitHub Desktop.
Save ahmed1hsn/7351ae6e1edaa64b9109ed19c8776af6 to your computer and use it in GitHub Desktop.
hello world demo keechma
(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