diff --git a/docs/modules/Components.md b/docs/modules/Components.md index d92aa0792..f40aea2eb 100644 --- a/docs/modules/Components.md +++ b/docs/modules/Components.md @@ -282,7 +282,7 @@ comps.addType('map', { ... }, { isComponent(el) { - // ... new logic for isComponent + // ... usually, you'd reuse the same logic }, }), // Even if I do nothing in view, I have to specify it @@ -291,14 +291,14 @@ comps.addType('map', { ``` **After** -The `map` type is already defined, so it will be used as a base for the model and view +The `map` type is already defined, so it will be used as a base for the model and view. +We can skip `isComponent` if the recognition logic is the same of the extended component. ```js comps.addType('map', { - isComponent(el) { ... } // ... new logic for isComponent model: { ... }, }); ``` -Extend the model and view with some other, already defined, components. +Extend the `model` and `view` with some other, already defined, components. ```js comps.addType('map', { extend: 'other-defined-component', diff --git a/src/dom_components/index.js b/src/dom_components/index.js index c84172984..a50086ff6 100644 --- a/src/dom_components/index.js +++ b/src/dom_components/index.js @@ -547,7 +547,10 @@ module.exports = () => { } }, { - isComponent: isComponent || (() => 0) + isComponent: + compType && !extendType && !isComponent + ? modelToExt.isComponent + : isComponent || (() => 0) } ); } diff --git a/test/specs/dom_components/index.js b/test/specs/dom_components/index.js index 6f6e29aff..1fab21a22 100644 --- a/test/specs/dom_components/index.js +++ b/test/specs/dom_components/index.js @@ -208,11 +208,10 @@ describe('DOM Components', () => { test('Extend component type with custom model and view', () => { obj = em.get('DomComponents'); - const id = 'text'; + const id = 'image'; const testProp = 'testValue'; - const testText = 'Some text'; const initialTypes = obj.getTypes().length; - obj.addType('text', { + obj.addType(id, { model: { defaults: { testProp @@ -225,26 +224,47 @@ describe('DOM Components', () => { } }); expect(obj.getTypes().length).toBe(initialTypes); - obj.addComponent(`