Adapter: SessionLocal

AeroGear.DataManager.adapters. SessionLocal

new SessionLocal(storeName, settings) → {Object}

Status: Stable
The SessionLocal adapter extends the Memory adapter to store data in either session or local storage which makes it a little more persistent than memory This constructor is instantiated when the "DataManager.add()" method is called
Parameters:
Name Type Argument Default Description
storeName String the name used to reference this particular store
settings Object <optional>
{} the settings to be passed to the adapter
Properties
Name Type Argument Default Description
recordId String <optional>
"id" the name of the field used to uniquely identify a "record" in the data
storageType String <optional>
"sessionStorage" the type of store can either be sessionStorage or localStorage
crypto Object <optional>
the crypto settings to be passed to the adapter
Properties
Name Type Argument Description
agcrypto Object <optional>
the AeroGear.Crypto object to be used
options Object <optional>
the specific options for the AeroGear.Crypto encrypt/decrypt methods
Source:
Returns:
The created store
Type
Object
Example
// Create an empty DataManager
var dm = AeroGear.DataManager();

// Add a custom SessionLocal store using local storage as its storage type
dm.add({
    name: "newStore",
    type: "SessionLocal"
    settings: {
        recordId: "customID",
        storageType: "localStorage"
    }
});

Mixes In

Methods

<static> isValid()

Determine if this adapter is supported in the current environment
Source:

<static> remove(toRemove) → {Object}

Removes data from the store
Parameters:
Name Type Description
toRemove String | Object | Array A variety of objects can be passed to remove to specify the item or if nothing is provided, all data is removed
Source:
Returns:
A Promise
Type
Object
Example
        var dm = AeroGear.DataManager([{ name: "tasks", type: "SessionLocal" }]).stores[ 0 ];

        dm.open()
            .then( function() {

                // Delete a record
                dm.remove( 1, )
                    .then( function( newData ) { ... } )
                    .catch( function( error ) { ... } );

                // Remove all data
                dm.remove( undefined )
                    .then( function( newData ) { ... } )
                    .catch( function( error ) { ... } );

                // Delete all remaining data from the store
                dm.remove()
                    .then( function( newData ) { ... } )
                    .catch( function( error ) { ... } );
            });

<static> save(data, options) → {Object}

Saves data to the store, optionally clearing and resetting the data
Parameters:
Name Type Argument Description
data Object | Array An object or array of objects representing the data to be saved to the server. When doing an update, one of the key/value pairs in the object to update must be the `recordId` you set during creation of the store representing the unique identifier for a "record" in the data set.
options Object <optional>
The options to be passed to the save method
Properties
Name Type Argument Description
reset Boolean <optional>
If true, this will empty the current data and set it to the data being saved
Source:
Returns:
A Promise
Type
Object
Example
        var dm = AeroGear.DataManager([{ name: "tasks", type: "SessionLocal" }]).stores[ 0 ];

        dm.open()
            .then( function() {

                // save one record
                dm.save({
                        title: "Created Task",
                        date: "2012-07-13",
                        ...
                    })
                    .then( function( newData ) { ... } )
                    .catch( function( error ) { ... } );

                // save multiple records
                dm.save([
                        {
                            title: "Task2",
                            date: "2012-07-13"
                        },
                        {
                            title: "Task3",
                            date: "2012-07-13"
                            ...
                        }
                    ])
                    .then( function( newData ) { ... } )
                    .catch( function( error ) { ... } );

                // Update an existing piece of data
                var toUpdate = dm.read()[ 0 ];
                toUpdate.data.title = "Updated Task";
                dm.save( toUpdate )
                    .then( function( newData ) { ... } )
                    .catch( function( error ) { ... } );
            });