dojox/data/KeyValueStore.js

  • Provides:

    • dojox.data.KeyValueStore
  • dojox.data.KeyValueStore

    • type
      Function
    • summary
      constructor
    • parameters:
      • keywordParameters: (typeof Object)
        dataVar: jsonObject}
    • source: [view]
        if(keywordParameters.url){
         this.url = keywordParameters.url;
        }
        this._keyValueString = keywordParameters.data;
        this._keyValueVar = keywordParameters.dataVar;
        this._keyAttribute = "key";
        this._valueAttribute = "value";
        this._storeProp = "_keyValueStore";
        this._features = {
         'dojo.data.api.Read': true,
         'dojo.data.api.Identity': true
        };
        this._loadInProgress = false; //Got to track the initial load to prevent duelling loads of the dataset.
        this._queuedFetches = [];
        if(keywordParameters && "urlPreventCache" in keywordParameters){
         this.urlPreventCache = keywordParameters.urlPreventCache?true:false;
        }
    • mixins:
      • dojo.data.util.simpleFetch: (prototype)
  • dojox.data.KeyValueStore.url

    • summary
  • dojox.data.KeyValueStore.data

    • summary
  • dojox.data.KeyValueStore.urlPreventCache

    • type
      boolean
    • summary
      Controls if urlPreventCache should be used with underlying xhrGet.
  • dojox.data.KeyValueStore._assertIsItem

    • type
      Function
    • parameters:
      • item: (typeof item)
        The item to test for being contained by the store.
    • source: [view]
        if(!this.isItem(item)){
         throw new Error("dojox.data.KeyValueStore: a function was passed an item argument that was not an item");
        }
    • summary
      This function tests whether the item passed in is indeed an item in the store.
  • dojox.data.KeyValueStore._assertIsAttribute

    • type
      Function
    • parameters:
      • item: (typeof item)
      • attribute: (typeof String)
        The attribute to test for being contained by the store.
    • source: [view]
        if(!dojo.isString(attribute)){
         throw new Error("dojox.data.KeyValueStore: a function was passed an attribute argument that was not an attribute object nor an attribute name string");
        }
    • summary
      This function tests whether the item passed in is indeed a valid 'attribute' like type for the store.
  • dojox.data.KeyValueStore.getValue

    • type
      Function
    • parameters:
      • item: (typeof item)
      • attribute: (typeof attribute-name-string)
      • defaultValue: (typeof value)
    • source: [view]
        this._assertIsItem(item);
        this._assertIsAttribute(item, attribute);
        var value;
        if(attribute == this._keyAttribute){ // Looking for key
         value = item[this._keyAttribute];
        }else{
         value = item[this._valueAttribute]; // Otherwise, attribute == ('value' || the actual key )
        }
        if(value === undefined){
         value = defaultValue;
        }
        return value;
    • summary
      See dojo.data.api.Read.getValue()
  • dojox.data.KeyValueStore.getValues

    • type
      Function
    • parameters:
      • item: (typeof item)
      • attribute: (typeof attribute-name-string)
    • source: [view]
        var value = this.getValue(item, attribute);
        return (value ? [value] : []); //Array
    • summary
      See dojo.data.api.Read.getValues()
      Key/Value syntax does not support multi-valued attributes, so this is just a
      wrapper function for getValue().
    • returns
      Array
  • dojox.data.KeyValueStore.getAttributes

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
        return [this._keyAttribute, this._valueAttribute, item[this._keyAttribute]];
    • summary
      See dojo.data.api.Read.getAttributes()
  • dojox.data.KeyValueStore.hasAttribute

    • type
      Function
    • parameters:
      • item: (typeof item)
      • attribute: (typeof attribute-name-string)
    • source: [view]
        this._assertIsItem(item);
        this._assertIsAttribute(item, attribute);
        return (attribute == this._keyAttribute || attribute == this._valueAttribute || attribute == item[this._keyAttribute]);
    • summary
      See dojo.data.api.Read.hasAttribute()
  • dojox.data.KeyValueStore.containsValue

    • type
      Function
    • parameters:
      • item: (typeof item)
      • attribute: (typeof attribute-name-string)
      • value: (typeof anything)
    • source: [view]
        var regexp = undefined;
        if(typeof value === "string"){
         regexp = dojo.data.util.filter.patternToRegExp(value, false);
        }
        return this._containsValue(item, attribute, value, regexp); //boolean.
    • summary
      See dojo.data.api.Read.containsValue()
    • returns
      boolean.
  • dojox.data.KeyValueStore._containsValue

    • type
      Function
    • parameters:
      • item: (typeof item)
        The data item to examine for attribute values.
      • attribute: (typeof attribute || attribute-name-string)
        The attribute to inspect.
      • value: (typeof anything)
        The value to match.
      • regexp: (typeof RegExp)
        Optional regular expression generated off value if value was of string type to handle wildcarding.
        If present and attribute values are string, then it can be used for comparison instead of 'value'
    • source: [view]
        var values = this.getValues(item, attribute);
        for(var i = 0; i < values.length; ++i){
         var possibleValue = values[i];
         if(typeof possibleValue === "string" && regexp){
          return (possibleValue.match(regexp) !== null);
         }else{
          //Non-string matching.
          if(value === possibleValue){
           return true; // Boolean
          }
         }
        }
        return false; // Boolean
    • summary
      Internal function for looking at the values contained by the item.
    • description
      Internal function for looking at the values contained by the item.  This
      function allows for denoting if the comparison should be case sensitive for
      strings or not (for handling filtering cases where string case should not matter)
    • returns
      Boolean
  • dojox.data.KeyValueStore.isItem

    • type
      Function
    • parameters:
      • something: (typeof anything)
    • source: [view]
        if(something && something[this._storeProp] === this){
         return true; //Boolean
        }
        return false; //Boolean
    • summary
      See dojo.data.api.Read.isItem()
    • returns
      Boolean
  • dojox.data.KeyValueStore.isItemLoaded

    • type
      Function
    • parameters:
      • something: (typeof anything)
    • source: [view]
        return this.isItem(something); //Boolean
    • summary
      See dojo.data.api.Read.isItemLoaded()
      The KeyValueStore always loads all items, so if it's an item, then it's loaded.
    • returns
      Boolean
  • dojox.data.KeyValueStore.loadItem

    • type
      Function
    • parameters:
      • keywordArgs: (typeof object)
    • source: [view]
        // summary:
        //  See dojo.data.api.Read.loadItem()
        // description:
        //  The KeyValueStore always loads all items, so if it's an item, then it's loaded.
        //  From the dojo.data.api.Read.loadItem docs:
        //   If a call to isItemLoaded() returns true before loadItem() is even called,
        //   then loadItem() need not do any work at all and will not even invoke
        //   the callback handlers.
    • summary
      See dojo.data.api.Read.loadItem()
    • description
      The KeyValueStore always loads all items, so if it's an item, then it's loaded.
      From the dojo.data.api.Read.loadItem docs:
      If a call to isItemLoaded() returns true before loadItem() is even called,
      then loadItem() need not do any work at all and will not even invoke
      the callback handlers.
  • dojox.data.KeyValueStore.getFeatures

    • type
      Function
    • source: [view]
        return this._features; //Object
    • summary
      See dojo.data.api.Read.getFeatures()
    • returns
      Object
  • dojox.data.KeyValueStore.close

    • type
      Function
    • parameters:
      • request: (typeof dojo.data.api.Request || keywordArgs || null)
    • source: [view]
        // summary:
        //  See dojo.data.api.Read.close()
    • summary
      See dojo.data.api.Read.close()
  • dojox.data.KeyValueStore.getLabel

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
        return item[this._keyAttribute];
    • summary
      See dojo.data.api.Read.getLabel()
  • dojox.data.KeyValueStore.getLabelAttributes

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
        return [this._keyAttribute];
    • summary
      See dojo.data.api.Read.getLabelAttributes()
  • dojox.data.KeyValueStore._fetchItems

    • type
      Function
    • parameters:
      • keywordArgs: (typeof Object)
      • findCallback: (typeof Function)
      • errorCallback: (typeof Function)
    • source: [view]
        var self = this;


        var filter = function(requestArgs, arrayOfAllItems){
         var items = null;
         if(requestArgs.query){
          items = [];
          var ignoreCase = requestArgs.queryOptions ? requestArgs.queryOptions.ignoreCase : false;


          //See if there are any string values that can be regexp parsed first to avoid multiple regexp gens on the
          //same value for each item examined. Much more efficient.
          var regexpList = {};
          for(var key in requestArgs.query){
           var value = requestArgs.query[key];
           if(typeof value === "string"){
            regexpList[key] = dojo.data.util.filter.patternToRegExp(value, ignoreCase);
           }
          }


          for(var i = 0; i < arrayOfAllItems.length; ++i){
           var match = true;
           var candidateItem = arrayOfAllItems[i];
           for(var key in requestArgs.query){
            var value = requestArgs.query[key];
            if(!self._containsValue(candidateItem, key, value, regexpList[key])){
             match = false;
            }
           }
           if(match){
            items.push(candidateItem);
           }
          }
         }else if(requestArgs.identity){
          items = [];
          var item;
          for(var key in arrayOfAllItems){
           item = arrayOfAllItems[key];
           if(item[self._keyAttribute] == requestArgs.identity){
            items.push(item);
            break;
           }
          }
         }else{
          // We want a copy to pass back in case the parent wishes to sort the array. We shouldn't allow resort
          // of the internal list so that multiple callers can get lists and sort without affecting each other.
          if(arrayOfAllItems.length> 0){
           items = arrayOfAllItems.slice(0,arrayOfAllItems.length);
          }
         }
         findCallback(items, requestArgs);
        };


        if(this._loadFinished){
         filter(keywordArgs, this._arrayOfAllItems);
        }else{
         if(this.url !== ""){
          //If fetches come in before the loading has finished, but while
          //a load is in progress, we have to defer the fetching to be
          //invoked in the callback.
          if(this._loadInProgress){
           this._queuedFetches.push({args: keywordArgs, filter: filter});
          }else{
           this._loadInProgress = true;
           var getArgs = {
             url: self.url,
             handleAs: "json-comment-filtered",
             preventCache: this.urlPreventCache
            };
           var getHandler = dojo.xhrGet(getArgs);
           getHandler.addCallback(function(data){
            self._processData(data);
            filter(keywordArgs, self._arrayOfAllItems);
            self._handleQueuedFetches();
           });
           getHandler.addErrback(function(error){
            self._loadInProgress = false;
            throw error;
           });
          }
         }else if(this._keyValueString){
          this._processData(eval(this._keyValueString));
          this._keyValueString = null;
          filter(keywordArgs, this._arrayOfAllItems);
         }else if(this._keyValueVar){
          this._processData(this._keyValueVar);
          this._keyValueVar = null;
          filter(keywordArgs, this._arrayOfAllItems);
         }else{
          throw new Error("dojox.data.KeyValueStore: No source data was provided as either URL, String, or Javascript variable data input.");
         }
        }
    • summary
      See dojo.data.util.simpleFetch.fetch()
  • dojox.data.KeyValueStore._handleQueuedFetches

    • type
      Function
    • source: [view]
        if(this._queuedFetches.length > 0){
         for(var i = 0; i < this._queuedFetches.length; i++){
          var fData = this._queuedFetches[i];
          var delayedFilter = fData.filter;
          var delayedQuery = fData.args;
          if(delayedFilter){
           delayedFilter(delayedQuery, this._arrayOfAllItems);
          }else{
           this.fetchItemByIdentity(fData.args);
          }
         }
         this._queuedFetches = [];
        }
    • summary
      Internal function to execute delayed request in the store.
      Execute any deferred fetches now.
  • dojox.data.KeyValueStore._processData

    • type
      Function
    • parameters:
      • data: (typeof Array)
    • source: [view]
        this._arrayOfAllItems = [];
        for(var i=0; i   this._arrayOfAllItems.push(this._createItem(data[i]));
        }
        this._loadFinished = true;
        this._loadInProgress = false;
    • summary
  • dojox.data.KeyValueStore._createItem

    • type
      Function
    • parameters:
      • something: (typeof Object)
    • source: [view]
        var item = {};
        item[this._storeProp] = this;
        for(var i in something){
         item[this._keyAttribute] = i;
         item[this._valueAttribute] = something[i];
         break;
        }
        return item; //Object
    • returns
      Object
    • summary
  • dojox.data.KeyValueStore.getIdentity

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
        if(this.isItem(item)){
         return item[this._keyAttribute]; //String
        }
        return null; //null
    • summary
      See dojo.data.api.Identity.getIdentity()
    • returns
      String|null
  • dojox.data.KeyValueStore.getIdentityAttributes

    • type
      Function
    • parameters:
      • item: (typeof item)
    • source: [view]
        return [this._keyAttribute];
    • summary
      See dojo.data.api.Identity.getIdentifierAttributes()
  • dojox.data.KeyValueStore.fetchItemByIdentity

    • type
      Function
    • parameters:
      • keywordArgs: (typeof object)
    • source: [view]
        keywordArgs.oldOnItem = keywordArgs.onItem;
        keywordArgs.onItem = null;
        keywordArgs.onComplete = this._finishFetchItemByIdentity ;
        this.fetch(keywordArgs);
    • summary
      See dojo.data.api.Identity.fetchItemByIdentity()
  • dojox.data.KeyValueStore._finishFetchItemByIdentity

    • type
      Function
    • parameters:
      • items: (typeof Array)
      • request: (typeof object)
    • source: [view]
        var scope = request.scope || dojo.global;
        if(items.length){
         request.oldOnItem.call(scope, items[0]);
        }else{
         request.oldOnItem.call(scope, null);
        }
    • chains:
      • request.oldOnItem: (call)
    • summary
  • dojox.data.KeyValueStore._loadInProgress

    • summary
  • dojox.data.KeyValueStore._keyValueString

    • summary
  • dojox.data.KeyValueStore._keyValueVar

    • summary
  • dojox.data.KeyValueStore._queuedFetches

    • summary
  • dojox.data.KeyValueStore._arrayOfAllItems

    • summary
  • dojox.data.KeyValueStore._loadFinished

    • summary
  • dojox.data.KeyValueStore._keyAttribute

    • summary
  • dojox.data.KeyValueStore._valueAttribute

    • summary
  • dojox.data.KeyValueStore._storeProp

    • summary
  • dojox.data.KeyValueStore._features

    • summary
  • dojox.data

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary