DataModelBase.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import onfire from 'onfire';
  2. export default class DataModelBase
  3. {
  4. constructor(modelName)
  5. {
  6. this._name = modelName;
  7. this._guid = onfire.getGuid();
  8. this._slice = Function.call.bind(Array.prototype.slice);
  9. }
  10. getModelName()
  11. {
  12. return this._name;
  13. }
  14. getAttributeEventID(attributeName)
  15. {
  16. return this._guid + attributeName;
  17. }
  18. on(attributeName,handler,context)
  19. {
  20. return onfire.on(this.getAttributeEventID(attributeName) ,handler,context);
  21. }
  22. off(event)
  23. {
  24. var type = typeof event;
  25. if (type === 'string') {
  26. onfire.un(this.getAttributeEventID(event));
  27. }
  28. else if (type === 'object' || type === 'function') {
  29. onfire.un(event);
  30. }
  31. }
  32. onReset()
  33. {
  34. }
  35. reset()
  36. {
  37. onfire.fireSync('reset',this);
  38. this.onReset();
  39. }
  40. onDestoy()
  41. {
  42. }
  43. destroy()
  44. {
  45. onfire.fireSync('destroy',this);
  46. this.onDestoy();
  47. }
  48. setData(msgId,pb)
  49. {
  50. }
  51. emit(attributeName)
  52. {
  53. onfire.fireSync(this.getAttributeEventID(attributeName),this,this._slice(arguments,1));
  54. }
  55. }