Created
March 5, 2016 14:40
-
-
Save a-x-/e0d60f23ee16021decc5 to your computer and use it in GitHub Desktop.
синтаксический сахар для установки модификаторов по событиям [i-bem.js] — https://ru.bem.info/forum/907/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Как сейчас. Это пример, где упрощённый синтаксис всё сильно упростит. | |
* Но есть и много других примеров, где, кажется, декларация модификаторов на события будет полезна | |
*/ | |
BEM.DOM.decl('b-page', { | |
bindEvents: function() { | |
this.__base.apply(this, arguments); | |
BEM.blocks['pane2-api'] | |
.on('fullscreen:enter', this._onFullscreenEnter, this) | |
.on('fullscreen:exit', this._onFullscreenExit, this); | |
return this; | |
}, | |
destruct: function() { | |
BEM.blocks['pane2-api'] | |
.un('fullscreen:enter', this._onFullscreenEnter, this) | |
.un('fullscreen:exit', this._onFullscreenExit, this); | |
this.__base.apply(this, arguments); | |
}, | |
_onFullscreenEnter: function() { | |
this.setMod('fullscreen', 'yes'); | |
}, | |
_onFullscreenExit: function() { | |
this.setMod('fullscreen', 'no'); | |
} | |
}); | |
/** | |
* Предлагаю синтаксический сахар | |
*/ | |
BEM.DOM.decl('b-page', { | |
onEvent: [{ | |
onStatic: 'pane2-api', // другие кейсы: on, bindTo, и др. | |
mods: { | |
// Вместо 'yes' в более сложных случаях может быть функция принимающая event | |
fullscreen: { 'fullscreen:enter': 'yes', 'fullscreen:exit': 'no' } | |
} | |
}] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment