Fix Realm.open() with no config
This commit is contained in:
parent
28e4d9bb96
commit
f85fe2f91d
16
CHANGELOG.md
16
CHANGELOG.md
|
@ -1,3 +1,19 @@
|
||||||
|
x.x.x Release notes (xxxx-xx-xx)
|
||||||
|
=============================================================
|
||||||
|
### Compatibility
|
||||||
|
|
||||||
|
### Breaking changes
|
||||||
|
* None.
|
||||||
|
|
||||||
|
### Enhancements
|
||||||
|
* None
|
||||||
|
|
||||||
|
### Bug fixes
|
||||||
|
* Fix `Realm.open()` to work without passing a config.
|
||||||
|
|
||||||
|
### Internal
|
||||||
|
|
||||||
|
|
||||||
2.6.0 Release notes (2018-5-16)
|
2.6.0 Release notes (2018-5-16)
|
||||||
=============================================================
|
=============================================================
|
||||||
### Compatibility
|
### Compatibility
|
||||||
|
|
|
@ -105,7 +105,7 @@ class Realm {
|
||||||
/**
|
/**
|
||||||
* Open a Realm asynchronously with a promise. If the Realm is synced, it will be fully
|
* Open a Realm asynchronously with a promise. If the Realm is synced, it will be fully
|
||||||
* synchronized before it is available.
|
* synchronized before it is available.
|
||||||
* @param {Realm~Configuration} config
|
* @param {Realm~Configuration} config - if no config is defined, it will open the default realm
|
||||||
* @returns {ProgressPromise} - a promise that will be resolved with the Realm instance when it's available.
|
* @returns {ProgressPromise} - a promise that will be resolved with the Realm instance when it's available.
|
||||||
*/
|
*/
|
||||||
static open(config) {}
|
static open(config) {}
|
||||||
|
|
|
@ -64,6 +64,9 @@ module.exports = function(realmConstructor) {
|
||||||
//Add async open API
|
//Add async open API
|
||||||
Object.defineProperties(realmConstructor, getOwnPropertyDescriptors({
|
Object.defineProperties(realmConstructor, getOwnPropertyDescriptors({
|
||||||
open(config) {
|
open(config) {
|
||||||
|
// If no config is defined, we should just open the default realm
|
||||||
|
if (config === undefined) { config = {}; }
|
||||||
|
|
||||||
// For local Realms we open the Realm and return it in a resolved Promise.
|
// For local Realms we open the Realm and return it in a resolved Promise.
|
||||||
if (!("sync" in config)) {
|
if (!("sync" in config)) {
|
||||||
let promise = Promise.resolve(new realmConstructor(config));
|
let promise = Promise.resolve(new realmConstructor(config));
|
||||||
|
|
|
@ -222,6 +222,21 @@ module.exports = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
testRealmOpenNoConfig: function() {
|
||||||
|
let realm = new Realm({schema: [schemas.TestObject], schemaVersion: 1});
|
||||||
|
realm.write(() => {
|
||||||
|
realm.create('TestObject', [1])
|
||||||
|
});
|
||||||
|
realm.close();
|
||||||
|
|
||||||
|
return Realm.open().then(realm => {
|
||||||
|
const objects = realm.objects('TestObject');
|
||||||
|
TestCase.assertEqual(objects.length, 1);
|
||||||
|
TestCase.assertEqual(objects[0].doubleCol, 1.0);
|
||||||
|
realm.close();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
testDefaultPath: function() {
|
testDefaultPath: function() {
|
||||||
const defaultPath = Realm.defaultPath;
|
const defaultPath = Realm.defaultPath;
|
||||||
let defaultRealm = new Realm({schema: []});
|
let defaultRealm = new Realm({schema: []});
|
||||||
|
|
Loading…
Reference in New Issue