CacheNode.js 568 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import Node from './Node.js';
  2. import NodeCache from './NodeCache.js';
  3. class CacheNode extends Node {
  4. constructor( node, cache = new NodeCache() ) {
  5. super();
  6. this.isCacheNode = true;
  7. this.node = node;
  8. this.cache = cache;
  9. }
  10. getNodeType( builder ) {
  11. return this.node.getNodeType( builder );
  12. }
  13. build( builder, ...params ) {
  14. const previousCache = builder.getCache();
  15. builder.setCache( this.cache );
  16. const data = this.node.build( builder, ...params );
  17. builder.setCache( previousCache );
  18. return data;
  19. }
  20. }
  21. export default CacheNode;