()
| 328 | |
| 329 | // Poll Pattern |
| 330 | function continueUsingPollPattern() { |
| 331 | function syncAgain() { |
| 332 | getLocalChangesForNode_autoAckIfEmpty( |
| 333 | node, |
| 334 | function ( |
| 335 | changes, |
| 336 | remoteBaseRevision, |
| 337 | partial, |
| 338 | nodeModificationsOnAck |
| 339 | ) { |
| 340 | protocolInstance.sync( |
| 341 | node.syncContext, |
| 342 | url, |
| 343 | options, |
| 344 | remoteBaseRevision, |
| 345 | node.appliedRemoteRevision, |
| 346 | changes, |
| 347 | partial, |
| 348 | applyRemoteChanges, |
| 349 | onChangesAccepted, |
| 350 | onSuccess, |
| 351 | onError |
| 352 | ); |
| 353 | |
| 354 | function onChangesAccepted() { |
| 355 | Object.keys(nodeModificationsOnAck).forEach(function (keyPath) { |
| 356 | Dexie.setByKeyPath( |
| 357 | node, |
| 358 | keyPath, |
| 359 | nodeModificationsOnAck[keyPath] |
| 360 | ); |
| 361 | }); |
| 362 | node.save().catch('DatabaseClosedError', () => {}); |
| 363 | } |
| 364 | |
| 365 | function onSuccess(continuation) { |
| 366 | if (!connectedContinuation) { |
| 367 | // Got disconnected before succeeding. Quit. |
| 368 | return; |
| 369 | } |
| 370 | connectedContinuation = continuation; |
| 371 | if (partial) { |
| 372 | // We only sent partial changes. Need to do another round asap. |
| 373 | syncAgain(); |
| 374 | } else { |
| 375 | // We've sent all changes now (in sync!) |
| 376 | if ( |
| 377 | !isNaN(continuation.again) && |
| 378 | continuation.again < Infinity |
| 379 | ) { |
| 380 | // Provider wants to keep polling. Set Status to ONLINE. |
| 381 | changeStatusTo(Statuses.ONLINE); |
| 382 | setTimeout(function () { |
| 383 | if (connectedContinuation) { |
| 384 | changeStatusTo(Statuses.SYNCING); |
| 385 | syncAgain(); |
| 386 | } |
| 387 | }, continuation.again); |
no test coverage detected