Class: Wallet

Wallet

Class that wraps IndexDB functionalities using LocalForage.

Members

staticWallet.contextString

String to be used before keys to avoid key collision between different applications.

staticWallet.databaseString

Chosen name for the database.
Cannot be changed. Use Wallet.init to initialize the tool.

Methods

staticWallet.clear(p_callback)

Removes all keys of this context. If the context is empty all data will be excluded.

Name Type Description
p_callback String | WalletCallback

Function that will handle the end of operation or String in the format path.to.event compatible with Suit controllers.

Example

Wallet.clear(function(p_removed_count,p_error){
if(p_error!=null) { return; } //failed
});

//Using 'Suit' notifications if available.
Wallet.clear('clear-complete'); //will generate 'clear-complete@remove' or 'clear-complete@error'

staticWallet.destroy(p_callback)

Removes all data from ALL databases. Use with care.

Name Type Description
p_callback String | WalletCallback

Function that will handle the end of operation or String in the format path.to.event compatible with Suit controllers.

Example

Wallet.destroy(function(p_error){
if(p_error!=null) { return; } //failed
});

//Using 'Suit' notifications if available.
Wallet.destroy('armageddon-complete'); //will generate 'armageddon-complete@destroy' or 'armageddon-complete@error'

staticWallet.exists(p_key, p_callback)

Checks if a given 'key' exists in the current database and context.

Name Type Description
p_key String

Key that index the information.

p_callback function

Callback called sending 'true'|'false' telling if the 'key' exists.

Example

Wallet.exists('key',function(p_flag){
if(p_flag) { console.log('exists'); }
});

//Using 'Suit' notifications if available.
Wallet.exists('key','have-it'); //will generate 'have-it@exists'

staticWallet.get(p_key, p_callback)

Retrieves a data from LocalForage.

Name Type Description
p_key String

Key that index the information.

p_callback String | WalletCallback

Function that will handle the end of operation or String in the format path.to.event compatible with Suit controllers.

Example

//Gets a value using 'key'
Wallet.get('key',function(p_data,p_error){
if(p_error!=null) { return; }
//use p_data
});

//Using 'Suit' notifications if available.
Wallet.get('key','get-event'); //will generate either 'get-event@get' or 'get-event@error'

staticWallet.init(p_name)

Initializes the storage with custom information.

Name Type Description
p_name String nullable

Database name. Defaults to 'wallet'.

Example

Wallet.init("my-unique-app-database");

staticWallet.iterate(p_callback)

Iterates all key-value pairs from this storaged context.

Name Type Description
p_callback WalletIterationCallback

Function that will handle each iteration step.

Example

Wallet.iterate(function(p_key,p_value,p_index){

});

staticWallet.key(p_id, p_callback)

Returns the keyname based on the numeric id.

Name Type Description
p_id Number

Numeric id whose string key will be returned.

p_callback String | WalletCallback

Function that will handle the end of operation or String in the format path.to.event compatible with Suit controllers.

Example

Wallet.key(5,function(p_key_name,p_error){
if(p_error!=null) { return; } //failed
});

//Using 'Suit' notifications if available.
Wallet.key(5,'is-finish'); //will generate 'is-finish@key' or 'is-finish@error'

staticWallet.keys(p_callback)

Recovers the keys related to the context. If the context if empty, returns all keys.

Name Type Description
p_callback String | WalletCallback

Function that will handle the end of operation or String in the format path.to.event compatible with Suit controllers.

Example

Wallet.keys(function(p_list,p_error){
if(p_error!=null) { return; } //failed
});

//Using 'Suit' notifications if available.
Wallet.keys('check-keys'); //will generate 'check-keys@keys' or 'check-keys@error'

staticWallet.length(p_callback)

Returns the length of this storage based on the current context.

Name Type Description
p_callback String | WalletCallback

Function that will handle the end of operation or String in the format path.to.event compatible with Suit controllers.

Example

Wallet.length(function(p_count,p_error){
if(p_error!=null) { return; } //failed
});

//Using 'Suit' notifications if available.
Wallet.length('count-complete'); //will generate 'count-complete@length' or 'count-complete@error'

staticWallet.remove(p_key, p_callback)

Removes data from LocalForage.
Stores a data into LocalForage.

Name Type Description
p_key String

Key that index the information to be removed.

p_callback String | WalletCallback

Function that will handle the end of operation or String in the format path.to.event compatible with Suit controllers.

Example

Wallet.remove('key',function(p_data,p_error){
if(p_error!=null) { return; } //failed
});

//Using 'Suit' notifications if available.
Wallet.remove('key','is-gone'); //will generate 'is-gone@remove' or 'is-gone@error'

staticWallet.set(p_key, p_value, p_callback)

Stores a data into LocalForage.

Name Type Description
p_key String

Key that index the information to be set.

p_value Object

Object to be stored.

p_callback String | WalletCallback

Function that will handle the end of operation or String in the format path.to.event compatible with Suit controllers.

Example

//Sets a value using 'key'
Wallet.set('key',{some: "data"},function(p_data,p_error){
if(p_error!=null) { return; }
//use p_data
});

//Using 'Suit' notifications if available.
Wallet.set('key',{some: "data"},'set-event'); //will generate either 'set-event@set' or 'set-event@error'

comments powered by Disqus