dojo/store/Memory.js

  • Provides:

    • dojo.store.Memory
  • dojo.store.Memory

    • type
      Function
    • summary
      Creates a memory object store.
    • parameters:
      • options: (typeof dojo.store.Memory)
        This provides any configuration information that will be mixed into the store.
        This should generally include the data property to provide the starting set of data.
    • source: [view]
        this.index = {};
        dojo.mixin(this, options);
        this.setData(this.data || []);
  • dojo.store.Memory.data

    • type
      Array
    • summary
      The array of all the objects in the memory store
  • dojo.store.Memory.idProperty

    • type
      String
    • summary
      Indicates the property to use as the identity property. The values of this
      property should be unique.
  • dojo.store.Memory.index

    • type
      Object
    • summary
      An index of data by id
  • dojo.store.Memory.queryEngine

    • type
      Function
    • summary
      Defines the query engine to use for querying the data store
  • dojo.store.Memory.get

    • type
      Function
    • parameters:
      • id: (typeof Number)
        The identity to use to lookup the object
    • source: [view]
        return this.index[id];
    • summary
      Retrieves an object by its identity
    • return_summary
      Object
      The object in the store that matches the given id.
  • dojo.store.Memory.getIdentity

    • type
      Function
    • parameters:
      • object: (typeof Object)
        The object to get the identity from
    • source: [view]
        return object[this.idProperty];
    • summary
      Returns an object's identity
    • return_summary
      Number
  • dojo.store.Memory.put

    • type
      Function
    • parameters:
      • object: (typeof Object)
        The object to store.
      • options: (typeof dojo.store.api.Store.PutDirectives?)
        Additional metadata for storing the data.  Includes an "id"
        property if a specific id is to be used.
    • source: [view]
        var id = options && options.id || object[this.idProperty] || Math.random();
        this.index[id] = object;
        var data = this.data,
         idProperty = this.idProperty;
        for(var i = 0, l = data.length; i < l; i++){
         if(data[i][idProperty] == id){
          data[i] = object;
          return id;
         }
        }
        this.data.push(object);
        return id;
    • summary
      Stores an object
    • return_summary
      Number
  • dojo.store.Memory.add

    • type
      Function
    • parameters:
      • object: (typeof Object)
        The object to store.
      • options: (typeof dojo.store.api.Store.PutDirectives?)
        Additional metadata for storing the data.  Includes an &quot;id&quot;
        property if a specific id is to be used.
    • source: [view]
        if(this.index[options && options.id || object[this.idProperty]]){
         throw new Error("Object already exists");
        }
        return this.put(object, options);
    • summary
      Creates an object, throws an error if the object already exists
    • return_summary
      Number
  • dojo.store.Memory.remove

    • type
      Function
    • parameters:
      • id: (typeof Number)
        The identity to use to delete the object
    • source: [view]
        delete this.index[id];
        var data = this.data,
         idProperty = this.idProperty;
        for(var i = 0, l = data.length; i < l; i++){
         if(data[i][idProperty] == id){
          data.splice(i, 1);
          return;
         }
        }
    • summary
      Deletes an object by its identity
  • dojo.store.Memory.query

    • type
      Function
    • parameters:
      • query: (typeof Object)
        The query to use for retrieving objects from the store.
      • options: (typeof dojo.store.api.Store.QueryOptions)
        The optional arguments to apply to the resultset.
    • source: [view]
        return dojo.store.util.QueryResults(this.queryEngine(query, options)(this.data));
    • summary
      Queries the store for objects.
    • return_summary
      dojo.store.api.Store.QueryResults
      The results of the query, extended with iterative methods.
    • example
      Given the following store:
      
      	var store = new dojo.store.Memory({
      		data: [
      			{id: 1, name: "one", prime: false },
      			{id: 2, name: "two", even: true, prime: true},
      			{id: 3, name: "three", prime: true},
      			{id: 4, name: "four", even: true, prime: false},
      			{id: 5, name: "five", prime: true}
      		]
      	});
      
      ...find all items where "prime" is true:
      
      	var results = store.query({ prime: true });
      
      ...or find all items where "even" is true:
      
      	var results = store.query({ even: true });
  • dojo.store.Memory.setData

    • type
      Function
    • parameters:
      • data: (typeof Object[)
        An array of objects to use as the source of data.
    • source: [view]
        if(data.items){
         // just for convenience with the data format IFRS expects
         this.idProperty = data.identifier;
         data = this.data = data.items;
        }else{
         this.data = data;
        }


        for(var i = 0, l = data.length; i < l; i++){
         var object = data[i];
         this.index[object[this.idProperty]] = object;
        }
    • summary
      Sets the given data as the source for this store, and indexes it
  • dojo.store.Memory.setData.data

    • type
      Object[
    • summary
      An array of objects to use as the source of data.
  • this

    • mixins:
      • options: (normal)
    • summary
  • dojo.store

    • type
      Object
    • summary
  • dojo

    • type
      Object
    • summary