Skip to content

Commit

Permalink
base routing support
Browse files Browse the repository at this point in the history
  • Loading branch information
awkay committed Feb 7, 2017
1 parent 6e073f6 commit fb09dd7
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 264 deletions.
2 changes: 1 addition & 1 deletion .idea/runConfigurations/Figwheel.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.7.0
-----
- Removed cache
- Adding UI routing helpers

0.6.1
-----
- Added support for nil as subquery class in load
Expand Down
7 changes: 0 additions & 7 deletions dev/clj/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
[figwheel-sidecar.system :as fig]
[com.stuartsierra.component :as component]))

(defn conform! [spec x]
(let [rt (s/conform spec x)]
(when (s/invalid? rt)
(throw (ex-info (s/explain-str spec x)
(s/explain-data spec x))))
rt))

(def figwheel (atom nil))

(defn start-figwheel
Expand Down
10 changes: 5 additions & 5 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject navis/untangled-client "0.6.1"
(defproject navis/untangled-client "0.7.0-SNAPSHOT"
:description "Client-side code for Untangled Webapps"
:url ""
:license {:name "MIT"
Expand All @@ -9,7 +9,7 @@
[lein-doo "0.1.7" :scope "test"]
[navis/untangled-spec "0.3.9" :scope "test"]
[org.clojure/clojure "1.9.0-alpha14" :scope "provided"]
[org.clojure/clojurescript "1.9.293" :scope "provided"]
[org.clojure/clojurescript "1.9.456" :scope "provided"]
[org.clojure/core.async "0.2.391"]
[com.ibm.icu/icu4j "58.2"] ; needed for i18n on server-side rendering
[org.omcljs/om "1.0.0-alpha47" :scope "provided"]
Expand All @@ -21,9 +21,9 @@
:jvm-opts ["-XX:-OmitStackTraceInFastThrow" "-Xmx512m" "-Xms256m"]
:clean-targets ^{:protect false} ["resources/private/js" "resources/public/js/test" "resources/public/js/compiled" "target"]

:plugins [[lein-cljsbuild "1.1.4"]
:plugins [[lein-cljsbuild "1.1.5"]
[lein-doo "0.1.7"]
[com.jakemccrary/lein-test-refresh "0.17.0"]]
[com.jakemccrary/lein-test-refresh "0.18.0"]]

:test-paths ["spec"]
:test-refresh {:report untangled-spec.reporters.terminal/untangled-report
Expand Down Expand Up @@ -70,7 +70,7 @@
:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
:dependencies [[binaryage/devtools "0.5.2"]
[com.cemerick/piggieback "0.2.1"]
[figwheel-sidecar "0.5.7"]
[figwheel-sidecar "0.5.9"]
[org.clojure/test.check "0.9.0"]
[org.clojure/tools.namespace "0.2.11"]
[org.clojure/tools.nrepl "0.2.12"]]}})
147 changes: 0 additions & 147 deletions spec/untangled/client/cache_manager_spec.cljs

This file was deleted.

77 changes: 77 additions & 0 deletions spec/untangled/client/routing_spec.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
(ns untangled.client.routing-spec
(:require [untangled.client.routing :as r :refer-macros [defrouter]]
[om.dom :as dom]
[untangled-spec.core :refer-macros [specification behavior assertions when-mocking component]]
[om.next :as om :refer-macros [defui]]
[untangled.client.mutations :as m]
[untangled.client.core :as uc]))

(defui Screen1
uc/InitialAppState
(initial-state [cls params] {:type :screen1})
Object
(render [this] (dom/div nil "TODO")))

(defrouter SampleRouter :router-1
(ident [this props] [(:type props) :top])
:screen1 Screen1)

(declare SampleRouter-Union)

(specification "Routers"
(assertions
"Have a top-level table namespaced to the untangled routing library"
(om/ident SampleRouter {}) => [r/routers-table :router-1]
"Use the user-supplied ident function for the union"
(om/ident SampleRouter-Union {:type :screen1}) => [:screen1 :top]))

(specification "current-route"
(let [state-map {r/routers-table {:router-1 {:id :router-1 :current-route [:A :top]}
:router-2 {:id :router-2 :current-route [:B :top]}}}]
(assertions
"Can read the current route from a router"
(r/current-route state-map :router-1) => [:A :top]
(r/current-route state-map :router-2) => [:B :top])))

(specification "update-routing-links"
(component "on non-parameterized routes"
(let [r (r/make-route :boo [(r/router-instruction :router-1 [:screen1 :top])])
r2 (r/make-route :foo [(r/router-instruction :router-2 [:screen2 :top])
(r/router-instruction :router-1 [:screen1 :other])])
tree (r/routing-tree r r2)
state-map {r/routing-tree-key tree
r/routers-table {:router-1 {:id :router-1 :current-route [:unset :unset]}
:router-2 {:id :router-2 :current-route [:unset :unset]}}}
new-state-map (r/update-routing-links state-map {:handler :foo})]
(assertions
"Switches the current routes according to the route instructions"
(r/current-route new-state-map :router-1) => [:screen1 :other]
(r/current-route new-state-map :router-2) => [:screen2 :top])))
(component "on parameterized routes"
(let [r (r/make-route :boo [(r/router-instruction :router-1 [:screen1 :param/some-id])])
tree (r/routing-tree r)
state-map {r/routing-tree-key tree
r/routers-table {:router-1 {:id :router-1 :current-route [:unset :unset]}}}
new-state-map (r/update-routing-links state-map {:handler :boo :route-params {:some-id :target-id}})]
(assertions
"Switches the current routes with parameter substitutions"
(r/current-route new-state-map :router-1) => [:screen1 :target-id]))))

(specification "route-to mutation"
(let [r (r/make-route :boo [(r/router-instruction :router-1 [:screen1 :top])])
r2 (r/make-route :foo [(r/router-instruction :router-2 [:screen2 :top])
(r/router-instruction :router-1 [:screen1 :other])])
tree (r/routing-tree r r2)
state-map {r/routing-tree-key tree
r/routers-table {:router-1 {:id :router-1 :current-route [:initial :top]}
:router-2 {:id :router-2 :current-route [:initial :top]}}}
state (atom state-map)
action (:action (m/mutate {:state state} `r/route-to {:handler :boo}))]

(action)

(assertions
"Switches the current routes according to the route instructions"
(r/current-route @state :router-1) => [:screen1 :top])))


2 changes: 1 addition & 1 deletion spec/untangled/tests_to_run.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
untangled.client.impl.util-spec
untangled.client.impl.application-spec
untangled.client.impl.built-in-mutations-spec
untangled.client.cache-manager-spec
untangled.client.data-fetch-spec
untangled.client.impl.om-plumbing-spec
untangled.client.logging-spec
untangled.client.core-spec
untangled.client.routing-spec
untangled.i18n-spec
untangled.client.impl.network-spec))

Expand Down
74 changes: 0 additions & 74 deletions src/untangled/client/cache_manager.cljc

This file was deleted.

2 changes: 1 addition & 1 deletion src/untangled/client/cards.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
(fn [state-atom# node#]
(untangled.client.core/mount (untangled.client.core/new-untangled-client :initial-state state-atom# ~@args) ~root-ui node#)
; ensures shows app state immediately if you're using inspect data and InitialAppState:
(js/setTimeout (fn [] (swap! state-atom# assoc :ui/react-key (untangled.dom/unique-key))) 200))))
(js/setTimeout (fn [] (swap! state-atom# assoc :ui/react-key (untangled.dom/unique-key))) 1000))))
Loading

0 comments on commit fb09dd7

Please sign in to comment.