-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from JeanLebrument/initialRelease
Add index.js file and configure package.json
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
var Rx = require('rx'); | ||
var Contacts = require('react-native-contacts'); | ||
|
||
function _execAddressBookMethodWithParamsErrorData(func) { | ||
return Rx.Observable.create(function(observer) { | ||
func(function(error, data) { | ||
if (error) { | ||
observer.onError(error); | ||
} else { | ||
observer.onNext(data); | ||
observer.onCompleted(); | ||
} | ||
}); | ||
|
||
return null; | ||
}); | ||
} | ||
|
||
function _execAddressBookMethodWithParamError(contact, func) { | ||
return Rx.Observable.create(function(observer) { | ||
func(contact, function(error) { | ||
if (error) { | ||
observer.onError(error); | ||
} else { | ||
observer.onCompleted(); | ||
} | ||
}); | ||
|
||
return null; | ||
}); | ||
} | ||
|
||
Contacts.rx_checkPermission = function() { | ||
return _execAddressBookMethodWithParamsErrorData(Contacts.checkPermission); | ||
}; | ||
|
||
Contacts.rx_requestPermission = function() { | ||
return _execAddressBookMethodWithParamsErrorData(Contacts.requestPermission); | ||
}; | ||
|
||
Contacts.rx_getAll = function() { | ||
return _execAddressBookMethodWithParamsErrorData(Contacts.getAll); | ||
}; | ||
|
||
Contacts.rx_addContact = function(contact) { | ||
return _execAddressBookMethodWithParamError(contact, Contacts.addContact); | ||
} | ||
|
||
Contacts.rx_updateContact = function(contact) { | ||
return _execAddressBookMethodWithParamError(contact, Contacts.updateContact); | ||
} | ||
|
||
Contacts.rx_deleteContact = function(contact) { | ||
return _execAddressBookMethodWithParamError(contact, Contacts.deleteContact); | ||
} | ||
|
||
module.exports = Contacts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "react-native-contacts-rx", | ||
"version": "1.0.0", | ||
"description": "react-native-contacts counterpart that include the support of RxJS.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/JeanLebrument/react-native-contacts-rx.git" | ||
}, | ||
"keywords": [ | ||
"react-native", | ||
"react-native-contacts", | ||
"rx", | ||
"rxjs" | ||
], | ||
"author": "Jean Lebrument", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/JeanLebrument/react-native-contacts-rx/issues" | ||
}, | ||
"homepage": "https://github.com/JeanLebrument/react-native-contacts-rx#readme" | ||
} |