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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-heisenberg

v0.9.3

Published

Ember-Heisenberg is a simple REST-like serialization and transport framework for Ember.js apps.

Downloads

3

Readme

Ember-Heisenberg

Ember-Heisenberg is a simple REST-like serialization and transport framework for Ember.js applications. At its core, it provides a fluent, customizable, promise-oriented API to define and bind client-side models to server-side endpoints. Heisenberg is server-agnostic, which allows it to be flexible and configurable without sacrificing simplicity. It also means that Heisenberg plays well outside of a strict REST environment, and can just as easily support RPC-oriented endpoints.

Key Benefits

  • Lightweight: client-side model definitions are simple Ember.Object wrappers
  • Decoupled architecture: create a Resource definition to specify transport details
  • No 'magic': be as explicit as necessary about server-side API expectations
  • Promise-aware: all AJAX requests are promise-compliant, using Ember.RSVP.Promise
  • Value-aware: response values can be directly bound to templates; Ember's binding will auto-update values seamlessly
  • Declarative model relationships: specify child models just as you would any other field; one-to-many relationships are just lists of children
  • Limited concerns: don't be forced into auto-magic 'caching' behaviors; if you want caching, layer that on top of Heisenberg

Example Usage


require('ember-heisenberg');

// Model definitions

App.Company = EH.Object.extend({
	name: EH.stringField()
});

var Company = App.Company;

App.Employee = EH.Object.extend({
	id: EH.numberField(),
	name: EH.stringField(),
	aliases: EH.stringList(),

	// embedded objects
	company: EH.field(Company),
});

var Employee = App.Employee;

// Resource Setup

App.EmployeeResource = EH.Resource.extend();

App.EmployeeResource.reopenClass({
	load: function(id) {
		var request = this.method('GET')
			// query/path parameters are templatized
			.url('/employee/{id}', {id: id}))

			// specify the expected return object to facilitate deserialization
			.produces(Employee);

		// This returns an object which has getResponsePromise() and getResponseValue() functions
		return EmployeeResource.executeRequest(request);
	},

	create: function(Employee) {
		var request = this.method('POST')
		.url('/Employee')
		.body(Employee.toJson())
		.produces(Employee);

		return EmployeeResource.executeRequest(request);
	}
 });


// Using Resources

// Use AJAX responses as promises...
var isBluth = App.EmployeeResource
				.load(10)
				.getResponsePromise()
				.then(doSomethingWithEmployee);

function doSomethingWithEmployee(Employee) {
	return Employee.get('name') === 'Bluth';
}

// ...or use them as values, which will be asynchronously set
var employee = App.EmployeeResource
				.load(11)
				.getResponseValue();

// Creating a new record and handle a failure of the save
var employee = App.Employee.create()
employee.set('name', 'Boy George')

var resultOfSave = EmployeeResource
						.create(Employee)
						.getResponsePromise()
						.then(doSomethingPostSaveSuccess)
						.fail(doSomethingPostSaveFail);

function doSomethingPostSaveSuccess() {
	return 1;
}

function doSomethingPostSaveFail() {
	return 0;
}

Building Ember-Heisenberg

  1. Install node: http://nodejs.org/
  • Install dependencies: npm install
  • Build and run tests: grunt
  • Output will be in dist/

Tests

Heisenberg uses Karma as its test runner. Tests are run automatically as a part of the build process, but you can invoke the tests manually with grunt karma:unit.

You can also run the tests continuously (they will auto-watch any dependencies) with grunt karma:dev.