Skip to content
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

Fix multiple events subscription #1529

Merged
merged 1 commit into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ var EVENT_PREFIX = '__bem__',
var event = EVENT_PREFIX + params.bindEntityCls.getEntityName() +
(typeof e === 'object'?
e instanceof events.Event?
' ' + e.type :
':' + e.type :
bemInternal.buildModPostfix(e.modName, e.modVal) :
' ' + e);
':' + e);

eventMethod === 'on' && // TODO: count usage and remove on 'un'
!eventsInUse[event] &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('DOM events', function() {
'js' : {
'inited' : function() {
this._domEvents()
.on('click', spy1)
.on('click keypress', spy1)
.on('click', spy2)
.on('click', data, wrapSpy(spy3))
.once('click', spy4);
Expand Down
16 changes: 16 additions & 0 deletions common.blocks/i-bem-dom/__events/i-bem-dom__events.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ var undef,
* @returns {EventManager} this
*/
on : function(e, data, fn, _fnCtx, _isOnce) {
if(typeof e === 'string' && e.indexOf(' ') > -1) {
e.split(' ').forEach(function(event) {
this.on(event, data, fn, _fnCtx, _isOnce);
}, this);

return this;
}

var params = this._params,
event = this._eventBuilder(e, params, 'on');

Expand Down Expand Up @@ -114,6 +122,14 @@ var undef,
un : function(e, fn, _fnCtx) {
var argsLen = arguments.length;
if(argsLen) {
if(typeof e === 'string' && e.indexOf(' ') > -1) {
e.split(' ').forEach(function(event) {
this.un(event, fn, _fnCtx);
}, this);

return this;
}

var params = this._params,
event = this._eventBuilder(e, params, 'un');

Expand Down