@async-resource/core
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

@async-resource/core

Installation

npm install --save @async-resource/core

Usage

import {
  registerResource,
  subscribe,
} from '@async-resource/core'

// -> Register resource
registerResource('user', {
  source: () => axios.get('/rest/user-info'),
  cache: { TTL: 24 * 60 * 60 * 1000 } // caches for a day
})

// -> listen for resource change
subscribe('user', resource => {
  // readonly cache: boolean
  // readonly loading: boolean
  // readonly loaded: boolean
  // readonly error: string | null
  // readonly data: any
})

// ...

// -> call resource
resources.consume('user')

Package Sidebar

Install

npm i @async-resource/core

Weekly Downloads

2

Version

0.2.0

License

MIT

Unpacked Size

73.6 kB

Total Files

28

Last publish

Collaborators

  • cristovao-trevisan