cycle-vtree-switcher
v2.0.0
Published
A Cycle.js helper for switching between route handlers
Downloads
5
Readme
Cycle VTree Switcher
A helper for Cycle.js apps to perform routing.
Install
npm install cycle-vtree-switcher
API
vtreeSwitcher(routes: Object, responses: Object) -> [vtree$: Observable, requests: Object]
Input:
routes
: an object mapping from routington route definitions to route handlers which are functions like Cycle.js main functions:main(responses: Object) -> requests: Object
.cycle-vtree-switcher
uses cycle-route under the hood so it also supports*
as the default route.responses
: an object containing Cycle.js driver responses/sources. Must include aPath
response, which can be built using cycle-pushstate-driver.
Output:
vtree$
: an Observable of vtrees that is the result of switching among the vtree outputs of the route handlers according to the current pathrequests
: an object containing Cycle.js driver requests/sinks, which you can combine to return to the drivers
Gotchas
Rx.Observable.combineLatest
is used to combine the route and route handlers, and it will only emit when every source has emitted, so make sure to have each route handler emit a starting vtree. This could be a loading page.
Usage
Check out the example.