Commit 890f68fd authored by Jared Jurkiewicz's avatar Jared Jurkiewicz

API update for dojo.data.api.Identity. refs #3554

git-svn-id: http://svn.dojotoolkit.org/src/dojo/trunk@9351 560b804f-0ae3-0310-86f3-f6aa0a117693
parent 83977c27
......@@ -418,21 +418,72 @@ dojo.declare("dojo.data.JsonItemStore",
return null; //null
},
getItemByIdentity: function(/* String */ identity){
fetchItemByIdentity: function(/* Object */ keywordArgs){
// summary:
// See dojo.data.api.Identity.getItemByIdentity()
// See dojo.data.api.Identity.fetchItemByIdentity()
// Force a sync'ed load if it hasn't occurred yet
//Hasn't loaded yet, we have to trigger the load.
if(!this._loadFinished){
this._forceLoad();
var self = this;
if(this._jsonFileUrl){
var getArgs = {
url: self._jsonFileUrl,
handleAs: "json-comment-optional"
};
var getHandler = dojo.xhrGet(getArgs);
getHandler.addCallback(function(data){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
try{
self._arrayOfAllItems = self._getItemsFromLoadedData(data);
self._loadFinished = true;
var item = self._getItemByIdentity(keywordArgs.identity);
if(keywordArgs.onItem){
keywordArgs.onItem.call(scope, item);
}
}catch(error){
if(keywordArgs.onError){
keywordArgs.onError.call(scope, error);
}
}
});
getHandler.addErrback(function(error){
if(keywordArgs.onError){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
keywordArgs.onError.call(scope, error);
}
});
}else if(this._jsonData){
//Passe din data, no need to xhr.
self._arrayOfAllItems = self._getItemsFromLoadedData(self._jsonData);
self._jsonData = null;
self._loadFinished = true;
var item = self._getItemByIdentity(keywordArgs.identity);
if(keywordArgs.onItem){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
keywordArgs.onItem.call(scope, item);
}
}
}else{
//Already loaded. We can just look it up and call back.
var item = this._getItemByIdentity(keywordArgs.identity);
if(keywordArgs.onItem){
var scope = keywordArgs.scope?keywordArgs.scope:dojo.global;
keywordArgs.onItem.call(scope, item);
}
}
},
_getItemByIdentity: function(/* Object */ identity){
// summary:
// Internal function to look an item up by its identity map.
var item = null;
if(this._itemsByIdentity){
var item = this._itemsByIdentity[identity];
if(item !== undefined){
return item; //Object
item = this._itemsByIdentity[identity];
if(item === undefined){
item = null;
}
}
return null; //null
return item; // Object
},
getIdentityAttributes: function(/* item */ item){
......
......@@ -20,7 +20,7 @@ dojo.declare("dojo.data.api.Identity",dojo.data.api.Read,null,{
// summary:
// Returns a unique identifier for an item. The return value will be
// either a string or something that has a toString() method (such as,
// for example, a dojo.uuid.Uuid object).
// for example, a dojox.uuid.Uuid object).
// item:
// The item from the store from which to obtain its identifier.
// exceptions:
......@@ -55,25 +55,49 @@ dojo.declare("dojo.data.api.Identity",dojo.data.api.Read,null,{
return null; // string
},
getItemByIdentity: function(/* string || object */ identity){
fetchItemByIdentity: function(/* object */ keywordArgs){
// summary:
// Given the identity of an item, this method returns the item that has
// that identity. Conforming implementations should return null if there
// is no item with the given identity. Implementations of getItemByIdentity()
// may sometimes return an item from a local cache and may sometimes
// fetch an item from a remote server, in which case the call to
// getItemByIdentity() will block until the getItemByIdentity() implementation
// has the item to return.
// that identity through the onItem callback. Conforming implementations
// should return null if there is no item with the given identity.
// Implementations of fetchItemByIdentity() may sometimes return an item
// from a local cache and may sometimes fetch an item from a remote server,
//
// identity:
// The identity of the object to locate. It should be a string or an
// object that toString() can be called on (such as a dojo.uuid object).
// keywordArgs:
// An anonymous object that defines the item to locate and callbacks to invoke when the
// item has been located and load has completed. The format of the object is as follows:
// {
// identity: string|object,
// onItem: Function,
// onError: Function,
// scope: object
// }
// The *identity* parameter.
// The identity parameter is the identity of the item you wish to locate and load
// This attribute is required. It should be a string or an object that toString()
// can be called on.
//
// The *onItem* parameter.
// Function(item)
// The onItem parameter is the callback to invoke when the item has been loaded. It takes only one
// parameter, the item located, or null if none found.
//
// examples:
// var alaska = store.getItemByIdentity("AK");
// assert("AK" == store.getItemByIdentity(store.getItemByIdentity("AK")));
throw new Error('Unimplemented API: dojo.data.api.Identity.getItemByIdentity');
var item = null;
return item; // item
// The *onError* parameter.
// Function(error)
// The onError parameter is the callback to invoke when the item load encountered an error. It takes only one
// parameter, the error object
//
// The *scope* parameter.
// If a scope object is provided, all of the callback functions (onItem,
// onError, etc) will be invoked in the context of the scope object.
// In the body of the callback function, the value of the "this"
// keyword will be the scope object. If no scope object is provided,
// the callback functions will be called in the context of dojo.global.
// For example, onItem.call(scope, item, request) vs.
// onItem.call(dojo.global, item, request)
if (!this.isItemLoaded(keywordArgs.item)) {
throw new Error('Unimplemented API: dojo.data.api.Identity.fetchItemByIdentity');
}
}
});
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment