mobx-requestor
TypeScript icon, indicating that this package has built-in type declarations

4.1.1 • Public • Published

mobx-requestor

What is this?

This is an abstraction over a resource request for mobx. It aims to make it simpler to deal with the data fetching and posting using any abstraction to perform the request/posts

How do I use it?

// simpler example
const rq = new MobxRequestor({
  call: (...args) => {
    // service.someMethod is just a function that returns a 
    // promise to resolve to the data being fetched or to 
    // the result of a POST/PUT/PATCH operation
    return service.someMethod(...args);
  }
});

// although this function return a promise
// it is guaranteed to always resolve 
// the data or error can be inspected on the 
// `error` and `response` properties respectively
await rq.execCall({ someArg: 1 });

// query the state of the request
rq.loading // true if the request is in progress

// if an error ocurred the error can be found here (as text)
rq.error

// if the request finalized without throwing then this will be true
rq.success

// whatever was resolved from the service.someMethod function 
// will be available in this property
req.response 

Building the repo

npm run build

Type-checking the repo

npm run type-check

And to run in --watch mode:

npm run type-check:watch

License

MIT

tests

TODO

Readme

Keywords

none

Package Sidebar

Install

npm i mobx-requestor

Weekly Downloads

133

Version

4.1.1

License

MIT

Unpacked Size

14.8 kB

Total Files

5

Last publish

Collaborators

  • royriojas