(id = 0, fake = false)
| 89 | |
| 90 | /** trigger all changeListeners */ |
| 91 | const flushChangesImpl: FlushChangesImpl = async function (id = 0, fake = false) { |
| 92 | // Only flush if ID is 0 or the current flush ID is the same as passed |
| 93 | if (id !== 0 && bufferChangesId !== id) { |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | bufferingChanges = false; |
| 98 | const changes = [...changeBuffer]; |
| 99 | changeBuffer = []; |
| 100 | |
| 101 | if (changes.length === 0) { |
| 102 | // No work to do |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | if (fake) { |
| 107 | console.log(`[db] Dropped ${changes.length} changes.`); |
| 108 | return; |
| 109 | } |
| 110 | // Notify local listeners too |
| 111 | for (const fn of changeListeners) { |
| 112 | await fn(changes); |
| 113 | } |
| 114 | |
| 115 | return changes; |
| 116 | }; |
| 117 | |
| 118 | const originalDatabase: IDatabase<initOptions> = { |
| 119 | batchModifyDocs: async function ({ upsert = [], remove = [] }: Operation) { |
no test coverage detected