-
-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit makes two changes. 1. The connect() method was changed to be able to set options for an existing node. If the node is disconnected then the options will just be saved on the existing node. If the node is already connected, it will be disconnected, the options will be saved and the node will be reconnected. This only happens if the current options for the node differ from the options connect() was called with. 2. A new method getOptions(url) was added which can be used to get the current options for the given node. This commit closes #447 I decided not to implement a setOptions() method as I don't think that it has much usage if we can have the same effect by using connect().
- Loading branch information
1 parent
5b93c78
commit 146950c
Showing
6 changed files
with
143 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
///<reference path="test-syncable.html" /> | ||
(function () { | ||
|
||
/* The following is being tested: | ||
1. getOptions method | ||
2. changing options on an existing connected node by using connect() with a different options object than before | ||
3. changing options on an existing disconnected node by using connect() with a different options object than before | ||
*/ | ||
var db = new Dexie("optionsTestDB"); | ||
var deletePromise = Dexie.delete("optionsTestDB"); | ||
|
||
module("tests-changing-options", { | ||
setup: function () { | ||
db.close(); | ||
stop(); | ||
deletePromise.then(function () { | ||
start() | ||
}); | ||
}, | ||
teardown: function () { | ||
} | ||
}); | ||
|
||
asyncTest('Change options on an existing node', function () { | ||
var protocolName = 'testProtocol'; | ||
var serverUrl = 'http://dummy.local'; | ||
var syncProtocol = { | ||
sync: undefined, | ||
partialsThreshold: 1000 | ||
}; | ||
|
||
Dexie.Syncable.registerSyncProtocol(protocolName, syncProtocol); | ||
|
||
db.version(1).stores({objects: "$$"}); | ||
db.open(); | ||
|
||
syncProtocol.sync = function(context, url, options, baseRevision, syncedRevision, changes, partial, applyRemoteChanges, onChangesAccepted, onSuccess) { | ||
propEqual(options, {option1: 'option1'}, 'sync got the correct options'); | ||
onSuccess({again: 1000}); | ||
}; | ||
|
||
db.syncable.connect(protocolName, serverUrl, {option1: "option1"}) | ||
.then(() => { | ||
return db.syncable.getOptions(serverUrl); | ||
}) | ||
.then((options) => { | ||
propEqual(options, {option1: 'option1'}, 'getOptions got the correct options'); | ||
|
||
syncProtocol.sync = function(context, url, options, baseRevision, syncedRevision, changes, partial, applyRemoteChanges, onChangesAccepted, onSuccess) { | ||
propEqual(options, {newOptions: 'other options'}, 'sync got the new options'); | ||
onSuccess({again: 1000}); | ||
}; | ||
|
||
// Test changing options on an already connected node | ||
// We are already connected but are changing options | ||
// We expect that the next getOptions/sync call has the new options | ||
return db.syncable.connect(protocolName, serverUrl, {newOptions: 'other options'}); | ||
}) | ||
.then(() => { | ||
return db.syncable.getOptions(serverUrl); | ||
}) | ||
.then((options) => { | ||
propEqual(options, {newOptions: 'other options'}, 'getOptions got the new options'); | ||
// Test changing options on a disconnected existing node | ||
return db.syncable.disconnect(serverUrl); | ||
}) | ||
.then(() => { | ||
syncProtocol.sync = function(context, url, options, baseRevision, syncedRevision, changes, partial, applyRemoteChanges, onChangesAccepted, onSuccess) { | ||
propEqual(options, {evenNewerOptions: 'super new options'}, 'sync got the even newer options'); | ||
onSuccess({again: 1000}); | ||
}; | ||
|
||
return db.syncable.connect(protocolName, serverUrl, {evenNewerOptions: 'super new options'}); | ||
}) | ||
.then(() => { | ||
return db.syncable.getOptions(serverUrl); | ||
}) | ||
.then((options) => { | ||
propEqual(options, {evenNewerOptions: 'super new options'}, 'getOptions got the even newer options'); | ||
}) | ||
.catch(function(err) { | ||
ok(false, "Error: " + err); | ||
}) | ||
.finally(start); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters