Skip to content

Jody-Geers/simple-store

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-store

Very lightweight client side store.

Based off object meta defined in its 'model' will either persist locally to browser or remotely to server.

Installation

Install with component(1):

$ component install Jody-Geers/simple-store

API

// provider on store
store.Cars.get(null, function( cars ) {
});

// model on store
var car = new store.Cars({
	id: 30,
	year: '2020',
	make: 'yippie',
	model: 'kayay'
});

// provider on obj
car.save( null, function( err, res ) {

	if ( err ) {
		// Who wants some?
		return;
	}
	
	// Groovy!
	
});

// extend for context
function CtxCar( args ) {
	this.uiId = args.uiId || undefined,
	store.Cars.call( this, args );
}
CtxCar.prototype = Object.create( store.Cars.prototype );
CtxCar.prototype.constructor = CtxCar;

// ctx obj
var car = new CtxCar({
	id: 30,
	year: '2020',
	make: 'beautifulcar',
	model: 'comegetsome',
	uiId: 42
});

Note

In the provider, I’ve used a local file for dummy data, but you can get from local / session storage by flipping that switch in the objects meta data found in its model definition.

In the provider, an ajax component (superagents pretty cool) can be used should you require data from server, works nice for conceptual REST services.

Should you go down this route, just note you need to extend the Provider.js.

Finally you can abstract the model and provider into their own components, and change your require paths in simple-stores index.js, even add a little logic if you want to (you can leave your friends behind), however, I’ve kept it simples here.

License

MIT

About

ikkle client-side store

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published