Ah. That sounds good. Looking at using some existing bits somewhere? Or even some existing 'style'?
Node.js's events.js module seems to be 'pure' JS, modulo some console method calls [1]. I'm kinda partial to Backbone's on/off/trigger brevity, along with the fact that you can bind a receiver with your callback function (they call it a 'context'), which doesn't require an actual bind() [2]. I haven't used 'promises' in anger yet, some folks seem to think they're the best thing evar [3]. I wouldn't want to foist that interface on our users - would prefer we just expose a typical 'listener' approach (node/backbone), but maybe there'd be some value of having promises as the substrate on which we'd build an event-y model. I'm not convinced yet. We'll certainly need some additional prims over what you get from a simple interface like node/backbone, in order to be able to do join() type calls (wait for all the specified events to fire, THEN fire the cb specified in the join() invocation). [1] https://github.com/joyent/node/blob/master/lib/events.js [2] https://github.com/documentcloud/backbone/blob/master/backbone.js#L71 [3] https://github.com/kriskowal/q On Thu, Mar 15, 2012 at 12:51, <[email protected]> wrote: > I know we have been throwing around the idea of replacing channel with an > eventing module. > > I agree the channel code is rather large and complex and I am sure we can > get all the functionality we need with an eventemitter interface and named > events. > > > Sent on the TELUS Mobility network with BlackBerry > > -----Original Message----- > From: Patrick Mueller <[email protected]> > Date: Thu, 15 Mar 2012 12:45:31 > To: <[email protected]> > Reply-To: [email protected] > Subject: Re: git commit: [CB-299] cordova.js should allow for registering > plugins as required before deviceready fires. Use for CupcakeStorage on > Android. > > On Wed, Mar 14, 2012 at 19:02, <[email protected]> wrote: > > > Updated Branches: > > refs/heads/master e71e51e88 -> efdcd7703 > > > > [CB-299] cordova.js should allow for registering plugins as required > > before deviceready fires. Use for CupcakeStorage on Android. > > > > Project: > http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo > > Commit: > > > http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/efdcd770 > > Tree: > > > http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/efdcd770 > > Diff: > > > http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/efdcd770 > > ... > > > > > > > http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/efdcd770/lib/channel.js > > ---------------------------------------------------------------------- > > diff --git a/lib/channel.js b/lib/channel.js > > old mode 100644 > > new mode 100755 > > index 9beed93..baf08b6 > > --- a/lib/channel.js > > +++ b/lib/channel.js > > @@ -46,6 +46,45 @@ var Channel = function(type, opts) { > > create: function (type, opts) { > > channel[type] = new Channel(type, opts); > > return channel[type]; > > + }, > > + > > + /** > > + * cordova Channels that must fire before "deviceready" is > fired. > > + */ > > + deviceReadyChannelsArray: [], > > + deviceReadyChannelsMap: {}, > > > > So, this is kind of a nasty pattern - keeping two data structures around > when one will suffice, as there's the problem of these getting out of sync > if code changes in the future. > > Then I looked at channel.join. :-) > > join: function (h, c) { > var i = c.length; > var len = i; > var f = function() { > if (!(--i)) h(); > }; > for (var j=0; j<len; j++) { > !c[j].fired?c[j].subscribeOnce(f):i--; > } > if (!i) h(); > }, > > Yikes! Not terribly understandable, especially since it's not immediately > obvious how a method like join() should work in the first place. But the > good news is, I think we could go to a single "map" and not use the array, > since it doesn't need to be an array. We can change the for loop to a for > (var key in map) loop, and then reference c[key] in the body of the loop > instead. > > Issues? > > -- > Patrick Mueller > http://muellerware.org > > -- Patrick Mueller http://muellerware.org
