Adding property Realm.isClosed. (#1560)

* Adding property Realm.isClosed.
This commit is contained in:
Kenneth Geisshirt 2017-12-13 10:09:26 +01:00 committed by GitHub
parent 517c165c12
commit aed1ea104b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 1 deletions

View File

@ -1,3 +1,18 @@
X.Y.Z Release notes
=============================================================
### Breaking changes
* None.
### Enhancements
* Added property `Realm.isClosed` which indicates if a Realm instance is closed or not.
### Bug fixes
* None.
### Internal
* None.
2.0.13 Release notes (2017-12-8) 2.0.13 Release notes (2017-12-8)
============================================================= =============================================================
### Breaking changes ### Breaking changes

View File

@ -72,6 +72,14 @@ class Realm {
*/ */
get isInTransaction() {} get isInTransaction() {}
/**
* Indicates if this Realm has been closed.
* @type {boolean}
* @readonly
* @since 2.1.0
*/
get isClosed() {}
/** /**
* Gets the sync session if this is a synced Realm * Gets the sync session if this is a synced Realm
* @type {Session} * @type {Session}

View File

@ -60,6 +60,7 @@ function setupRealm(realm, realmId) {
'schemaVersion', 'schemaVersion',
'syncSession', 'syncSession',
'isInTransaction', 'isInTransaction',
'isClosed',
'subscribeToObjects', 'subscribeToObjects',
].forEach((name) => { ].forEach((name) => {
Object.defineProperty(realm, name, {get: util.getterForProperty(name)}); Object.defineProperty(realm, name, {get: util.getterForProperty(name)});

1
lib/index.d.ts vendored
View File

@ -458,6 +458,7 @@ declare class Realm {
readonly schema: Realm.ObjectSchema[]; readonly schema: Realm.ObjectSchema[];
readonly schemaVersion: number; readonly schemaVersion: number;
readonly isInTransaction: boolean; readonly isInTransaction: boolean;
readonly isClosed: boolean;
readonly syncSession: Realm.Sync.Session | null; readonly syncSession: Realm.Sync.Session | null;

View File

@ -198,6 +198,7 @@ public:
static void get_in_memory(ContextType, ObjectType, ReturnValue &); static void get_in_memory(ContextType, ObjectType, ReturnValue &);
static void get_read_only(ContextType, ObjectType, ReturnValue &); static void get_read_only(ContextType, ObjectType, ReturnValue &);
static void get_is_in_transaction(ContextType, ObjectType, ReturnValue &); static void get_is_in_transaction(ContextType, ObjectType, ReturnValue &);
static void get_is_closed(ContextType, ObjectType, ReturnValue &);
#if REALM_ENABLE_SYNC #if REALM_ENABLE_SYNC
static void get_sync_session(ContextType, ObjectType, ReturnValue &); static void get_sync_session(ContextType, ObjectType, ReturnValue &);
#endif #endif
@ -259,6 +260,7 @@ public:
{"inMemory", {wrap<get_in_memory>, nullptr}}, {"inMemory", {wrap<get_in_memory>, nullptr}},
{"readOnly", {wrap<get_read_only>, nullptr}}, {"readOnly", {wrap<get_read_only>, nullptr}},
{"isInTransaction", {wrap<get_is_in_transaction>, nullptr}}, {"isInTransaction", {wrap<get_is_in_transaction>, nullptr}},
{"isClosed", {wrap<get_is_closed>, nullptr}},
#if REALM_ENABLE_SYNC #if REALM_ENABLE_SYNC
{"syncSession", {wrap<get_sync_session>, nullptr}}, {"syncSession", {wrap<get_sync_session>, nullptr}},
#endif #endif
@ -694,6 +696,11 @@ void RealmClass<T>::get_is_in_transaction(ContextType ctx, ObjectType object, Re
return_value.set(get_internal<T, RealmClass<T>>(object)->get()->is_in_transaction()); return_value.set(get_internal<T, RealmClass<T>>(object)->get()->is_in_transaction());
} }
template<typename T>
void RealmClass<T>::get_is_closed(ContextType ctx, ObjectType object, ReturnValue &return_value) {
return_value.set(get_internal<T, RealmClass<T>>(object)->get()->is_closed());
}
#if REALM_ENABLE_SYNC #if REALM_ENABLE_SYNC
template<typename T> template<typename T>
void RealmClass<T>::get_sync_session(ContextType ctx, ObjectType object, ReturnValue &return_value) { void RealmClass<T>::get_sync_session(ContextType ctx, ObjectType object, ReturnValue &return_value) {

View File

@ -57,6 +57,13 @@ module.exports = {
TestCase.assertEqual(realm2.path, defaultDir + testPath2); TestCase.assertEqual(realm2.path, defaultDir + testPath2);
}, },
testRealmIsClosed: function() {
const realm = new Realm({schema: []});
TestCase.assertFalse(realm.isClosed);
realm.close();
TestCase.assertTrue(realm.isClosed);
},
testRealmConstructorSchemaVersion: function() { testRealmConstructorSchemaVersion: function() {
const defaultRealm = new Realm({schema: []}); const defaultRealm = new Realm({schema: []});
TestCase.assertEqual(defaultRealm.schemaVersion, 0); TestCase.assertEqual(defaultRealm.schemaVersion, 0);