warehouse.ts is a collection of reactive state management utilities for SvelteKit and Svelte apps.
To install warehouse.ts, run the following command in your project directory:
npm install warehouse.ts
pnpm install warehouse.ts
bun install warehouse.ts
The PromiseStore
class wraps a promise and provides reactive state management:
import { createPromiseStore } from 'warehouse.ts';
const myAsyncFunction = async () => {
// Your async logic here
};
const myPromiseStore = createPromiseStore(myAsyncFunction, {
onPending: () => console.log('Loading...'),
onSuccess: (result) => console.log('Success:', result),
onError: (error) => console.error('Error:', error),
});
// Use the promise
myPromiseStore.promise();
// Access reactive states
console.log(myPromiseStore.status);
console.log(myPromiseStore.result);
console.log(myPromiseStore.error);
The PromiseMap
class manages multiple PromiseStore
instances:
import { PromiseMap } from 'warehouse.ts';
const promiseMap = new PromiseMap();
promiseMap.set('user', fetchUser, { /* options */ });
promiseMap.set('posts', fetchPosts, { /* options */ });
// Access individual PromiseStore instances
const userPromise = promiseMap.get('user');
const postsPromise = promiseMap.get('posts');
For detailed API documentation, please refer to the source code and inline comments in the promiseStore.ts
file.
Contributions are welcome! Please feel free to submit a Pull Request.