Skip to content

sirprize/dojo-local-storage

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

Dojo-local-storage

This store provides a dojo/store interface when working with LocalStorage. Check out the Dojo Object Store Tutorial or the Creating Dojo Stores Tutorial

Introduction

LocalStorage only works with key/value pairs where value is a string. Dojo-local-storage in contrast works with objects. A JSON serialization of an object is stored in LocalStorage, storing strings directly is not supported.

Usage

require(["dojo-local-storage/LocalStorage"], function (LocalStorage) {
    var store = new LocalStorage({
        idProperty: 'id'
    });

    // storing an object
    var id = store.add({
        title: 'Elementarteilchen',
        year: 2006,
        id: 'abc'
    });

    // querying the store
    var result = store.query({
        year: 2006
    },{
        sort: [{ attribute:"year", descending: false }]
    });

    // updating an object
    var id = store.put({
        id: 'abc',
        title: 'Elementarteilchen',
        year: 2006
    });

    // getting an object
    var object = store.get('abc');

    // deleting an object
    store.remove('abc');
});

Working With A Data Subset By Configuration

Sometimes it can be desirable to configure a store such that it only operates on a subset of data. This feature can be helpful to use LocalStorage as a read/writeable replacement for a remote API during development. Transparently to a client, Dojo-local-storage adds a property to each object it stores and removes it upon retrieval. Name and value of this property can be passed to the constructor upon instantiation

var store = new LocalStorage({
    subsetProperty: 'mySubsetProperty',
    subsetName: "movies"
});

Running Tests

  1. cd <path-to-dojo-local-storage>
  2. npm install
  3. Point browser to http://<localhost>/dojo-local-storage/node_modules/intern/client.html?config=tests/intern

Thanks

Original Gist by dmachi

About

LocalStorage wrapper providing dojo/store interface

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published