-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[menu] base template for block contains logic only for one mod. #1513
Comments
I can provide a PR if you accept my proposal. |
// cc @narqo |
The main purpose of changes from da75b81 is this exact line. E.g. we need to map values from The same thing goes to I think for your particular case, the only "right" solution is to redefine |
I have tried and didn't find an acceptable solution. I can't just skip def mode from bem-components, because I need somehow to get def from bem-core's i-bem.bemhtml. Could you provide an example? |
I can accept your point but still ask one little change which will resolve my issue: add check of existence of |
The only way I managed to solve my issue: {
block: 'test',
content: {
elem:'menu',
content: {
block: 'test', // must explicitly set to preserve original block
elem: 'items'
}
}
} block('test')(
elem('menu')(
def()(function(){
applyNext({
_items:this.ctx.content, // hide content from bem-components menu template
_mode: '', // reset _mode like it does applyCtx
'ctx': {
block: 'menu'
}
})
})
),
elem('items').def()(function(){
return applyCtx([{
block: 'menu-item',
content: '1'
},{
block: 'menu-item',
content: '2'
}])
})
);
block('menu')
.match(function(){
return !!this._items
})
.content()(function(){
return this._items // restore content from _items
}); to finally get <div class="test">
<div class="menu menu__control i-bem" data-bem="{"menu":{}}" role="menu" tabindex="0">
<div class="menu-item i-bem" data-bem="{"menu-item":{}}" role="menuitem">1</div>
<div class="menu-item i-bem" data-bem="{"menu-item":{}}" role="menuitem">2</div>
</div>
</div> |
See also #1516. |
This whole iterateItems thing really hard to understand without deep debugging. |
I'm still not sure I understand, what exactly you're doing. Could you show some real example?
Actually they do the same things, but from the point of how |
dist: Switch on mimic for BH. Closes #1513
da75b81 introduced logic which demanded only by
menu_mode_radio
template.It iterates over content to set properties
_firstItem
and_checkedItems
. Iteration function has assumption thatmenu
should contain onlymenu-item
ormenu__group
. It very inconvinient when we try to put inside blockmenu
another elements or blocks which will be replaced withmenu-item
in later processing.I suppose two enhancements:
mod('mode', 'radio')
matcher.ctx.content = [].concat(ctx.content)
instead ofif(!this.isArray(ctx.content)) throw Error
else if(ctx.content) { // menu__group
) before recursive callAdditionally we can support case of resolving blocks to
menu-item
which cannot be catched by iteration function and add js behavior in init section ofmenu_mode_radio
, and document that in such cases live initialization should be disabled. But I think it can and should be done at project level./cc @hcodes @tadatuta
The text was updated successfully, but these errors were encountered: