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

ember-simple-data

v0.1.1

Published

a simple data store for emberjs

Readme

$ npm install ember-simple-data

Setup the Simple Store

var SD = require('ember-simple-data');

First we need to create some store objects that houses our models. Each store needs a unique name which we will use to reference it. IDs default to 'id' but you can specify which key on your objects you would like to use as an id, it obviously must be unique in your data set.

var users = SD.store.create({
	name: 'user',
	id_key: '_id'
});

var comments = SD.store.create({
	name: 'comment',
	id_key: '_id'
});

Then we need to define the models that will be inserted into the store. This is a description of the attributes on each object and its relationship to other objects you have. The has_many and belongs_to attribute definitions require you pass it the name of the store these related objects are defined on and which attribute to expect the list of ids to be in.

users.define({
	name: SD.attribute(),
	comments: SD.has_many('comment', 'comment_ids')
});

comments.define({
	text: SD.attribute(),
	post: SD.belongs_to('user', 'user_id')
});

Loading objects

The json for our user objects would look something like this, where user_data and comment_data would be a result of api calls for example. The persistance side of things will be explained somewhere below.

var user_data = [
	{
		_id: 'riker',
		name: 'Riker',
		comment_ids: [22, 123]
	},
	{
		_id: 'troi',
		name: 'Troi',
		comment_ids: [1701]
	}
];

var comment_data = [
	{
		_id: 22,
		text: 'Greetings from planet Earth.',
		user_id: 'riker'
	},
	{
		_id: 123,
		text: 'Where are you Imzadi?',
		user_id: 'riker'
	},
	{
		_id: 1701,
		text: 'This is a stupid comment.',
		user_id: 'troi'
	}
];

And then we load it into our store by simply doing

users.load(user_data);
comments.load(comment_data);

Updating and upserting objects

We can update existing comment objects by using comments.update() and passing it the object to update. It will do a find for the object id given and then update attributes. If we want to do an 'update or insert' then we can pass true as a second parameter to the update call and it will insert a new object if not found for updating.

comments.update({
	_id: 1701,
	text: 'I have a feeling.',
	user_id: 'troi'
}, true);

Finding objects

Pretty simple, find() will return all in the store, pass it an id to get a specific object.

comments.find();
comments.find(1701);

If you just want to know if an id exists in your store you can use contains()

comments.contains(123451235); // false
comments.contains(1701); // true

Accessing your object attributes

The objects are loaded into the store as instances of Ember.Object so you will need to use .get() so that all the observer functions fire properly, especially with the relationship attributes.

comments.find(22).get('_id'); // 22
comments.find(22).get('text'); // 'Greetings from planet Earth.'
comments.find(22).get('user'); // The user object that this post belongs to
comments.find(22).get('user').get('name'); // 'Riker'

more to come