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 | 25 | try |
| 26 | 26 | db = event.target.result |
| 27 | 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 | 29 | @checkedBuggyIDB = true |
| 30 | 30 | catch |
| 31 | 31 | try db.close() |
| @@ -66,10 +66,14 @@ class app.DB · 34 unmodified lines | ||
| 66 | 66 | onError() |
| 67 | 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 | 70 | txn.oncomplete = => |
| 71 | 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 | 77 | return |
| 74 | 78 | |
| 75 | 79 | store = txn.objectStore(doc.slug) |
| @@ -87,10 +91,14 @@ class app.DB · 11 unmodified lines | ||
| 87 | 91 | onError() |
| 88 | 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 | 95 | txn.oncomplete = => |
| 92 | 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 | 102 | return |
| 95 | 103 | |
| 96 | 104 | store = txn.objectStore(doc.slug) |
| @@ -106,12 +114,12 @@ class app.DB · 9 unmodified lines | ||
| 106 | 114 | fn(version) |
| 107 | 115 | return |
| 108 | 116 | |
| 109 | − @db (db) -> | |
| 117 | + @db (db) => | |
| 110 | 118 | unless db |
| 111 | 119 | fn(false) |
| 112 | 120 | return |
| 113 | 121 | |
| 114 | − txn = db.transaction ['docs'], 'readonly' | |
| 122 | + txn = @idbTransaction db, stores: ['docs'], mode: 'readonly' | |
| 115 | 123 | store = txn.objectStore('docs') |
| 116 | 124 | |
| 117 | 125 | req = store.get(doc.slug) |
| @@ -134,13 +142,15 @@ class app.DB · 16 unmodified lines | ||
| 134 | 142 | fn(versions) |
| 135 | 143 | return |
| 136 | 144 | |
| 137 | − @db (db) -> | |
| 145 | + @db (db) => | |
| 138 | 146 | unless db |
| 139 | 147 | fn(false) |
| 140 | 148 | return |
| 141 | 149 | |
| 142 | − txn = db.transaction ['docs'], 'readonly' | |
| 143 | − txn.oncomplete = -> fn(result) | |
| 150 | + txn = @idbTransaction db, stores: ['docs'], mode: 'readonly' | |
| 151 | + txn.oncomplete = -> | |
| 152 | + fn(result) | |
| 153 | + return | |
| 144 | 154 | store = txn.objectStore('docs') |
| 145 | 155 | result = {} |
| 146 | 156 | |
| @@ -182,7 +192,7 @@ class app.DB · 35 unmodified lines | ||
| 182 | 192 | onError() |
| 183 | 193 | return |
| 184 | 194 | |
| 185 | − txn = db.transaction [entry.doc.slug], 'readonly' | |
| 195 | + txn = @idbTransaction db, stores: [entry.doc.slug], mode: 'readonly' | |
| 186 | 196 | store = txn.objectStore(entry.doc.slug) |
| 187 | 197 | |
| 188 | 198 | req = store.get(entry.dbPath()) |
| @@ -199,7 +209,7 @@ class app.DB · 10 unmodified lines | ||
| 199 | 209 | loadDocsCache: (db) -> |
| 200 | 210 | @cachedDocs = {} |
| 201 | 211 | |
| 202 | − txn = db.transaction ['docs'], 'readonly' | |
| 212 | + txn = @idbTransaction db, stores: ['docs'], mode: 'readonly' | |
| 203 | 213 | store = txn.objectStore('docs') |
| 204 | 214 | |
| 205 | 215 | req = store.openCursor() |
| @@ -216,6 +226,18 @@ class app.DB · 10 unmodified lines | ||
| 216 | 226 | shouldLoadWithIDB: (entry) -> |
| 217 | 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 | 241 | reset: -> |
| 220 | 242 | try indexedDB?.deleteDatabase(NAME) catch |
| 221 | 243 | return |