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