Skip to content

Commit 3dcaecd

Browse files
committed
- add test for transaction and update code for doc
- replace parcel with rollup
1 parent dceacc1 commit 3dcaecd

File tree

6 files changed

+7657
-11821
lines changed

6 files changed

+7657
-11821
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</a>
3737
&nbsp;
3838
<img
39-
src="https://img.shields.io/badge/gzipped-6KB-brightgreen"
39+
src="https://img.shields.io/badge/gzipped-8KB-brightgreen"
4040
alt="package size"
4141
/>
4242
&nbsp;

codeForDoc/src/quick_start/runTransaction.ts

+31-24
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,46 @@ import {
44
serverTimestamp,
55
increment,
66
arrayRemove,
7+
Timestamp,
78
} from 'firelord'
89

910
export const dummy = async () => {
1011
try {
11-
await runTransaction(db, async transaction => {
12-
// ...
13-
})
1412
// OR you can skip 'db'
15-
await runTransaction(async transaction => {
16-
await transaction.get(example.doc('lmn')).then(docSnapshot => {
17-
const data = docSnapshot.data()
18-
})
13+
await runTransaction(
14+
db,
15+
async transaction => {
16+
await transaction.get(example.doc('lmn')).then(docSnapshot => {
17+
const data = docSnapshot.data()
18+
})
1919

20-
transaction.create(example.doc('lmn'), {
21-
a: 500,
22-
b: { c: true, d: [{ e: 'efg' }] },
23-
f: { g: serverTimestamp(), h: 3838 },
24-
})
20+
transaction.create(example.doc('lmn'), {
21+
a: 500,
22+
b: { c: true, d: [{ e: 'efg' }] },
23+
f: { g: serverTimestamp(), h: 3838 },
24+
})
2525

26-
transaction.set(example.doc('lmn'), {
27-
a: 88,
28-
b: { c: false, d: [{ e: 'opq' }] },
29-
f: { g: serverTimestamp(), h: 2929 },
30-
})
26+
transaction.set(example.doc('lmn'), {
27+
a: 88,
28+
b: { c: false, d: [{ e: 'opq' }] },
29+
f: { g: serverTimestamp(), h: 2929 },
30+
})
3131

32-
transaction.update(example.doc('lmn'), {
33-
a: increment(1),
34-
b: { d: arrayRemove({ e: 'rst' }) }, // nested form
35-
'f.g': serverTimestamp(), // dot notation form
36-
})
32+
transaction.update(example.doc('lmn'), {
33+
a: increment(1),
34+
b: { d: arrayRemove({ e: 'rst' }) }, // nested form
35+
'f.g': serverTimestamp(), // dot notation form
36+
})
3737

38-
transaction.delete(example.doc('lmn'))
39-
})
38+
transaction.delete(example.doc('lmn'))
39+
},
40+
{ readOnly: true, readTime: Timestamp.now() } // optional
41+
// we can supply 2 set of options:
42+
// 1. { readOnly?: false, maxAttempts?: number }
43+
// note that in case 1 both properties are optional and readOnly is false
44+
// 2. { readOnly: true, readTime?: Timestamp }
45+
// note that in case only readTime is optional and readOnly is true
46+
)
4047
console.log('Transaction successfully committed!')
4148
} catch (e) {
4249
console.log('Transaction failed: ', e)

0 commit comments

Comments
 (0)