Identity.js 4.3 KB

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