LtbLightning / bdk-rn

Bitcoin Development Kit - React Native Module
MIT License
50 stars 15 forks source link

Update Method Return Response #28

Closed coreyphillips closed 2 years ago

coreyphillips commented 2 years ago

Do you have any thoughts/feelings on updating the method return response for increased clarity on returned types?

At Synonym we use the following: https://www.npmjs.com/package/@synonymdev/result

Example Usage:

const randomDataCheck = (data): Result<string> => {
    if (!data) return err('No data available');
    return ok('Data was provided');
};

const result = randomDataCheck('Some data');
if (result.isErr()) {
    console.error(result.error.message); // "error message"
    return;
}
const dataCheckRes = result.value;

This way we always know what's getting returned and it ensures we're checking each response before proceeding. It also helps keep our responses consistent across projects. I would be happy to create a PR with these changes if you believe it would benefit the bdk-rn library.

BitcoinZavior commented 2 years ago

@coreyphillips This seems like a good pattern to follow. Would be very happy to get a PR that implements this pattern. Thanks!