Proxy.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. --[[
  2. * @author PureMVC Lua Native Port by Sean
  3. * @author Copyright(c) 2006-2012 Futurescale, Inc., Some rights reserved.
  4. *
  5. * @class puremvc.Proxy
  6. * @extends puremvc.Notifier
  7. *
  8. * A base Proxy implementation.
  9. *
  10. * In PureMVC, Proxy classes are used to manage parts of the application's data
  11. * model.
  12. *
  13. * A Proxy might simply manage a reference to a local data object, in which case
  14. * interacting with it might involve setting and getting of its data in
  15. * synchronous fashion.
  16. *
  17. * Proxy classes are also used to encapsulate the application's interaction with
  18. * remote services to save or retrieve data, in which case, we adopt an
  19. * asyncronous idiom; setting data (or calling a method) on the Proxy and
  20. * listening for a
  21. * {@link puremvc.Notification Notification}
  22. * to be sent when the Proxy has retrieved the data from the service.
  23. *
  24. *
  25. * @param {string} [proxyName]
  26. * The Proxy's name. If none is provided, the Proxy will use its constructors
  27. * NAME property.
  28. * @param {Object} [data]
  29. * The Proxy's data object
  30. * @constructor
  31. ]]
  32. local Notifier = require( framework.PACKAGE_NAME .. '/patterns/observer/Notifier')
  33. local Proxy = class('Proxy', Notifier)
  34. function Proxy:ctor(proxyName, data)
  35. self.proxyName = proxyName or Proxy.NAME
  36. if data ~= nil then
  37. self:setData(data)
  38. end
  39. end
  40. Proxy.NAME = "Proxy"
  41. --[[
  42. * Get the Proxy's name.
  43. *
  44. * @return {string}
  45. ]]
  46. function Proxy:getProxyName()
  47. return self.proxyName
  48. end
  49. --[[
  50. * Set the Proxy's data object
  51. *
  52. * @param {Object} data
  53. * @return {void}
  54. ]]
  55. function Proxy:setData(data)
  56. self.data = data
  57. end
  58. --[[
  59. * Get the Proxy's data object
  60. *
  61. * @return {Object}
  62. ]]
  63. function Proxy:getData()
  64. return self.data
  65. end
  66. --[[
  67. * Called by the {@link puremvc.Model Model} when
  68. * the Proxy is registered.
  69. *
  70. * @return {void}
  71. ]]
  72. function Proxy:onRegister()
  73. end
  74. --[[
  75. * Called by the {@link puremvc.Model Model} when
  76. * the Proxy is removed.
  77. *
  78. * @return {void}
  79. ]]
  80. function Proxy:onRemove()
  81. end
  82. return Proxy