libs/generated/lawnchair.js
function(name) {
    return {
      // the key
      key: name + '._index_',
      // returns the index
      all: function() {
        var a  = storage.getItem(this.key)
        if (a) {
          a = JSON.parse(a)
        }
        if (a === null) storage.setItem(this.key, JSON.stringify([])) // lazy init
        return JSON.parse(storage.getItem(this.key))
      },
      // adds a key to the index
      add: function (key) {
        var a = this.all()
        a.push(key)
        storage.setItem(this.key, JSON.stringify(a))
      },
      // deletes a key from the index
      del: function (key) {
        var a = this.all(), r = []
        // FIXME this is crazy inefficient but I'm in a strata meeting and half concentrating
        for (var i = 0, l = a.length; i < l; i++) {
          if (a[i] != key) r.push(a[i])
        }
        storage.setItem(this.key, JSON.stringify(r))
      },
      // returns index for a key
      find: function (key) {
        var a = this.all()
        for (var i = 0, l = a.length; i < l; i++) {
          if (key === a[i]) return i
        }
        return false
      }
    }
  }
function(name) {
    return {
      // the key
      key: name + '._index_',
      // returns the index
      all: function() {
        var a  = storage.getItem(this.key)
        if (a) {
          a = JSON.parse(a)
        }
        if (a === null) storage.setItem(this.key, JSON.stringify([])) // lazy init
        return JSON.parse(storage.getItem(this.key))
      },
      // adds a key to the index
      add: function (key) {
        var a = this.all()
        a.push(key)
        storage.setItem(this.key, JSON.stringify(a))
      },
      // deletes a key from the index
      del: function (key) {
        var a = this.all(), r = []
        // FIXME this is crazy inefficient but I'm in a strata meeting and half concentrating
        for (var i = 0, l = a.length; i < l; i++) {
          if (a[i] != key) r.push(a[i])
        }
        storage.setItem(this.key, JSON.stringify(r))
      },
      // returns index for a key
      find: function (key) {
        var a = this.all()
        for (var i = 0, l = a.length; i < l; i++) {
          if (key === a[i]) return i
        }
        return false
      }
    }
  }
function ( name ) { return { // the key key : name + '._index_' , // returns the index all : function ( ) { var a = storage . getItem ( this . key ) if ( a ) { a = JSON . parse ( a ) } if ( a === null ) storage . setItem ( this . key , JSON . stringify ( [ ] ) ) // lazy init return JSON . parse ( storage . getItem ( this . key ) ) } , // adds a key to the index add : function ( key ) { var a = this . all ( ) a . push ( key ) storage . setItem ( this . key , JSON . stringify ( a ) ) } , // deletes a key from the index del : function ( key ) { var a = this . all ( ) , r = [ ] // FIXME this is crazy inefficient but I'm in a strata meeting and half concentrating for ( var i = 0 , l = a . length ; i < l ; i ++ ) { if ( a [ i ] != key ) r . push ( a [ i ] ) } storage . setItem ( this . key , JSON . stringify ( r ) ) } , // returns index for a key find : function ( key ) { var a = this . all ( ) for ( var i = 0 , l = a . length ; i < l ; i ++ ) { if ( key === a [ i ] ) return i } return false } } }
the indexer is an encapsulation of the helpers needed to keep an ordered index of the keys
the indexer is an encapsulation of the helpers needed to keep an ordered index of the keys