Releases: octet-stream/use-suspender
Releases · octet-stream/use-suspender
2.0.0-beta.0
Update
- Rewrite project with TypeScript;
- Rewrite documentation;
- Expand cache so it can hold multiple operations. With that, when
useSuspender
is called with different arguments - each call will create a new operation. However, if called with the same arguments, the same operation will be thrown unless finished.
Add
- Expose
cache
property fromuseSuspender
hook for manual control over the internal cache. The cache has two properties:size
andclear
. This feature is experimental and not documented yet!
All changes: v1.1.0...v2.0.0-beta.0
1.1.0
Update
- Improved TS typings - the result of
SuspenderHook
function will be the same asSuspenderImplementation
you provided (for example, if yourSuspenderImplementation
function returnsUser
type, thenSuspenderHook
will also returnUser
type instead ofany
). - Add
exports
section, so this package can be used with both CJS and ESM in Node.js. The next major release will be ESM only.
All changes: v1.0.0...v1.1.0
1.0.0
Add
- Add a new TypeScript typings
Update
- Overall package improvements
- Stabilise public API for the first major release
All changes: v0.4.2...v1.0.0
0.4.2
0.4.1
0.4.0
Update
- BREAKING: Rename
useSuspender.init()
->useSuspender.callEarly()
Add
- useSuspender hook will compare taken arguments with the previous, then execute the suspender function when they aren't the same. This will also cancel the previous operation.
All changes: v0.3.1...v0.4.0
0.3.1
Update
- Improvements for library's internal code. Nothing really changed or updated for public API or behaviour.
All changes: v0.3.0...v0.3.1
0.3.0
Add
createSuspenser
now takes second argument:ctx
. It allows to set a thisArg for eachuseSuspender()
call. This argument can be overwritten usingFunction#{call,apply,bind}
methods on any particularuseSuspender()
call.
import createSuspender from "use-suspender"
import User from "./api/User"
const useSuspender = createSuspender(User.getUser, User)
useSuspender.init()
allows to call useSuspender earcly (outside of a component render function),
so that you can do something before your component will be actually called and rendered:
import creteSuspender from "use-suspender"
import React from "react"
const useSuspender = createSuspender(
() => new Promise(resolve => setTimeout(() => resolve("Hello, world!"), 1000))
)
// Calls your suspender function
useSuspender.init()
function HelloComponent() {
// Will return a result immediately if Promise returned by suspender function
// has been fulfilled before HelloComponent call.
const text = useSuspender()
return <div>{text}</div>
}
The init()
and useSuspender()
functions can be used separately:
import creteSuspender from "use-suspender"
import React from "react"
const {useSuspender, init} = createSuspender(
() => new Promise(resolve => setTimeout(() => resolve("Hello, world!"), 1000))
)
All changes: v0.2.0...v0.3.0
0.2.0
Initial release
v0.1.0 Fix for .npmignore