Skip to content

Commit

Permalink
♻️ auto commit once added
Browse files Browse the repository at this point in the history
  • Loading branch information
harshzalavadiya committed Apr 25, 2020
1 parent 4fe1a27 commit 4a38afc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ const Example = () => {
export default Container;
```

### `add(value, key?)`
### `add(value, key?, commit?)`

Inserts given `value` record to selected store, second param is optional key useful if auto-increment is disabled

By default commit is enabled after each transaction so changes are reflected in indexedDB instantly

```jsx
import { useIndexedDBStore } from "use-indexeddb";

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "use-indexeddb",
"version": "1.0.2",
"version": "1.0.3",
"description": "Lightweight (1KB gzipped) hooks w/ promises for easy IndexedDB access in React ⚓",
"author": "Harsh Zalavadiya",
"module": "dist/use-indexeddb.esm.js",
Expand Down
3 changes: 2 additions & 1 deletion src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function getActions<T>(currentStore, config) {
});
},

add(value: T, key?: any) {
add(value: T, key?: any, commit = true) {
return new Promise<number>((resolve, reject) => {
getConnection(config)
.then(db => {
Expand All @@ -135,6 +135,7 @@ export function getActions<T>(currentStore, config) {
let objectStore = tx.objectStore(currentStore);
let request = objectStore.add(value, key);
request.onsuccess = (e: any) => {
commit && (tx as any)?.commit();
resolve(e.target.result);
};
})
Expand Down

0 comments on commit 4a38afc

Please sign in to comment.