ng.data

simple data storage

ng.data: data persistence getter/setter

ng.data aims to make it dead simple to persist data

ng.data has a very simple API

ng.data = function(keyvaluepersist)
{
 
}

ng.data is just a getter/setter

module('example').controller('ctrl', function(data)
{
    var val = 'Hello!'
 
    //Store the value under key 
    data('key', val)
 
    //Get the value: logs Hello! 
    console.log(data('key'))
 
    //Delete the value 
    data('key', undefined)
})

If persist is truthy, data is persisted until deleted. On the client this is done with localStorage, on the server this is done with a JSON object.

If persist is undefined, data is persisted in memory only. On the client this is done with sessionStorage, on the server this is done with memory (until server restart).

If persist is falsey (but not undefined), data is stored as flash data. It will be available on the next location path change and then will be erased (this is great for alert messages)

Sometimes getters/setters can be annoying if you only want to manipulate data. ng.data has shorthand for these common manipulations

####incrementing verbose

module('example').controller('ctrl', function(data)
{
  var count = data('count')
 
  count += 5
 
  data('count', count)
})

shorthand

module('example').controller('ctrl', function(data)
{
  data('count+', 5)
})

####decrementing verbose

module('example').controller('ctrl', function(data)
{
  var count = data('count')
 
  count -= 5
 
  data('count', count)
})

shorthand

module('example').controller('ctrl', function(data)
{
  data('count-', 5)
})

verbose

module('example').controller('ctrl', function(data)
{
  var arr = data('arr')
 
  arr.push('Hello!')
 
  data('arr', arr)
})

shorthand note: this only works if arr is already an array

module('example').controller('ctrl', function(data)
{
  data('arr[]', 'Hello!')
})

verbose

module('example').controller('ctrl', function(data)
{
  var obj = data('obj')
 
  obj.prop = 'Hello!'
 
  data('obj', obj)
})

shorthand note: this only works if obj is already an object

module('example').controller('ctrl', function(data)
{
  data('obj.prop', 'Hello!')
})
  • Initial commit
  • ???
  • ng: angular reimagined
  • ng.seed: create a modular ng application using npm packages
  • ng.cql: realtime cassandra database syncing
  • ng.auth: example authentication using ng interceptors
  • ng.crud: example demonstrating a simple crud application using ng.seed
  • ng.style: beautiful html using twitter bootstrap