Skip to content

⬅️ Back to Table of Contents

📄 NodeCache.js

📊 Analysis Summary

Metric Count
🔧 Functions 2
🧱 Classes 1
📊 Variables & Constants 1

📚 Table of Contents

🛠️ File Location:

📂 src/nodes/core/NodeCache.js

Variables & Constants

Name Type Kind Value Exported
_id number let/var 0

Functions

NodeCache.getData(node: Node): any

JSDoc:

/**
     * Returns the data for the given node.
     *
     * @param {Node} node - The node.
     * @return {?Object} The data for the node.
     */

Parameters:

  • node Node

Returns: any

Calls:

  • this.nodesData.get
  • this.parent.getData
Code
getData( node ) {

        let data = this.nodesData.get( node );

        if ( data === undefined && this.parent !== null ) {

            data = this.parent.getData( node );

        }

        return data;

    }

NodeCache.setData(node: Node, data: any): void

JSDoc:

/**
     * Sets the data for a given node.
     *
     * @param {Node} node - The node.
     * @param {Object} data - The data that should be cached.
     */

Parameters:

  • node Node
  • data any

Returns: void

Calls:

  • this.nodesData.set
Code
setData( node, data ) {

        this.nodesData.set( node, data );

    }

Classes

NodeCache

Class Code
class NodeCache {

    /**
     * Constructs a new node cache.
     *
     * @param {?NodeCache} parent - A reference to a parent cache.
     */
    constructor( parent = null ) {

        /**
         * The id of the cache.
         *
         * @type {number}
         * @readonly
         */
        this.id = _id ++;

        /**
         * A weak map for managing node data.
         *
         * @type {WeakMap<Node, Object>}
         */
        this.nodesData = new WeakMap();

        /**
         * Reference to a parent node cache.
         *
         * @type {?NodeCache}
         * @default null
         */
        this.parent = parent;

    }

    /**
     * Returns the data for the given node.
     *
     * @param {Node} node - The node.
     * @return {?Object} The data for the node.
     */
    getData( node ) {

        let data = this.nodesData.get( node );

        if ( data === undefined && this.parent !== null ) {

            data = this.parent.getData( node );

        }

        return data;

    }

    /**
     * Sets the data for a given node.
     *
     * @param {Node} node - The node.
     * @param {Object} data - The data that should be cached.
     */
    setData( node, data ) {

        this.nodesData.set( node, data );

    }

}

Methods

getData(node: Node): any
Code
getData( node ) {

        let data = this.nodesData.get( node );

        if ( data === undefined && this.parent !== null ) {

            data = this.parent.getData( node );

        }

        return data;

    }
setData(node: Node, data: any): void
Code
setData( node, data ) {

        this.nodesData.set( node, data );

    }