Showing the changes to assets/javascripts (1 of 1 file). Show all
Unified · Split
| @@ -25,7 +25,7 @@ class app.DB · 24 unmodified lines | |||
| 25 | try | 25 | try |
| 26 | db = event.target.result | 26 | db = event.target.result |
| 27 | unless @checkedBuggyIDB | 27 | unless @checkedBuggyIDB |
| 28 | db.transaction(['docs', app.docs.all()[0].slug], 'readwrite').abort() # https://bugs.webkit.org/show_bug.cgi?id=136937 | 28 | @idbTransaction(db, stores: ['docs', app.docs.all()[0].slug], mode: 'readwrite').abort() # https://bugs.webkit.org/show_bug.cgi?id=136937 |
| 29 | @checkedBuggyIDB = true | 29 | @checkedBuggyIDB = true |
| 30 | catch | 30 | catch |
| 31 | try db.close() | 31 | try db.close() |
| @@ -66,10 +66,14 @@ class app.DB · 34 unmodified lines | |||
| 66 | onError() | 66 | onError() |
| 67 | return | 67 | return |
| 68 | 68 | ||
| 69 | txn = db.transaction ['docs', doc.slug], 'readwrite' | 69 | txn = @idbTransaction db, stores: ['docs', doc.slug], mode: 'readwrite', ignoreError: false |
| 70 | txn.oncomplete = => | 70 | txn.oncomplete = => |
| 71 | @cachedDocs?[doc.slug] = doc.mtime | 71 | @cachedDocs?[doc.slug] = doc.mtime |
| 72 | if txn.error then onError() else onSuccess() | 72 | onSuccess() |
| 73 | return | ||
| 74 | txn.onerror = (event) -> | ||
| 75 | event.preventDefault() | ||
| 76 | onError(event) | ||
| 73 | return | 77 | return |
| 74 | 78 | ||
| 75 | store = txn.objectStore(doc.slug) | 79 | store = txn.objectStore(doc.slug) |
| @@ -87,10 +91,14 @@ class app.DB · 11 unmodified lines | |||
| 87 | onError() | 91 | onError() |
| 88 | return | 92 | return |
| 89 | 93 | ||
| 90 | txn = db.transaction ['docs', doc.slug], 'readwrite' | 94 | txn = @idbTransaction db, stores: ['docs', doc.slug], mode: 'readwrite', ignoreError: false |
| 91 | txn.oncomplete = => | 95 | txn.oncomplete = => |
| 92 | delete @cachedDocs?[doc.slug] | 96 | delete @cachedDocs?[doc.slug] |
| 93 | if txn.error then onError() else onSuccess() | 97 | onSuccess() |
| 98 | return | ||
| 99 | txn.onerror = (event) -> | ||
| 100 | event.preventDefault() | ||
| 101 | onError(event) | ||
| 94 | return | 102 | return |
| 95 | 103 | ||
| 96 | store = txn.objectStore(doc.slug) | 104 | store = txn.objectStore(doc.slug) |
| @@ -106,12 +114,12 @@ class app.DB · 9 unmodified lines | |||
| 106 | fn(version) | 114 | fn(version) |
| 107 | return | 115 | return |
| 108 | 116 | ||
| 109 | @db (db) -> | 117 | @db (db) => |
| 110 | unless db | 118 | unless db |
| 111 | fn(false) | 119 | fn(false) |
| 112 | return | 120 | return |
| 113 | 121 | ||
| 114 | txn = db.transaction ['docs'], 'readonly' | 122 | txn = @idbTransaction db, stores: ['docs'], mode: 'readonly' |
| 115 | store = txn.objectStore('docs') | 123 | store = txn.objectStore('docs') |
| 116 | 124 | ||
| 117 | req = store.get(doc.slug) | 125 | req = store.get(doc.slug) |
| @@ -134,13 +142,15 @@ class app.DB · 16 unmodified lines | |||
| 134 | fn(versions) | 142 | fn(versions) |
| 135 | return | 143 | return |
| 136 | 144 | ||
| 137 | @db (db) -> | 145 | @db (db) => |
| 138 | unless db | 146 | unless db |
| 139 | fn(false) | 147 | fn(false) |
| 140 | return | 148 | return |
| 141 | 149 | ||
| 142 | txn = db.transaction ['docs'], 'readonly' | 150 | txn = @idbTransaction db, stores: ['docs'], mode: 'readonly' |
| 143 | txn.oncomplete = -> fn(result) | 151 | txn.oncomplete = -> |
| 152 | fn(result) | ||
| 153 | return | ||
| 144 | store = txn.objectStore('docs') | 154 | store = txn.objectStore('docs') |
| 145 | result = {} | 155 | result = {} |
| 146 | 156 | ||
| @@ -182,7 +192,7 @@ class app.DB · 35 unmodified lines | |||
| 182 | onError() | 192 | onError() |
| 183 | return | 193 | return |
| 184 | 194 | ||
| 185 | txn = db.transaction [entry.doc.slug], 'readonly' | 195 | txn = @idbTransaction db, stores: [entry.doc.slug], mode: 'readonly' |
| 186 | store = txn.objectStore(entry.doc.slug) | 196 | store = txn.objectStore(entry.doc.slug) |
| 187 | 197 | ||
| 188 | req = store.get(entry.dbPath()) | 198 | req = store.get(entry.dbPath()) |
| @@ -199,7 +209,7 @@ class app.DB · 10 unmodified lines | |||
| 199 | loadDocsCache: (db) -> | 209 | loadDocsCache: (db) -> |
| 200 | @cachedDocs = {} | 210 | @cachedDocs = {} |
| 201 | 211 | ||
| 202 | txn = db.transaction ['docs'], 'readonly' | 212 | txn = @idbTransaction db, stores: ['docs'], mode: 'readonly' |
| 203 | store = txn.objectStore('docs') | 213 | store = txn.objectStore('docs') |
| 204 | 214 | ||
| 205 | req = store.openCursor() | 215 | req = store.openCursor() |
| @@ -216,6 +226,18 @@ class app.DB · 10 unmodified lines | |||
| 216 | shouldLoadWithIDB: (entry) -> | 226 | shouldLoadWithIDB: (entry) -> |
| 217 | @useIndexedDB and (not @cachedDocs or @cachedDocs[entry.doc.slug]) | 227 | @useIndexedDB and (not @cachedDocs or @cachedDocs[entry.doc.slug]) |
| 218 | 228 | ||
| 229 | idbTransaction: (db, options) -> | ||
| 230 | txn = db.transaction(options.stores, options.mode) | ||
| 231 | unless options.ignoreError is false | ||
| 232 | txn.onerror = (event) -> | ||
| 233 | event.preventDefault() | ||
| 234 | return | ||
| 235 | unless options.ignoreAbort is false | ||
| 236 | txn.onabort = (event) -> | ||
| 237 | event.preventDefault() | ||
| 238 | return | ||
| 239 | txn | ||
| 240 | |||
| 219 | reset: -> | 241 | reset: -> |
| 220 | try indexedDB?.deleteDatabase(NAME) catch | 242 | try indexedDB?.deleteDatabase(NAME) catch |
| 221 | return | 243 | return |