Skip to content

Commit

Permalink
Changed "on"-data-query to be able to accept unlimited "args".
Browse files Browse the repository at this point in the history
  • Loading branch information
Joscha Rohmann committed Nov 9, 2016
1 parent f5ae842 commit 6002545
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/query/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -829,25 +829,28 @@ define([
* @memberof blocks.queries
* @param {(String|Array)} events - The event or events to subscribe to
* @param {Function} callback - The callback that will be executed when the event is fired
* @param {*} [args] - Optional arguments that will be passed as second parameter to
* @param {...*} [args] - Optional arguments that will be passed as second parameter to
* the callback function after the event arguments
*/
on: {
ready: function (events, callbacks, args) {
ready: function (events, callbacks) {
if (!events || !callbacks) {
return;
}
var args = blocks.toArray(arguments).slice(2);
var element = this;
var context = blocks.context(this);
var thisArg;

callbacks = blocks.toArray(callbacks);

var handler = function (e) {
args = blocks.clone(args);
args.splice(0,0, e);
context = blocks.context(this) || context;
thisArg = context.$template || context.$view || context.$root;
blocks.each(callbacks, function (callback) {
callback.call(thisArg, e, args);
callback.apply(thisArg, args);
});
};

Expand All @@ -871,8 +874,10 @@ define([
blocks.queries[eventName] = {
passRawValues: true,

ready: function (callback, data) {
blocks.queries.on.ready.call(this, eventName, callback, data);
ready: function (/*callback, data*/) {
var args = blocks.toArray(arguments);
args.splice(0, 0, eventName);
blocks.queries.on.ready.apply(this, args);
}
};
});
Expand Down

0 comments on commit 6002545

Please sign in to comment.