keechma.app-state
->AppState
(->AppState name reporter router routes-chan route-processor commands-chan app-db subscriptions-cache components controllers context html-element stop-fns)
->AppStateWriteHandler
(->AppStateWriteHandler)
->ControllerWriteHandler
(->ControllerWriteHandler)
->SerializedAppState
(->SerializedAppState app-db)
add-sub-cache
(add-sub-cache cache [key sub])
app-renderer
(app-renderer state)
AppState
AppStateWriteHandler
ControllerWriteHandler
default-route-processor
(default-route-processor route _)
deserialize-app-state
(deserialize-app-state transit-readers serialized-state)
get-controller-types-set
(get-controller-types-set app-state)
get-initial-data
(get-initial-data config)
map->AppState
(map->AppState G__14038)
map->SerializedAppState
(map->SerializedAppState G__14047)
prepare-for-serialization
(prepare-for-serialization value)
(prepare-for-serialization value controller-types)
restore-app-db
(restore-app-db old-app new-app)
serialize-app-state
(serialize-app-state transit-writers state)
SerializedAppState
start!
(start! config)
(start! config should-mount?)
Starts the application. It receives the application config map
as the first argument. It receives boolean
should-mount?
as the second element. Default value for should-mount?
is true
.
You can pass false to the should-mount?
argument if you want to start the app, but you want to manually mount the application (for instance another app could manage mounting and unmounting). In that case you can get the
main app component at the :main-component
of the map returned from the start!
function.
Application config contains all the parts needed to run the application:
- Route defintions
- Controllers
- UI subscriptions
- UI components
- HTML element to which the component should be mounted
- Routes chan (through which the route changes will be communicated)
- Commands chan (through which the UI sends the commands to the controllers)
start!
function returns the updated config map which can be passed to the stop!
function to stop the application.
Example:
(def app-config {:controllers {:users (->users/Controller)}
:subscriptions {:user-list (fn [app-db-atom])}
:components {:main layout/component
:users users/component}
:html-element (.getElementById js/document "app")})
If any of the params is missing, the defaults will be used.
When the application is started, the following happens:
- Routes are expanded (converted to regexps, etc.)
- Application binds the listener the history change event
- Controller manager is started
- Application is (optionally) mounted into the DOM
start-router!
(start-router! state)
start-selected-router!
(start-selected-router! state constructor)
stop!
(stop! config)
(stop! config done)
Stops the application. stop!
function receives the following as the arguments:
config
- App config map returned from thestart!
functiondone
- An optional callback function that will be called when the application is stopped.
Purpose of the stop!
function is to completely clean up after the application. When the application is stopped, the following happens:
- History change event listener is unbound
- Controller manager and any running controllers are stopped
- Any channels used by the app (
routes-chan
,commands-chan
,…) are closed - Application is unmounted and removed from the DOM