document.js 654 B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict'
  2. let Container = require('./container')
  3. let LazyResult, Processor
  4. class Document extends Container {
  5. constructor(defaults) {
  6. // type needs to be passed to super, otherwise child roots won't be normalized correctly
  7. super({ type: 'document', ...defaults })
  8. if (!this.nodes) {
  9. this.nodes = []
  10. }
  11. }
  12. toResult(opts = {}) {
  13. let lazy = new LazyResult(new Processor(), this, opts)
  14. return lazy.stringify()
  15. }
  16. }
  17. Document.registerLazyResult = dependant => {
  18. LazyResult = dependant
  19. }
  20. Document.registerProcessor = dependant => {
  21. Processor = dependant
  22. }
  23. module.exports = Document
  24. Document.default = Document