Skip to content

Commit

Permalink
Removing wire!context resolver, and updating unit tests. Polyfills fo…
Browse files Browse the repository at this point in the history
…r Array.isArray and Array.prototype.indexOf
  • Loading branch information
briancavalier committed Nov 1, 2011
1 parent ed59241 commit 6f951e6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion support/when
19 changes: 9 additions & 10 deletions test/wire-resolver1.html
Expand Up @@ -12,7 +12,6 @@

wire({
_wire: { $ref: 'wire!' },
_context: { $ref: 'wire!context' },
success: true
}).then(
function(context) {
Expand All @@ -22,15 +21,15 @@
doh.assertTrue(typeof context._wire.destroy == 'function');
doh.assertTrue(typeof context._wire.resolve == 'function');
},
function(doh) {
doh.assertTrue(typeof context._context == 'object');
doh.assertTrue(typeof context._context.then == 'function');
doh.assertTrue(typeof context._context.destroy == 'function');
doh.assertTrue(typeof context._context.resolve == 'function');
},
function(doh) {
doh.assertTrue(context._context.success);
},
// function(doh) {
// doh.assertTrue(typeof context._context == 'object');
// doh.assertTrue(typeof context._context.then == 'function');
// doh.assertTrue(typeof context._context.destroy == 'function');
// doh.assertTrue(typeof context._context.resolve == 'function');
// },
// function(doh) {
// doh.assertTrue(context._context.success);
// },
function(doh) {
var dohd = new doh.Deferred();

Expand Down
51 changes: 36 additions & 15 deletions wire.js
Expand Up @@ -14,19 +14,48 @@

"use strict";

var VERSION, tos, slice, rootSpec, rootContext, delegate, emptyObject,
defer, chain, whenAll, isPromise, isArray, undef;
var VERSION, tos, arrayProto, apIndexOf, apSlice, rootSpec, rootContext, delegate, emptyObject,
defer, chain, whenAll, isPromise, isArray, indexOf, undef;

wire.version = VERSION = "0.7.2";
tos = Object.prototype.toString;
slice = Array.prototype.slice;

rootSpec = global['wire'] || {};

tos = Object.prototype.toString;

arrayProto = Array.prototype;
apSlice = arrayProto.slice;
apIndexOf = arrayProto.indexOf;

/**
* Object.create polyfill
*/
delegate = Object.create || createObject;

// Array polyfills

/**
* Array.indexOf polyfill
*/
isArray = Array.isArray || function (it) {
return tos.call(it) == '[object Array]';
};

/**
* Array.prototype.indexOf polyfill
*/
indexOf = apIndexOf
? function(array, item) {
apIndexOf.call(array, item);
}
: function (array, item) {
for (var i = 0, len = array.length; i < len; i++) {
if(array[i] === item) return i;
}

return -1;
};

emptyObject = {};

// Local refs to when.js
Expand All @@ -46,14 +75,6 @@
return d;
}

function indexOf(array, item) {
for (var i = 0, len = array.length; i < len; i++) {
if(array[i] === item) return i;
}

return -1;
}

//
// AMD Module API
//
Expand Down Expand Up @@ -132,7 +153,7 @@
if(isString(specs)) {
var specIds = specs.split(',');

require(specIds, function() { doWireContexts(slice.call(arguments)); });
require(specIds, function() { doWireContexts(apSlice.call(arguments)); });
} else {
doWireContexts(isArray(specs) ? specs : [specs]);
}
Expand Down Expand Up @@ -858,13 +879,13 @@
return promise;
}

function wireResolver(promise, name /*, refObj, wire*/) {
function wireResolver(promise /*, name, refObj, wire*/) {
// DEPRECATED access to objects
// Providing access to objects here is dangerous since not all
// the components in objects have been initialized--that is, they
// may still be promises, and it's possible to deadlock by waiting
// on one of those promises (via when() or promise.then())
promise.resolve(name ? objects : wireApi);
promise.resolve(wireApi);
}

//
Expand Down

0 comments on commit 6f951e6

Please sign in to comment.