Skip to content

Commit

Permalink
#25 Add dispatch event fallback on client
Browse files Browse the repository at this point in the history
  • Loading branch information
tracend committed Oct 9, 2012
1 parent 19c2666 commit e5d7f07
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,26 @@ var crudr, socket;
backend.options = options;
backend.socket.on('synced', function(method, resp) {
var event = backend.options.event;


if(typeof collection.trigger == "undefined"){

// fallback to a regular event dispatcher
var evt = document.createEvent(event);
evt.initEvent(event,true,true);
evt.method = method;
evt.response = resp;
collection.dispatchEvent(evt);

var evt = document.createEvent(event + ':' + method);
evt.initEvent(event + ':' + method,true,true);
evt.response = resp;
collection.dispatchEvent(evt);

collection.trigger(event, method, resp);
collection.trigger(event + ':' + method, resp);
} else {
collection.trigger(event, method, resp);
collection.trigger(event + ':' + method, resp);
}
});

promise.resolve();
Expand Down

0 comments on commit e5d7f07

Please sign in to comment.