Skip to content

Commit

Permalink
simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
aristov committed Jul 23, 2015
1 parent 565e3f3 commit e217170
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
16 changes: 3 additions & 13 deletions common.blocks/dropdown/dropdown.bemhtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,9 @@ block('dropdown')(
applyCtx(switcher);
}),
elem('switcher').mix()(function() {
var dropdown = this._dropdown,
dropdownMix = dropdown.mix,
switcherMix = dropdown.switcher.mix || [];

Array.isArray(switcherMix) || (switcherMix = [switcherMix]);
var dropdown = this._dropdown;

return switcherMix.concat(dropdownMix?
Array.isArray(dropdownMix)?
dropdownMix.concat([dropdown]) :
[dropdownMix, dropdown] :
dropdown);
return [dropdown].concat(dropdown.switcher.mix || [], dropdown.mix || []);
}),
elem('popup').def()(function() {
var dropdown = this._dropdown,
Expand All @@ -46,9 +38,7 @@ block('dropdown')(

popupMods.target = 'anchor';

var popupMix = popup.mix || [];
Array.isArray(popupMix) || (popupMix = [popupMix]);
popup.mix = popupMix.concat([dropdown]);
popup.mix = [dropdown].concat(popup.mix || []);

applyCtx(popup);
})
Expand Down
18 changes: 5 additions & 13 deletions common.blocks/dropdown/dropdown.bh.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@ module.exports = function(bh) {

bh.match({
'dropdown' : function(ctx) {
var dropdown = ctx.json(),
dropdownMix = dropdown.mix,
switcherMix = dropdown.switcher.mix || [];

Array.isArray(switcherMix) || (switcherMix = [switcherMix]);
var dropdown = ctx.json();

ctx
.js(ctx.extend({ id : ctx.generateId() }, ctx.js()))
.tParam('dropdown', dropdown)
.tParam('theme', ctx.mod('theme'))
.tParam('mix', switcherMix.concat(dropdownMix?
Array.isArray(dropdownMix)?
dropdownMix.concat([dropdown]) :
[dropdownMix, dropdown] :
dropdown));
.tParam('mix', [dropdown].concat(
dropdown.switcher.mix || [],
dropdown.mix || []));

return [{ elem : 'switcher' }, { elem : 'popup' }];
},
Expand All @@ -35,9 +29,7 @@ module.exports = function(bh) {

popupMods.target = 'anchor';

var popupMix = popup.mix || [];
Array.isArray(popupMix) || (popupMix = [popupMix]);
popup.mix = popupMix.concat([dropdown]);
popup.mix = [dropdown].concat(popup.mix || []);

return popup;
},
Expand Down

0 comments on commit e217170

Please sign in to comment.