rm of
This commit is contained in:
33
pronto.cm
33
pronto.cm
@@ -319,45 +319,12 @@ function requestorize(unary) {
|
||||
}
|
||||
}
|
||||
|
||||
// objectify(factory_fn)
|
||||
// Converts a factory that takes arrays to one that takes objects.
|
||||
function objectify(factory_fn) {
|
||||
def factory = 'objectify'
|
||||
if (!is_function(factory_fn))
|
||||
throw make_reason(factory, 'Not a factory.', factory_fn)
|
||||
|
||||
return function objectified_factory(object_of_requestors, ...rest) {
|
||||
if (!is_object(object_of_requestors))
|
||||
throw make_reason(factory, 'Expected an object.', object_of_requestors)
|
||||
|
||||
def keys = array(object_of_requestors)
|
||||
def requestor_array = array(keys, k => object_of_requestors[k])
|
||||
|
||||
def inner_requestor = factory_fn(requestor_array, ...rest)
|
||||
|
||||
return function(callback, value) {
|
||||
return inner_requestor(function(results, reason) {
|
||||
if (results == null) {
|
||||
callback(null, reason)
|
||||
} else if (is_array(results)) {
|
||||
def obj = {}
|
||||
arrfor(keys, (k, i) => { obj[k] = results[i] })
|
||||
callback(obj, reason)
|
||||
} else {
|
||||
callback(results, reason)
|
||||
}
|
||||
}, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
fallback,
|
||||
parallel,
|
||||
race,
|
||||
sequence,
|
||||
requestorize,
|
||||
objectify,
|
||||
is_requestor,
|
||||
check_callback
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user