Identity.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. define("dojo/data/api/Identity", ["../..", "./Read"], function(dojo) {
  2. // module:
  3. // dojo/data/api/Identity
  4. // summary:
  5. // TODOC
  6. dojo.declare("dojo.data.api.Identity", dojo.data.api.Read, {
  7. // summary:
  8. // This is an abstract API that data provider implementations conform to.
  9. // This file defines methods signatures and intentionally leaves all the
  10. // methods unimplemented.
  11. getFeatures: function(){
  12. // summary:
  13. // See dojo.data.api.Read.getFeatures()
  14. return {
  15. 'dojo.data.api.Read': true,
  16. 'dojo.data.api.Identity': true
  17. };
  18. },
  19. getIdentity: function(/* item */ item){
  20. // summary:
  21. // Returns a unique identifier for an item. The return value will be
  22. // either a string or something that has a toString() method (such as,
  23. // for example, a dojox.uuid.Uuid object).
  24. // item:
  25. // The item from the store from which to obtain its identifier.
  26. // exceptions:
  27. // Conforming implementations may throw an exception or return null if
  28. // item is not an item.
  29. // example:
  30. // | var itemId = store.getIdentity(kermit);
  31. // | assert(kermit === store.findByIdentity(store.getIdentity(kermit)));
  32. throw new Error('Unimplemented API: dojo.data.api.Identity.getIdentity');
  33. },
  34. getIdentityAttributes: function(/* item */ item){
  35. // summary:
  36. // Returns an array of attribute names that are used to generate the identity.
  37. // For most stores, this is a single attribute, but for some complex stores
  38. // such as RDB backed stores that use compound (multi-attribute) identifiers
  39. // it can be more than one. If the identity is not composed of attributes
  40. // on the item, it will return null. This function is intended to identify
  41. // the attributes that comprise the identity so that so that during a render
  42. // of all attributes, the UI can hide the the identity information if it
  43. // chooses.
  44. // item:
  45. // The item from the store from which to obtain the array of public attributes that
  46. // compose the identifier, if any.
  47. // example:
  48. // | var itemId = store.getIdentity(kermit);
  49. // | var identifiers = store.getIdentityAttributes(itemId);
  50. // | assert(typeof identifiers === "array" || identifiers === null);
  51. throw new Error('Unimplemented API: dojo.data.api.Identity.getIdentityAttributes');
  52. },
  53. fetchItemByIdentity: function(/* object */ keywordArgs){
  54. // summary:
  55. // Given the identity of an item, this method returns the item that has
  56. // that identity through the onItem callback. Conforming implementations
  57. // should return null if there is no item with the given identity.
  58. // Implementations of fetchItemByIdentity() may sometimes return an item
  59. // from a local cache and may sometimes fetch an item from a remote server,
  60. //
  61. // keywordArgs:
  62. // An anonymous object that defines the item to locate and callbacks to invoke when the
  63. // item has been located and load has completed. The format of the object is as follows:
  64. // {
  65. // identity: string|object,
  66. // onItem: Function,
  67. // onError: Function,
  68. // scope: object
  69. // }
  70. // The *identity* parameter.
  71. // The identity parameter is the identity of the item you wish to locate and load
  72. // This attribute is required. It should be a string or an object that toString()
  73. // can be called on.
  74. //
  75. // The *onItem* parameter.
  76. // Function(item)
  77. // The onItem parameter is the callback to invoke when the item has been loaded. It takes only one
  78. // parameter, the item located, or null if none found.
  79. //
  80. // The *onError* parameter.
  81. // Function(error)
  82. // The onError parameter is the callback to invoke when the item load encountered an error. It takes only one
  83. // parameter, the error object
  84. //
  85. // The *scope* parameter.
  86. // If a scope object is provided, all of the callback functions (onItem,
  87. // onError, etc) will be invoked in the context of the scope object.
  88. // In the body of the callback function, the value of the "this"
  89. // keyword will be the scope object. If no scope object is provided,
  90. // the callback functions will be called in the context of dojo.global.
  91. // For example, onItem.call(scope, item, request) vs.
  92. // onItem.call(dojo.global, item, request)
  93. if(!this.isItemLoaded(keywordArgs.item)){
  94. throw new Error('Unimplemented API: dojo.data.api.Identity.fetchItemByIdentity');
  95. }
  96. }
  97. });
  98. return dojo.data.api.Identity;
  99. });