index.js 760 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. function BaseRenderer () {
  3. }
  4. BaseRenderer.prototype.init = function (traversal) {
  5. var _this = this;
  6. traversal.on('start', function (context) {
  7. _this.onStart(context);
  8. });
  9. traversal.on('data', function (esNode) {
  10. _this.onData(esNode);
  11. });
  12. traversal.on('end', function () {
  13. _this.onEnd();
  14. });
  15. };
  16. BaseRenderer.prototype.setWritable = function (writable) {
  17. this.writable = writable;
  18. };
  19. // API
  20. BaseRenderer.prototype.onStart = function (context) {
  21. };
  22. // API
  23. BaseRenderer.prototype.onData = function (esNode) {
  24. };
  25. // API
  26. BaseRenderer.prototype.onEnd = function () {
  27. };
  28. // API
  29. BaseRenderer.prototype.write = function (str) {
  30. this.writable.write(str);
  31. };
  32. module.exports = BaseRenderer;