This repository has been archived by the owner on Aug 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJoin.js
59 lines (50 loc) · 1.67 KB
/
Join.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* eslint-env browser,amd */
define([
'dojo/_base/declare', 'dojo/_base/lang', 'dojo/Deferred', 'dojo/promise/all',
'artnum/dojo/Request'
], function (
djDeclare, djLang, DjDeferred, djAll,
Request) {
return function (req1, req2) {
var def1 = new DjDeferred()
var getDataCB = function (data) { return data }
if (arguments[2]) {
getDataCB = arguments[2]
}
if (!req1.options) { req1.options = {} }
if (!req2.options) { req2.options = {} }
Request.get(req1.url, req1.options).then(function (results) {
var def2 = new DjDeferred()
window.setTimeout(function () {
var data = getDataCB(results)
var promises = []
for (var i = 0; i < data.length; i++) {
var entry = data[i]
promises.push(Request.get(entry[req2.attribute], req2.options).then(djLang.hitch(Object.assign({}, entry), function (results) {
var entry = this
var def3 = new DjDeferred()
window.setTimeout(function () {
var out = []
var data = getDataCB(results)
for (var i = 0; i < data.length; i++) {
entry[req2.attribute] = data[i]
out.push(entry)
}
def3.resolve(out)
}, 0)
return def3.promise
})))
}
djAll(promises).then(function (results) {
var merge = []
for (var i = 0; i < results.length; i++) {
merge = merge.concat(results[i])
}
def2.resolve(merge)
})
}, 0)
return def2.promise
}).then(function (result) { def1.resolve(result) })
return def1.promise
}
}) /* define */