mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-17 22:24:49 +02:00
Add asyncMap
This commit is contained in:
+6
-9
@@ -186,16 +186,13 @@
|
||||
|
||||
var id = iD();
|
||||
|
||||
d3.json('keys.json', function(err, keys) {
|
||||
d3.json('presets/presets.json', function(err, presets_data) {
|
||||
iD.util.asyncMap(['keys.json', 'presets/presets.json'], d3.json, function(err, data) {
|
||||
id.connection()
|
||||
.keys(data[0])
|
||||
.presetData(iD.presetData().data(data[1]));
|
||||
|
||||
id.connection()
|
||||
.keys(keys)
|
||||
.presetData(iD.presetData().data(presets_data));
|
||||
|
||||
d3.select("#iD")
|
||||
.call(id.ui())
|
||||
});
|
||||
d3.select("#iD")
|
||||
.call(id.ui())
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -112,3 +112,18 @@ iD.util.fastMouse = function(container) {
|
||||
};
|
||||
|
||||
iD.util.getPrototypeOf = Object.getPrototypeOf || function(obj) { return obj.__proto__; };
|
||||
|
||||
iD.util.asyncMap = function(inputs, func, callback) {
|
||||
var remaining = inputs.length,
|
||||
results = [],
|
||||
errors = [];
|
||||
|
||||
inputs.forEach(function(d, i) {
|
||||
func(d, function done(err, data) {
|
||||
errors[i] = err;
|
||||
results[i] = data;
|
||||
remaining --;
|
||||
if (!remaining) callback(errors, results);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user