keechma.controller-manager
apply-route-change
(apply-route-change reporter route-params app-db-atom commands-chan controllers)
apply-start-controllers
apply-start-or-wake-controllers
(apply-start-or-wake-controllers action reporter-action app-db reporter controllers commands-chan get-running start-or-wake)
apply-stop-controllers
(apply-stop-controllers app-db reporter stop)
apply-wake-controllers
call-handler-on-started-controllers
(call-handler-on-started-controllers app-db-atom reporter start)
call-ssr-handler-on-started-controllers
(call-ssr-handler-on-started-controllers app-db-atom reporter start ssr-handler-done-cb)
report-running-controllers
(report-running-controllers app-db-atom)
route-change-execution-plan
(route-change-execution-plan route-params running-controllers controllers)
send-route-changed-to-surviving-controllers
(send-route-changed-to-surviving-controllers app-db-atom reporter route-changed route-params)
start
(start route-chan route-processor commands-chan app-db-atom controllers reporter)
Starts the controller manager. Controller manager is the central part of the application that manages the lifecycle of the controllers and routes the messages sent to them.
start
function receives the following parameters:
route-chan
- Route changes will communicated through this channelroute-processor
- Function that will be called on every route change. It can be used to process the route before it’s written into app-dbcommands-chan
- User (UI) commands will be sent through this channelapp-db
- application state atomcontrollers
map of controllers registered for the appreporter
- internal reporter function
Each time when the new route data comes through the route-chan
controller manager will do the following:
- call the
params
function on each registered controller - compare the value returned by the
params
function with the value that was returned last time when the route changes - based on the comparison it will do one of the following:
- if the last value was
nil
and the current value isnil
- do nothing - if the last value was
nil
and the current value is notnil
- start the controller - if the last value was not
nil
and the current value isnil
- stop the controller - if the last value was not
nil
and the current value is notnil
and these values are the same - do nothing - if the last value was not
nil
and the current value is notnil
and these values are different - restart the controller (stop the current instance and start the new one)
Controller manager also acts as a command router. Each time a command comes - through the commands-chan
the name of the command should look like this [:controlnler-key :command-name]
. Controller manager will
route the :command-name
command to the appropriate controller based on the :controller-key
. Controller key is the key under which the controller was registered in the controllers
argument.
start-ssr
(start-ssr routes-chan commands-chan app-db-atom controllers reporter done-cb)