
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
cycle-director
Advanced tools
This is a first attempt a making a router driver for cycle.js using director
npm install cycle-director
import {run, Rx} from '@cycle/core';
import {h, makeDOMDriver} from '@cycle/dom';
import {makeClientDriver} from 'cycle-director';
let author = () => { return "author" };
let books = () => { return "books"};
let viewBook = (id) => {return "viewBook: bookId is populated: " + id};
let viewChapter = (bookId, chapterNumber) => { return "BookId: " + bookId + " Chapter: " + chapterNumber}
let routes = [
{ url: "/author",
on: author,
after: () => {if (!confirm("You sure you want to leave this page?")) {
window.location.hash = '#/author'
}}
},
{ url: "/books", on: [books, () => { return "An inline route handler"}]},
{ url: "/books/view/:bookId", on: viewBook},
{ url: "/books/view/:bookId/chapter/:chapterNumber", on: viewChapter }
]
function render(text) {
return h('div', [
h('ul', [
h('li', [h('a', {href: '#/author'}, 'Author')]),
h('li', [h('a', {href: '#/books'}, 'Books')]),
h('li', [h('a', {href: '#/books/view/33'}, 'Book 33')]),
h('li', [h('a', {href: '#/books/view/33/chapter/2'}, 'Book 33 Chapter 2')])
]),
h ('h1', text)
])
}
function main({DOM, Router}){
let route$ = Rx.Observable.from(routes);
let view$ = Router
.map((output) => {
console.log("Output: " + output);
return render(output);
})
return {
DOM: view$,
Router: route$
};
}
let drivers = {
DOM: makeDOMDriver('.app'),
Router: makeRouterDriver({
html5history: false,
notfound: () => { return 'Page can not be found'}
})
};
run(main, drivers);
options - options are all configuration options supported by director
(Function) The Router Driver function. It expects an Observable of Route Objects as input, and outputs the path of the current route.
import {run} from '@cycle/core';
import {makeServerDriver} from 'cycle-http-server';
import {makeHTTPDriver} from 'cycle-director';
function helloWorld() {
this.res.writeHead(200, {'Content-Type': 'text/plain'});
this.res.end("Hello, world!");
}
let routes = {
"/hello": {
get: helloWorld
}
};
function main({Server, Router}) {
Server.subscribe( ({req, res}) => {
Router.dispatch(req, res, (err) => {
if (err) {
res.writeHead(404);
res.end(err.toString());
}
Router.get("/bonjour", helloWorld);
Router.get("/hola/", helloWorld);
Server.listen(3000);
}
let drivers = {
// Takes routes and [configuration](https://github.com/flatiron/director#configuration)
Router: makeHTTPDriver(routes, {
strict: false
}),
Server: makeServerDriver()
}
run(main,drivers);
FAQs
A router driver for cycle.js based on director
We found that cycle-director demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.