Giter Club home page Giter Club logo

ember-localstorage-adapter's Introduction

Ember Data Local Storage Adapter

Build Status

Store your ember application data in localStorage.

Compatible with Ember Data 1.0.beta.16

NOTE: New versions of the localStorage adapter are no longer compatible with older versions of Ember Data. For older versions, checkout the pre-beta branch.

Usage

Include localstorage_adapter.js in your app and then like all adapters:

App.ApplicationSerializer = DS.LSSerializer.extend();
App.ApplicationAdapter = DS.LSAdapter.extend({
    namespace: 'yournamespace'
});

If you are using Ember Localstorage Adapter within an Ember CLI project you can install it as an addon with the following command:

ember install:bower ember-localstorage-adapter

Local Storage Namespace

All of your application data lives on a single localStorage key, it defaults to DS.LSAdapter but if you supply a namespace option it will store it there:

DS.LSAdapter.create({
  namespace: 'my app'
});

Models

Whenever the adapter returns a record, it'll also return all relationships, so do not use {async: true} in your model definitions.

Namespace

If your model definition has a url property, the adapter will store the data on that namespace. URL is a weird term in this context, but it makes swapping out adapters simpler by not requiring additional properties on your models.

var List = DS.Model.extend({
  // ...
});
List.reopen({
  url: '/some/url'
});

Quota Exceeded Handler

Browser's localStorage has limited space, if you try to commit application data and the browser is out of space, then the adapter will trigger the QUOTA_EXCEEDED_ERR event.

App.store.adapter.on('QUOTA_EXCEEDED_ERR', function(records){
  // do stuff
});

App.store.commit();

Local Storage Unavailable

When localStorage is not available (typically because the user has explicitly disabled it), the adapter will keep records in memory. When the adapter first discovers that this is the case, it will trigger a persistenceUnavailable event, which the application may use to take any necessary actions.

adapter.on('persistenceUnavailable', function() {
  // Maybe notify the user that their data won't live past the end of the current session
});

Todo

  • Make the repo nicer to work with long-term (do something more intelligent with dependencies found in vendor, etc.)

Tests

If you don't have bower, install it with

npm install bower -g

Then install the dependencies with

bower install

Open test/index.html in a browser. If you have phantomjs installed, run

phantomjs test/runner.js test/index.html

License & Copyright

Copyright (c) 2012 Ryan Florence MIT Style license. http://opensource.org/licenses/MIT

ember-localstorage-adapter's People

Contributors

kurko avatar ryanflorence avatar coroa avatar fsmanuel avatar bjarkehs avatar wmeldon avatar jonkoops avatar dfreeman avatar jayphelps avatar rondale-sc avatar fivetanley avatar atmartin avatar abossard avatar bradleypriest avatar csantero avatar truffula avatar quaertym avatar julienmelissas avatar rubyconvict avatar micahblu avatar passy avatar munter avatar bittersweetryan avatar samuraisam avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.