From e5d7f072f3ed5de3c09d413c276d99c689ea370e Mon Sep 17 00:00:00 2001 From: Makis Tracend Date: Tue, 9 Oct 2012 02:03:22 -0700 Subject: [PATCH] #25 Add dispatch event fallback on client --- lib/client.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index f250d5a..8371b9e 100755 --- a/lib/client.js +++ b/lib/client.js @@ -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();