Notification.js 5.6 KB

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