0.2.2 • Published 3 years ago
ts-utility-lib v0.2.2
TS Utility Library
This is a library with utility functions for typescript.
Usage
An example usage would look something like the following
// Get a user from an api call and cache it with the memoize function
const getUser = useMemoize(async (id: string) => promise(id), {
getKey: id => id,
});
// Wrap a single function returning a promise which is used multiple times
const resolveGetUser = usePromiseAll((user: User) =>
getUser(user.id).then(result => (user.promise = result))
);
// Wrap multiple promise with the promise all function
const resolveGetUserAndProduct = usePromiseAll((user: User) => [
getUser(user.id).then(result => (user.promise = result)),
getProduct(user.productId).then(result => (user.product = result))
]);
// Collect all promises
for (const user of userArray) {
resolveGetUser(user);
}
// Resolve all promises simultaneously
await resolveGetUser.resolve();