Skip to content

Polonious/dojo-local-storage

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

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
    });
    // storing a string
    store.add('hello world', {id: 'greeting'});
    
    
    // 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');
    // getting a string
    var str = store.get('greeting');
    
    // deleting an object
    store.remove('abc');
    
    // clear everything from LocalStorage
    store.clear();
});

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 subset name to the key and removes it upon retrieval. Name and value of this property can be passed to the constructor upon instantiation

var store = new LocalStorage({
    subset: "movies"
});

Thanks

Original Gist by dmachi

About

LocalStorage wrapper providing dojo/store interface

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 100.0%