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

circus-router

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

circus-router

Router parser for Circus components

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

circus-router

In-source router parser for Circus components dependencies, allowing for smart runtime behavior such as demand loading of chunks based on the current route. This allows the application to bootstrap from minimal code sent to the client, with only the pertinent code being loaded when the user hits that portion of the site.

Usage

See the example directory for an example of a complete Backbone application.

Configuration

Used as a preprocessor for the Circus.config method:

var Circus = require('circus'),
    CircusRouter = require('circus-router');

var config = {};
config = CircusStylus.config(config);
config = Circus.config(config);

Routers

Routers are the primary execution component for Circus applications. As in generic backbone applications, they allow for specific behaviors to occur in response to the current url of the page.

Circus.router({
  routes: {
    '/': 'home',
    '/home': 'home'
  },

  home: function(params) {
    // Respond to the route
  }
});

Defines a [Backbone router][backbone-router] on the routes / and /home but have the important distinction of being parse-able at build time so they may be demand loaded with the Circus.loader and integrated into the server routing tables for push state and SSJS support.

This does not necessarily need to be a Backbone router, and can be anything as long as the first parameter is an object with the field routes who's keys define routes in a manner that can be consumed by Circus.loader.

Loaders

Loaders serve as entry points into routers. They will demand load a given router and it's dependencies in response to the current route on the page.

Circus.loader([
  './home',
  './items'
]);

Will generate two different chunks, one for the home router and one for the items route.

Generally a loader is used for simple bootstrapping of an application, along with core libraries.

If two parameters are passed, the first paramter is passed to the loader runtime and maybe used as needed for initialization.

Circus.loader({root: '/foo'}, [
  './home',
  './items'
]);

Would pass the object containing root to the generated module json at runtime.

Generated Code

The loader will generate a JavaScript construct similar to the following:

Circus.loader(__webpack_requre__, moduleJSON);

and Circus.router calls are not modified at build time. Implementors are expected to provide their own implementations of these methods that integrates with their framework of choice.

For those who wish to use a different root object, the Circus name may be changed by passing a circusNamespace option to the Circus.config compiler method.

FAQs

Package last updated on 15 Apr 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