Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cycle-routing-driver

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cycle-routing-driver

A bare-bones router for simple frontend routing in CycleJS

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
31
increased by244.44%
Maintainers
1
Weekly downloads
 
Created
Source

cycle-routing-driver

CircleCI

Routing driver for CycleJS that enables simple client-side routing.

npm install --save cycle-routing-driver

Usage

Updating the location bar and clicking links already works, so most of the work is hands-off. If you do need to force a route change based on an event, just stream it in via the sinks.

import {run} from '@cycle/run'
import makeRoutingDriver, {routes} from 'lib/cyclejs/routing-driver'

function main(sources) {
	// in addition to path data and parameters, we get query string data so your page can render accordingly
	const modal_ = sources.route.map(({query}) => query.modal)

	return {
		// other stuff...,
		route: xs.merge(
			// if you would prefer to just bounce bad urls somewhere, you can!
			sources.route.filter(({page}) => page === `404`).mapTo({page: `homepage`}),

			// updating the URL always happens contextually - what streams through is reduced into the existing route
			sources.DOM.select(`.signup-modal`).events(`click`).mapTo({query: {modal: `signup`}}),

			// mapping query values to null removes them entirely
			sources.DOM.select(`.modal-close`).events(`click`).mapTo({query: {modal: null}}),
		),
	}
}

run(main, {
	// other stuff...,
	route: makeRoutingDriver(
		// the routes DSL provides a clean interface for defining basic routes
		routes`
		homepage
		about
		post (/posts/:post) -> view
			view
			edit
			performance -> dashboard
				demographics
				reach
				dashboard
				search-ranking
		`,
		{
			params: {
				post: {
					toData: _ => _,
					toParam: data => data.id || data,
				},
			},
		}
	)
})

Keywords

FAQs

Package last updated on 13 Oct 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc