Would it make sense to move the api to use promises rather than callbacks? I'm not exactly sure when people tend to use one over the other, possibly when there are some background tasks involved in the native code. Which I believe we do have in here.
I think promises are pretty popular. There are some js folks I know that still prefer callbacks. Is it hard to support both?
I'm sure you could support both, but I think it might lead to confusion.
I've started using the async / await syntax in my RN apps which makes using promises a lot nicer, not so much nasty boilerplate code. And neater than callbacks too.
Any progress about promise?
I did some tests modifying the project in my own node_modules directory and it ran nice on android. In my opinion promises are cleaner especially when using async/await. +1 to support promises.
My solution in the case anybody needs promises for _redux-saga_ or some other async code:
function getContacts() {
return new Promise(resolve => {
Contacts.getAll((error, contacts) => {
if (error) {
throw error;
} else {
resolve(contacts);
}
});
});
}
And then just call:
const contacts = yield call(getContacts);
If the collaborators are ok with it, I may take a whack at promisifying the library. I will ensure that callbacks are supported as well, for backwards compatibility.
@jacob-israel-turner absolutely, please submit a PR :)
To use this great component with Redux, I needed to make it return promises (rather than callbacks). Using the hints in this thread and other resources, I came up with a solution for calling this component from a Redux's Action (Action Creator).
Please, refer to the following question on StackOverflow.
https://stackoverflow.com/questions/58126240/in-a-reduxs-action-calling-a-function-with-callbacks
any progress?
Most helpful comment
My solution in the case anybody needs promises for _redux-saga_ or some other async code:
And then just call: