Storing data¶
Taist allows to store data in different ways:
User data locally¶
taistApi.localStorage allows to store data using localStorage - it’s just a wrapper around localStorage that allows storing objects:
set(key, value)- stores value inlocalStorage; can store objectsget(key)- gets previously stored value;delete(key)- deletes value
User and company data on server¶
Data can also be stored on Taist server:
- user-level data is processed via
userData - company-level data (shared between all company members) is processed via
companyData
userData and companyData have the same basic interface:
set(key, value, callback)- storesvalueon Taist serverget(key, callback)- gets previously stored datadelete(key, callback)- deletesvalue; throws an error if there is no data stored with givenkey
params:
key,value- scalar value or JSON-like objectfunction callback(error, result)-resultis set only forgetmethod
Company data: working with parts of values¶
companyData also allows to change or retrieve parts of data:
getPart(key, partKey, callback)- gets fieldpartKeyof an object previously stored with key =keysetPart(key, partKey, value, callback)- sets fieldpartKeyof an object previously stored with key =key
Example:
taistApi.companyData.set('foo', {bar: 1, baz: '2'}, function(setErr){
taistApi.companyData.getPart('foo', 'bar', function(getPartErr, part){
taistApi.log('foo.bar =', part);
taistApi.companyData.setPart('foo', 'baz', {newBaz: true}, function(setPartErr){
taistApi.companyData.get('foo', function(getErr, whole){
taistApi.log('foo =', whole);
})
})
})
})
/*
output:
foo.bar = 1
foo = {"bar":1,"baz":{"newBaz":true}}
*/