Repository: playcanvas/engine
File: src/framework/components/render/component.js (JavaScript)

Code before:

    /**
     * Gets the render asset id for the render component.
     *
     * @type {number}
     */
    get asset() {
        return this._assetReference.id;
    }

    /**
     * Assign asset id to the component, without updating the component with the new asset.
     * This can be used to assign the asset id to already fully created component.
     *
     * @param {Asset|number} asset - The render asset or asset id to assign.
     * @ignore
     */
    assignAsset(asset) {
        const id = asset instanceof Asset ? asset.id : asset;
        this._assetReference.id = id;
    }

    /**
     * Sets the root bone entity (or entity guid) for the render component.
     *
     * @type {import('../../entity.js').Entity|string|null}
     */
    set rootBone(value) {
        if (this._rootBone !== value) {
            const isString = typeof value === 'string';
            if (this._rootBone && isString && this._rootBone.getGuid() === value) {
                return;
            }

            if (this._rootBone) {
                this._clearSkinInstances();
            }

            if (value instanceof GraphNode) {
                this._rootBone = value;
            } else if (isString) {
                this._rootBone = this.system.app.getEntityFromIndex(value) || null;
            } else {
                this._rootBone = null;
            }

            if (this._rootBone) {
                this._cloneSkinInstances();
            }
        }
    }

Review comment (bug):
I'm not a massive fan of having types differ for a single setter/getter pair. The previous type of `rootBone` was `Entity`. Seems correct to also allow `null`. Was the old type definition wrong for not specifying `string` was valid too?

Code after:
            this._onRenderAssetAdded();
        }
    }

    /**
     * Gets the render asset id for the render component.
     *
     * @type {number}
     */
    get asset() {
        return this._assetReference.id;
    }

    /**
     * Assign asset id to the component, without updating the component with the new asset.
     * This can be used to assign the asset id to already fully created component.
     *
     * @param {Asset|number} asset - The render asset or asset id to assign.
     * @ignore
     */
    assignAsset(asset) {
        const id = asset instanceof Asset ? asset.id : asset;
        this._assetReference.id = id;
    }

    /**
     * Sets the root bone entity (or entity guid) for the render component.
     *
     * @type {Entity|string|null}
     */
    set rootBone(value) {
        if (this._rootBone !== value) {
            const isString = typeof value === 'string';
            if (this._rootBone && isString && this._rootBone.getGuid() === value) {
                return;
            }

            if (this._rootBone) {
                this._clearSkinInstances();
            }

            if (value instanceof GraphNode) {
                this._rootBone = value;
            } else if (isString) {
                this._rootBone = this.system.app.getEntityFromIndex(value) || null;
                if (!this._rootBone) {
                    Debug.warn('Failed to find rootBone Entity by GUID');
                }
            } else {
                this._rootBone = null;
            }