New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bacon-routes

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bacon-routes

Route management, the bacon.js way.

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-90%
Maintainers
1
Weekly downloads
 
Created
Source

bacon-routes Build Status

Route management, the bacon.js way.

Intro

Bacon.js is a library for functional reactive programming, you can get more information about it on the github project webpage.

The idea here is to handle history states and manage client-side routing using Bacon.js.

Install

You can install bacon-routes with bower or npm (in order to use it with browserify)

Using bower:

bower install --save bacon-routes

Using browserify, you currently have to put Bacon in the global scope:

npm install --save bacon-routes
/* In your javascript file */
var Bacon = window.Bacon = require("baconjs");
require("bacon-routes");

API

Bacon.history is a reactive property handling history changes.

Example:

Bacon.history.onValue(function(history) {
  console.log(history);
});

/* Prints:
  {
    "state": [history forwarded from popstate],
    "location": [window.location]
  }
*/

Bacon.history provides a pushState method in order to trigger the load of a URL. See the related MDN article for further documentation.

  Bacon.history.pushState(null, null, "/some-path/some-param");

Bacon.fromRoutes is a method creating streams for each given route.

Example:

var routes = Bacon.fromRoutes({
  routes: {
    "users":  "/users",
    "user":   "/users/:id"
  }
});

/* Log history */
routes.users.onValue(function(history) {
  console.log(history);
});

/* Log user id */
routes.user.map(function(history) {
  return history.params.id;
}).log();

By default, no event is sent until the next url change. To send an event at start, use a ready property:

var ready = new Bacon.Bus();
var routes = Bacon.fromRoutes({
  ready: ready.map(true).toProperty(false),
  routes: {
    "users":  "/users",
    "user":   "/users/:id"
  }
});

/* Log history */
routes.users.onValue(function(history) {
  console.log(history);
});

/* Log user id */
routes.user.map(function(history) {
  return history.params.id;
}).log();

ready.push("Stream subscribers are ready, sir!");

Keywords

FAQs

Package last updated on 30 Jun 2015

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