npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

bifrost

v0.3.7

Published

State and data transport manager for mobile and web applications

Readme

Bifrost

State and data transport manager for mobile and web applications

Intro

Bifrost is a small library that focuses local and remote state management to a single abstraction. Bifrost is useful in mobile applications that make use of a local storage, and need to sync to a remote server or device. Applications subscribe to local state events, and when requests are made to or pushed from the remote server or device, the local state is synchronised, updating the application. Bifrost is also helpful when multiple components of the application are dependent on the same state.

Todo List Conceptual Example

When a new item is added to a todo list, the local state is updated. If the device is online, the state will sync to the server. If the device is offline, the sync will queue until the connection is enabled. When the remote sync completes, the local state will update with any remote keys set by the server. If the application is closed, and reopened - the state is loaded the local storage while the sync takes place in the background.

React

A reactMixin method is provided to allow easy integration with React components. By invoking the mixin, the component will bind to the local state.

Quick Start

To use Bifrost, include the script on your page:

<script type="text/javascript" src="javascripts/bifrost.js"></script>

In your Application, create a Bifrost store (where TodoApp is your global app namespace):

TodoApp.todoStore = Bifrost.createResource({
	host:"http://todo.example.com/", 
	name:"todo", 
	key:"todoid"
});

In your List React component, add the Mixin:

var TodoList = React.createClass({
	mixins: [TodoApp.todoStore.reactMixin()],
	render: function() {
		// The todoStore reactMixin adds the store to 'this.state.items'
		var todoitems = this.state.items.map(function(item){
			return (
				<TodoItem key={item.todoid} item={item} />
			)
		});
		return (
			<ul className="todo-list">
				<li className="todo-list-head">
					<div className="todo-list-field">Key</div>
					<div className="todo-list-text">Todo Item</div>
					<div className="todo-list-field">Is Done?</div>
					<div className="todo-list-field">Date Entered</div>
					<div className="todo-list-field">Actions</div>
				</li>
				{todoitems}
			</ul>
		)
	}
});

Create your data-entry Component, and you're done!

var TodoEntry = React.createClass({
	getInitialState:function(){
		return {
			"todoid": null,
			"todotext": "",
			"tododate": null,
			"isdone": false,
		};
	},
	componentDidMount:function(){
		var self = this;
		TodoApp.todoStore.bind(function(){
			self.setState(self.getInitialState());
		});
	},
	handleChange:function(e){
		this.state.todotext = e.target.value;
		this.setState(this.state);
	},
	handleSave:function(e){
		this.state.tododate = (new Date()).toLocaleString();
		TodoApp.todoStore.add(this.state);
	},
	render: function(){
		var self = this;
		var state = self.state;
		return (
			<div className="todo-form">
				<textarea id="todotext" value={state.todotext} onChange={this.handleChange} />
				<button id="todosave" onClick={this.handleSave}>Add</button>
			</div>
		);
	}
});

Now, when you add a new Todo list item, it will sync to the local state, and to your remote resource at http://todo.example.com/todos

If you close and reopen your app - it will instantly load the local storage data, while it fetches any updated data from the remote server in the background.

See the full example in the /examples directory of the repo.

API

The Bifrost API is meant to be simple to use to create a store that automatically syncs to a remote server. Bifrost also comes with an extended API providing methods for events and ajax that work across all browsers. The API methods are as follows, with documentation on their parameters:

createLocal

Creates a localStorage only store.

@name :: The name of the store
@key  :: The unique keyname field for each item kept in the store

createResource

Creates a local store synced with a remote RESTful resource.

@host       :: The hostname of the REST api
@resource   :: The RESTful resource endpoint 
@key        :: The unique keyname field for each item kept in the store
@filter     :: An optional function to filter server side results on synch
@addFilter  :: An optional function to filter server side results on add response
@saveFilter :: An optional function to filter server side results on save response

online

Tells Bifrost that the app is connected to the network (on by default)

This method accepts no parameters

offline

Tells Bifrost that the app is not connected to the network (on by default). When Bifrost is offline, it will queue any remote requests to be called when a connection is made.

This method accepts no parameters

on

Subscribes a function to a custom event

@name     :: The name of the event type
@callback :: the function to be called when the event fires

off

Unsubscribes a function from a custom event

@name     :: The name of the event type
@callback :: the function to be removed from the subscription (must be the same as on)

If @callback is blank, all functions are unsubscribed from the event

trigger

Fires a custom event

@name :: The name of the event to fire
@data :: The data to send to the event callback

get

Performs an ajax GET request to a remote resource

@url      :: The URL to request
@data     :: The querystring object for the request
@callback :: The function to call with the response

Note: the data parameter must be given, for no data, use null

head

Performs an ajax HEAD request to a remote resource

@url      :: The URL to request
@data     :: The querystring object for the request
@callback :: The function to call with the response

Note: the data parameter must be given, for no data, use null

post

Performs an ajax POST request to a remote resource

@url      :: The URL to request
@data     :: The body object for the request
@callback :: The function to call with the response

Note: the data parameter must be given, for no data, use null

put

Performs an ajax PUT request to a remote resource

@url      :: The URL to request
@data     :: The body object for the request
@callback :: The function to call with the response

Note: the data parameter must be given, for no data, use null

del

Performs an ajax DELETE request to a remote resource

@url      :: The URL to request
@data     :: null
@callback :: The function to call with the response

Note: the data parameter must be given but is always ignored, use null