Notification.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. define("dojo/data/api/Notification", ["../..", "./Read"], function(dojo) {
  2. // module:
  3. // dojo/data/api/Notification
  4. // summary:
  5. // TODOC
  6. dojo.declare("dojo.data.api.Notification", dojo.data.api.Read, {
  7. // summary:
  8. // This is an abstract API that data provider implementations conform to.
  9. // This file defines functions signatures and intentionally leaves all the
  10. // functions unimplemented.
  11. //
  12. // description:
  13. // This API defines a set of APIs that all datastores that conform to the
  14. // Notifications API must implement. In general, most stores will implement
  15. // these APIs as no-op functions for users who wish to monitor them to be able
  16. // to connect to then via dojo.connect(). For non-users of dojo.connect,
  17. // they should be able to just replace the function on the store to obtain
  18. // notifications. Both read-only and read-write stores may implement
  19. // this feature. In the case of a read-only store, this feature makes sense if
  20. // the store itself does internal polling to a back-end server and periodically updates
  21. // its cache of items (deletes, adds, and updates).
  22. //
  23. // example:
  24. //
  25. // | function onSet(item, attribute, oldValue, newValue) {
  26. // | //Do something with the information...
  27. // | };
  28. // | var store = new some.newStore();
  29. // | dojo.connect(store, "onSet", onSet);
  30. getFeatures: function(){
  31. // summary:
  32. // See dojo.data.api.Read.getFeatures()
  33. return {
  34. 'dojo.data.api.Read': true,
  35. 'dojo.data.api.Notification': true
  36. };
  37. },
  38. onSet: function(/* item */ item,
  39. /* attribute-name-string */ attribute,
  40. /* object|array */ oldValue,
  41. /* object|array */ newValue){
  42. // summary:
  43. // This function is called any time an item is modified via setValue, setValues, unsetAttribute, etc.
  44. // description:
  45. // This function is called any time an item is modified via setValue, setValues, unsetAttribute, etc.
  46. // Its purpose is to provide a hook point for those who wish to monitor actions on items in the store
  47. // in a simple manner. The general expected usage is to dojo.connect() to the store's
  48. // implementation and be called after the store function is called.
  49. //
  50. // item:
  51. // The item being modified.
  52. // attribute:
  53. // The attribute being changed represented as a string name.
  54. // oldValue:
  55. // The old value of the attribute. In the case of single value calls, such as setValue, unsetAttribute, etc,
  56. // this value will be generally be an atomic value of some sort (string, int, etc, object). In the case of
  57. // multi-valued attributes, it will be an array.
  58. // newValue:
  59. // The new value of the attribute. In the case of single value calls, such as setValue, this value will be
  60. // generally be an atomic value of some sort (string, int, etc, object). In the case of multi-valued attributes,
  61. // it will be an array. In the case of unsetAttribute, the new value will be 'undefined'.
  62. //
  63. // returns:
  64. // Nothing.
  65. throw new Error('Unimplemented API: dojo.data.api.Notification.onSet');
  66. },
  67. onNew: function(/* item */ newItem, /*object?*/ parentInfo){
  68. // summary:
  69. // This function is called any time a new item is created in the store.
  70. // It is called immediately after the store newItem processing has completed.
  71. // description:
  72. // This function is called any time a new item is created in the store.
  73. // It is called immediately after the store newItem processing has completed.
  74. //
  75. // newItem:
  76. // The item created.
  77. // parentInfo:
  78. // An optional javascript object that is passed when the item created was placed in the store
  79. // hierarchy as a value f another item's attribute, instead of a root level item. Note that if this
  80. // function is invoked with a value for parentInfo, then onSet is not invoked stating the attribute of
  81. // the parent item was modified. This is to avoid getting two notification events occurring when a new item
  82. // with a parent is created. The structure passed in is as follows:
  83. // {
  84. // item: someItem, //The parent item
  85. // attribute: "attribute-name-string", //The attribute the new item was assigned to.
  86. // oldValue: something //Whatever was the previous value for the attribute.
  87. // //If it is a single-value attribute only, then this value will be a single value.
  88. // //If it was a multi-valued attribute, then this will be an array of all the values minues the new one.
  89. // newValue: something //The new value of the attribute. In the case of single value calls, such as setValue, this value will be
  90. // //generally be an atomic value of some sort (string, int, etc, object). In the case of multi-valued attributes,
  91. // //it will be an array.
  92. // }
  93. //
  94. // returns:
  95. // Nothing.
  96. throw new Error('Unimplemented API: dojo.data.api.Notification.onNew');
  97. },
  98. onDelete: function(/* item */ deletedItem){
  99. // summary:
  100. // This function is called any time an item is deleted from the store.
  101. // It is called immediately after the store deleteItem processing has completed.
  102. // description:
  103. // This function is called any time an item is deleted from the store.
  104. // It is called immediately after the store deleteItem processing has completed.
  105. //
  106. // deletedItem:
  107. // The item deleted.
  108. //
  109. // returns:
  110. // Nothing.
  111. throw new Error('Unimplemented API: dojo.data.api.Notification.onDelete');
  112. }
  113. });
  114. return dojo.data.api.Notification;
  115. });