Skip to content

Commit e6bd03e

Browse files
committed
updated readme
1 parent f85285d commit e6bd03e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ using the `resetBags()` method.
6868

6969
---
7070

71+
## Stateful bags
72+
73+
When creating a `bag manager`, you can make it `stateful` by passing `true` to `CreateBagManager(true)`. All
74+
bags created will then be 'fused' with a entry in `IndexedDB` in the browser.
75+
76+
A new tabled named `saddlebag` will be added, combined with a table called `bags`
77+
78+
Each write via `set` on a bag, will also write to the DB, and when you reload your browser, `saddlebag` can
79+
restore state to each bag automatically using the `loadStatefulBags()` method on your `bag manager`.
80+
81+
A Promise is returned that resolves once all state is loaded and ready and your bags are loaded and ready hit the trail.
82+
83+
---
84+
7185
## Basic Use
7286

7387
All imports are exposed as named exports via `@pb33f/saddlebag`.
@@ -170,4 +184,24 @@ const bag = bagManager.getBag<string>('foo');
170184

171185
---
172186

187+
## Loading stateful bags
188+
189+
If the `bag manager` was created as a stateful one, then use the `loadStatefulBags()` to populate from IndexedDB.
190+
191+
```typescript
192+
bagManager.loadStatefulBags().then(() => {
193+
// do something fun.
194+
...
195+
});
196+
```
197+
198+
A promise is returned that resolves once all data is populated in all bags.
199+
200+
The values for the DB/Store name in IndexedDB
201+
202+
```typescript
203+
export const BAG_OBJECT_STORE = 'bags';
204+
export const BAG_DB_NAME = 'saddlebag';
205+
```
206+
173207
`saddlebag` A product of [pb33f](https://pb33f.io).

0 commit comments

Comments
 (0)