Skip to content

Instantly share code, notes, and snippets.

@snichme
Created May 11, 2017 15:06
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 snichme/101600b849dc7bcab17877a3310d4ad2 to your computer and use it in GitHub Desktop.
Save snichme/101600b849dc7bcab17877a3310d4ad2 to your computer and use it in GitHub Desktop.
(ns chestnut-app.core
(:require [om.next :as om :include-macros true]
[om.dom :as dom :include-macros true]
[compassus.core :as c]
[pushy.core :as pushy]
[goog.dom :as gdom]
[chestnut-app.ui :as ui]
[chestnut-app.parser :refer [read mutate]]
[chestnut-app.util :refer [transit-post]]
[chestnut-app.router :as router]))
(enable-console-print!)
(def om-parser (om/parser {:read read}))
(def c-parser (c/parser
{:read read
:route-dispatch false}))
(def reconciler)
(defn get-rec [parser]
(om/reconciler
{:state {:projects [{:project/id 1 :project/title "PP1"}
{:project/id 2 :project/title "PP2"}]}
:normalize true
:parser parser
:send (transit-post "/api")
;:remotes [:remote]
}))
(om/add-root! (get-rec om-parser) ui/ProjectList (gdom/getElement "app2"))
(defonce app (c/application
{:routes {:index ui/ProjectList
:project ui/Project
:pp ui/ProjectPage}
:index-route :index
:reconciler (get-rec c-parser)
:mixins [(c/did-mount (fn [_] (pushy/start! router/history)))
(c/will-unmount (fn [_] (pushy/stop! router/history)))
(c/wrap-render ui/Root)]}))
(defonce mounted? (atom false))
(if-not @mounted?
(do
(router/start-nav-listener! (router/route-handler app))
(c/mount! app (js/document.getElementById "app"))
(swap! mounted? not)
)
(let [route->component (-> app :config :route->component)
c (om/class->any
(c/get-reconciler app)
(get route->component (c/current-route app)))]
(.forceUpdate c)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment