Home Reference Source

cables_dev/cables/src/core/core_variable.js

  1. import { Events } from "cables-shared-client";
  2.  
  3. /**
  4. * @type {Object}
  5. * @name PatchVariable
  6. * @param {String} name
  7. * @param {String|Number} value
  8. * @memberof Patch
  9. * @constructor
  10. */
  11. class PatchVariable extends Events
  12. {
  13. constructor(name, val, type)
  14. {
  15. super();
  16. this._name = name;
  17. this.type = type;
  18. this.setValue(val);
  19. }
  20.  
  21. /**
  22. * keeping this for backwards compatibility in older
  23. * exports before using eventtarget
  24. *
  25. * @param cb
  26. */
  27. addListener(cb)
  28. {
  29. this.on("change", cb, "var");
  30. }
  31.  
  32. /**
  33. * @function Variable.getValue
  34. * @memberof PatchVariable
  35. * @returns {String|Number|Boolean}
  36. */
  37. getValue()
  38. {
  39. return this._v;
  40. }
  41.  
  42. /**
  43. * @function getName
  44. * @memberof PatchVariable
  45. * @instance
  46. * @returns {String|Number|Boolean}
  47. * @function
  48. */
  49. getName()
  50. {
  51. return this._name;
  52. }
  53.  
  54. /**
  55. * @function setValue
  56. * @memberof PatchVariable
  57. * @instance
  58. * @param v
  59. * @returns {String|Number|Boolean}
  60. * @function
  61. */
  62. setValue(v)
  63. {
  64. this._v = v;
  65. this.emitEvent("change", v, this);
  66. }
  67. }
  68.  
  69. export default PatchVariable;