forked from dadbob/react-native-pinch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (29 loc) · 908 Bytes
/
index.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
'use strict';
import { NativeModules } from 'react-native';
var Q = require('q');
var RNPinch = {
fetch: function (url, obj, callback) {
var deferred = Q.defer();
NativeModules.RNPinch.fetch(url, obj, (err, res) => {
if (err) {
deferred.reject(err);
} else {
res.json = function() {
return Q.fcall(function () {
return JSON.parse(res.bodyString);
});
};
res.text = function() {
return Q.fcall(function () {
return res.bodyString;
});
};
res.url = url;
deferred.resolve(res);
}
deferred.promise.nodeify(callback);
});
return deferred.promise;
}
};
module.exports = RNPinch;