Notification.js 5.2 KB

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