Skip to content

Commit

Permalink
common.blocks: prepare for bem-xjst@2.x
Browse files Browse the repository at this point in the history
* Remove `match()` with inline value
* Always return when doing `applyNext()`/`applyCtx()`
  • Loading branch information
indutny committed May 5, 2015
1 parent d9e53e8 commit 6e6e34e
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion common.blocks/attach/__button/attach__button.bemhtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
block('button')
.match(this._attach)(
.match(function() { return this._attach; })(
tag()('span'),
content()(function() {
return [
Expand Down
2 changes: 1 addition & 1 deletion common.blocks/attach/attach.bemhtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
block('attach')(
def()(function() { applyNext({ _attach : this.ctx }); }),
def()(function() { return applyNext({ _attach : this.ctx }); }),

tag()('span'),

Expand Down
2 changes: 1 addition & 1 deletion common.blocks/input/input.bemhtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ block('input')(
tag()('span'),
js()(true),
def()(function() {
applyNext({ _input : this.ctx });
return applyNext({ _input : this.ctx });
}),
content()({ elem : 'box', content : { elem : 'control' } })
);
2 changes: 1 addition & 1 deletion common.blocks/link/link.bemhtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ block('link')(
var ctx = this.ctx;
typeof ctx.url === 'object' && // url could contain bemjson
(ctx.url = this.reapply(ctx.url));
applyNext();
return applyNext();
}),

tag()('a'),
Expand Down
12 changes: 8 additions & 4 deletions common.blocks/menu-item/_type/menu-item_type_link.bemhtml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
block('menu-item').mod('type', 'link').mod('disabled', true).match(!this._menuItemDisabled).def()(function() {
apply({ _menuItemDisabled : true });
block('menu-item').mod('type', 'link').mod('disabled', true).match(function() {
return !this._menuItemDisabled;
}).def()(function() {
return applyNext({ _menuItemDisabled : true });
});

block('link').match(this._menuItemDisabled).def()(function() {
block('link').match(function() {
return this._menuItemDisabled;
}).def()(function() {
delete this._menuItemDisabled;
this.mods.disabled = true;
apply();
return applyNext();
});
4 changes: 2 additions & 2 deletions common.blocks/menu-item/menu-item.bemhtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ block('menu-item')(
return { val : this.ctx.val };
}),
attrs()({ role : 'menuitem' }),
match(this._menuMods).def()(function() {
match(function() { return this._menuMods; }).def()(function() {
var mods = this.mods;
mods.theme = mods.theme || this._menuMods.theme;
mods.disabled = mods.disabled || this._menuMods.disabled;
applyNext();
return applyNext();
})
);
6 changes: 4 additions & 2 deletions common.blocks/menu/_mode/menu_mode_radio.bemhtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
block('menu')
.mod('mode', 'radio')
.match(this._firstItem && this._checkedItems && !this._checkedItems.length)(
.match(function() {
return this._firstItem && this._checkedItems && !this._checkedItems.length;
})(
def()(function() {
(this._firstItem.mods = this._firstItem.mods || {}).checked = true;
applyNext();
return applyNext();
}));
2 changes: 1 addition & 1 deletion common.blocks/menu/menu.bemhtml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ block('menu')(
this._firstItem = firstItem;
this._checkedItems = checkedItems;

applyNext({
return applyNext({
_menuMods : {
theme : mods.theme,
disabled : mods.disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ block('radio-group').mod('mode', 'radio-check')(
if(this.mods.type !== 'button')
throw Error('Modifier mode=radio-check can be only with modifier type=button');

applyNext();
return applyNext();
})
);
2 changes: 1 addition & 1 deletion common.blocks/select/__button/select__button.bemhtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
block('select').elem('button')(
def()(function() {
var mods = this.mods;
applyCtx({
return applyCtx({
block : 'button',
mix : { block : this.block, elem : this.elem },
mods : {
Expand Down
2 changes: 1 addition & 1 deletion common.blocks/select/__menu/select__menu.bemhtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ block('select').elem('menu')(
return res;
};

applyCtx({
return applyCtx({
block : 'menu',
mix : { block : this.block, elem : this.elem },
mods : {
Expand Down
6 changes: 4 additions & 2 deletions common.blocks/select/_mode/select_mode_radio.bemhtml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
block('select').mod('mode', 'radio')(
def().match(this._checkedOptions)(function() {
def().match(function() {
return this._checkedOptions;
})(function() {
var checkedOptions = this._checkedOptions,
firstOption = this._firstOption;
if(firstOption && !checkedOptions.length) {
firstOption.checked = true;
checkedOptions = [firstOption];
}
applyNext({ _checkedOption : checkedOptions[0] });
return applyNext({ _checkedOption : checkedOptions[0] });
}),

content()(function() {
Expand Down
6 changes: 4 additions & 2 deletions common.blocks/select/select.bemhtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
block('select')(
def().match(!this._select)(function() { // TODO: check BEM-XJST for proper applyNext
def().match(function() {
return !this._select;
})(function() { // TODO: check BEM-XJST for proper applyNext
if(!this.mods.mode) throw Error('Can\'t build select without mode modifier');

var ctx = this.ctx,
Expand Down Expand Up @@ -29,7 +31,7 @@ block('select')(

iterateOptions(ctx.options);

applyNext({
return applyNext({
_select : this.ctx,
_checkedOptions : checkedOptions,
_firstOption : firstOption
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
block('select').def()(function() {
applyNext({ _selectCls : this.ctx.cls });
return applyNext({ _selectCls : this.ctx.cls });
});

block('popup').match(this._selectCls).def()(function() {
block('popup').match(function() {
return this._selectCls;
}).def()(function() {
// NOTE: we "mark" popups which are inside select block
// with special classes, so gemini tests could find them
this.ctx.cls = this._selectCls + '-popup';
delete this._selectCls;
apply();
return apply();
});

0 comments on commit 6e6e34e

Please sign in to comment.