From e09a622a955d780c9f69804b6f6b7482d7624de1 Mon Sep 17 00:00:00 2001 From: Alexis Jacomy Date: Wed, 12 Jun 2013 12:31:57 +0200 Subject: [PATCH] Fixed #32 --- src/domino.js | 17 ++++++++++------- test/unit.services.js | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/domino.js b/src/domino.js index 7f51b6e..1f0b126 100644 --- a/src/domino.js +++ b/src/domino.js @@ -264,10 +264,7 @@ }); scope.dispatchEvent = function(type, data) { - this._events.push({ - type: type, - data: data - }); + this._events.push(_self.getEvent(type, data)); return this; }; @@ -796,7 +793,7 @@ a = _utils.array(obj['events']); for (k in a) { reiterate = true; - dispatch[a[k].type] = 1; + dispatch[a[k].type] = a[k]; } for (k in obj['update']) @@ -820,8 +817,14 @@ // Check events to dispatch: events = []; - for (event in dispatch) - events.push(_self.getEvent(event)); + console.log(dispatch); + for (event in dispatch) { + events.push( + dispatch[event] === 1 ? + _self.getEvent(event) : + dispatch[event] + ); + } // Start looping: if (reiterate) diff --git a/test/unit.services.js b/test/unit.services.js index 7734f78..25174b7 100644 --- a/test/unit.services.js +++ b/test/unit.services.js @@ -152,6 +152,21 @@ asyncTest('Services', function() { this.prop_8 = 'def'; } } + }, + { + data: 'abc', + expected: 'def', + label: 'Dispatch an event with data', + params: { + type: 'POST', + contentType: 'application/json', + data: { value: 'def' }, + success: function(data) { + this.dispatchEvent('update_prop_9', { + prop_9: data.prop_9 + }); + } + } } ]; @@ -167,6 +182,7 @@ asyncTest('Services', function() { return { id: 'prop_' + i, dispatch: 'prop_' + i + '_updated', + triggers: 'update_prop_' + i, type: '?*' }; }),