1 | ![Tests](https://github.com/SebastianSpeitel/proxystore/workflows/Tests/badge.svg?branch=master)
|
2 |
|
3 | # proxystore
|
4 |
|
5 | Persistent object storage using proxies
|
6 |
|
7 | ## Usage
|
8 |
|
9 | ```javascript
|
10 | import { ProxyStore, FileHandler } from "@sebastianspeitel/proxystore";
|
11 |
|
12 | const handler = new FileHandler("store.json");
|
13 | const store = new ProxyStore(handler).store;
|
14 | ```
|
15 |
|
16 | Now you can use `store` as any other object and it will be saved in `store.json`
|
17 |
|
18 | ## Options
|
19 |
|
20 | ```typescript
|
21 | export interface ProxyStoreOptions<T extends object> {
|
22 | // true to load the initial store using the provided handler
|
23 | // or provide an object to use as initial value
|
24 | init?: T | boolean;
|
25 | }
|
26 | ```
|
27 |
|
28 | ## TypeScript
|
29 |
|
30 | All methods take a type to use for the store, so you can provide it for autocompletion.
|
31 |
|
32 | ### Example
|
33 |
|
34 | ```typescript
|
35 | interface FooBar {
|
36 | foo: number;
|
37 | bar: string;
|
38 | }
|
39 |
|
40 | const store = new ProxyStore<FooBar>(handler).store;
|
41 |
|
42 | store.foo; // works
|
43 | store.baz; // doesn't work
|
44 | ```
|
45 |
|
46 | ## Handler
|
47 |
|
48 | You can provide your own handler. Any object with a `load` and `save` method works.
|