Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fluent interface for using the core library #15

Closed
ashgkwd opened this issue Sep 18, 2022 · 0 comments
Closed

Fluent interface for using the core library #15

ashgkwd opened this issue Sep 18, 2022 · 0 comments

Comments

@ashgkwd
Copy link

ashgkwd commented Sep 18, 2022

Is your feature request related to a problem? Please describe.
Not really a problem. Considering developer experience, the library API can be improved.

Describe the solution you'd like

With the fluent interface, the usage will look like this:

import smsReader from "react-native-expo-read-sms";

smsReader
  .withPermission()
  .onRead(sms => { 
    /* do something with SMS string */ 
    smsReader.stop()
  })
  .onFail(error => { 
    /* do something with error; maybe stop reading */ 
  })

Describe alternatives you've considered

Support for Config

See notes in context about supporting config that goes with auto stop mechanism. In that case, the signature of the interface changes:

smsReader() // without config
  .withPermission()
  .onRead(...)
  .onFail(...)

smsReader( { maxOnReads: 5, stopOnFail: false } )
  .withPermission()
  .onRead(...)
  .onFail(...)

Stop on failure

We can have implicit stop in case of failure so that the library user doesn't have to call stop inside onFail.

Additional context

  • In the fluent interface, the function withPermission() will ask for permission if not given already. If the user denies the permission, onRead will not be called.
  • As onRead and onFailure may be called multiple times, it's the user's responsibility to call stop whenever done. We can have an implicit limit on how many times onRead can be called. So that way even if the user forgets to call stop; we can stop listening whenever the counter completes. This counter mechanism can also allow (optional) configuration. Ideally that we can take as a param in the reader function: smsReader({ maxOnReads: 10 }). If the optional config is not provided, then the user will be smsReader()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants