Skip to content

Bug: bemDom.declBlock with mixins #1549

@belozer

Description

@belozer

Bug case

const Mixin = bemDom.declMixin({ myProp : 'test' });
Block = bemDom.declBlock('block', [Mixin]);

Block.prototype.findChildBlock // undefined

but

const Mixin = bemDom.declMixin({ myProp : 'test' });
Block = bemDom.declBlock('block', [bemDom.Block, Mixin]);

Block.prototype.findChildBlock // function

After add code (This is the draft version of the solution. It remains to do right now.)

    /**
     * Declares DOM-based block and creates block class
     * @param {String|Function} blockName Block name or block class
     * @param {Function|Array[Function]} [base] base block + mixes
     * @param {Object} [props] Methods
     * @param {Object} [staticProps] Static methods
     * @returns {Function} Block class
     */
    declBlock : function(blockName, base, props, staticProps) {
        if(!base || (typeof base === 'object' && !Array.isArray(base))) {
            staticProps = props;
            props = base;
            base = typeof blockName === 'string'?
                entities[blockName] || Block :
                blockName;
        }

        // added code start
        base || (base = entities[blockName] || Block);

        Array.isArray(base) || (base = [base]);

        if(!base[0].__bemEntity) {
            base = base.slice();
            base.unshift(entities[blockName] || Block);
        }
         // added code end

        return bem.declBlock(blockName, base, props, staticProps);
    },
Block = bemDom.declBlock('block', [Mixin]);
Block.prototype.findChildBlock // function

P.S.
A problem can also be with elements

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions