Skip to content

Commit

Permalink
Remove keepAlive pseudo functions
Browse files Browse the repository at this point in the history
The keepAlive hack introduced as a work-around for
dart-lang/sdk#49643
is no longer needed, as of dart 2.19.0 or later.
  • Loading branch information
nielsenko committed May 26, 2024
1 parent 4e75f51 commit e65cc14
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 103 deletions.
7 changes: 1 addition & 6 deletions packages/realm_dart/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class AppConfiguration {
/// * Register uses and perform various user-related operations through authentication providers
/// * Synchronize data between the local device and a remote Realm App with Synchronized Realms
/// {@category Application}
class App implements Finalizable {
class App {
final AppHandle _handle;

/// The id of this application. This is the same as the appId in the [AppConfiguration] used to
Expand Down Expand Up @@ -260,11 +260,6 @@ enum MetadataPersistenceMode {

/// @nodoc
extension AppInternal on App {
@pragma('vm:never-inline')
void keepAlive() {
_handle.keepAlive();
}

AppHandle get handle => _handle;

static App create(AppHandle handle) => App._(handle);
Expand Down
7 changes: 1 addition & 6 deletions packages/realm_dart/lib/src/collections.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MapChanges {
}

/// Describes the changes in a Realm collection since the last time the notification callback was invoked.
class RealmCollectionChanges implements Finalizable {
class RealmCollectionChanges {
final CollectionChangesHandle _handle;
late final CollectionChanges _changes = _handle.changes;

Expand All @@ -73,10 +73,5 @@ class RealmCollectionChanges implements Finalizable {
}

extension RealmCollectionChangesInternal on RealmCollectionChanges {
@pragma('vm:never-inline')
void keepAlive() {
_handle.keepAlive();
}

CollectionChanges get changes => _changes;
}
7 changes: 1 addition & 6 deletions packages/realm_dart/lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ typedef AfterResetCallback = FutureOr<void> Function(Realm beforeResetRealm, Rea

/// Configuration used to create a `Realm` instance
/// {@category Configuration}
abstract class Configuration implements Finalizable {
abstract class Configuration {
/// The default realm filename to be used.
static String get defaultRealmName => _path.basename(defaultRealmPath);
static set defaultRealmName(String name) => defaultRealmPath = _path.join(_path.dirname(defaultRealmPath), _path.basename(name));
Expand Down Expand Up @@ -377,11 +377,6 @@ class FlexibleSyncConfiguration extends Configuration {
}

extension FlexibleSyncConfigurationInternal on FlexibleSyncConfiguration {
@pragma('vm:never-inline')
void keepAlive() {
user.keepAlive();
}

SessionStopPolicy get sessionStopPolicy => _sessionStopPolicy;
set sessionStopPolicy(SessionStopPolicy value) => _sessionStopPolicy = value;
}
Expand Down
14 changes: 2 additions & 12 deletions packages/realm_dart/lib/src/credentials.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extension AuthProviderTypeInternal on AuthProviderType {

/// A class, representing the credentials used for authenticating a [User]
/// {@category Application}
class Credentials implements Finalizable {
class Credentials {
final CredentialsHandle _handle;

/// Returns a [Credentials] object that can be used to authenticate an anonymous user.
Expand Down Expand Up @@ -100,18 +100,13 @@ class Credentials implements Finalizable {

/// @nodoc
extension CredentialsInternal on Credentials {
@pragma('vm:never-inline')
void keepAlive() {
_handle.keepAlive();
}

CredentialsHandle get handle => _handle;
}

/// A class, encapsulating functionality for users, logged in with [Credentials.emailPassword()].
/// It is always scoped to a particular app.
/// {@category Application}
class EmailPasswordAuthProvider implements Finalizable {
class EmailPasswordAuthProvider {
final App app;

/// Create a new EmailPasswordAuthProvider for the [app]
Expand Down Expand Up @@ -160,10 +155,5 @@ class EmailPasswordAuthProvider implements Finalizable {
}

extension EmailPasswordAuthProviderInternal on EmailPasswordAuthProvider {
@pragma('vm:never-inline')
void keepAlive() {
app.keepAlive();
}

static EmailPasswordAuthProvider create(App app) => EmailPasswordAuthProvider(app);
}
11 changes: 1 addition & 10 deletions packages/realm_dart/lib/src/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import 'results.dart';
/// added to or deleted from the collection or from the Realm.
///
/// {@category Realm}
abstract class RealmList<T extends Object?> with RealmEntity implements List<T>, Finalizable {
abstract class RealmList<T extends Object?> with RealmEntity implements List<T> {
late final RealmObjectMetadata? _metadata;

/// Gets a value indicating whether this collection is still valid to use.
Expand Down Expand Up @@ -255,15 +255,6 @@ extension RealmListOfObject<T extends RealmObjectBase> on RealmList<T> {

/// @nodoc
extension RealmListInternal<T extends Object?> on RealmList<T> {
@pragma('vm:never-inline')
void keepAlive() {
final self = this;
if (self is ManagedRealmList<T>) {
realm.keepAlive();
self._handle.keepAlive();
}
}

ManagedRealmList<T> asManaged() => this is ManagedRealmList<T> ? this as ManagedRealmList<T> : throw RealmStateError('$this is not managed');

ListHandle get handle {
Expand Down
11 changes: 1 addition & 10 deletions packages/realm_dart/lib/src/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import 'realm_class.dart';
import 'results.dart';

/// RealmMap is a collection that contains key-value pairs of <String, T>.
abstract class RealmMap<T extends Object?> with RealmEntity implements MapBase<String, T>, Finalizable {
abstract class RealmMap<T extends Object?> with RealmEntity implements MapBase<String, T> {
/// Gets a value indicating whether this collection is still valid to use.
///
/// Indicates whether the [Realm] instance hasn't been closed,
Expand Down Expand Up @@ -228,15 +228,6 @@ extension RealmMapOfObject<T extends RealmObjectBase> on RealmMap<T?> {

/// @nodoc
extension RealmMapInternal<T extends Object?> on RealmMap<T> {
@pragma('vm:never-inline')
void keepAlive() {
final self = this;
if (self is ManagedRealmMap<T>) {
realm.keepAlive();
self._handle.keepAlive();
}
}

ManagedRealmMap<T> asManaged() => this is ManagedRealmMap<T> ? this as ManagedRealmMap<T> : throw RealmStateError('$this is not managed');

MapHandle get handle {
Expand Down
13 changes: 2 additions & 11 deletions packages/realm_dart/lib/src/realm_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export 'user.dart' show User, UserState, ApiKeyClient, UserIdentity, ApiKey, Fun
/// A [Realm] instance represents a `Realm` database.
///
/// {@category Realm}
class Realm implements Finalizable {
class Realm {
late final RealmMetadata _metadata;
late final RealmHandle _handle;
final bool _isInMigration;
Expand Down Expand Up @@ -726,15 +726,6 @@ class Transaction {

/// @nodoc
extension RealmInternal on Realm {
@pragma('vm:never-inline')
void keepAlive() {
_handle.keepAlive();
final c = config;
if (c is FlexibleSyncConfiguration) {
c.keepAlive();
}
}

RealmHandle get handle {
if (_handle.released) {
throw RealmClosedError('Cannot access realm that has been closed');
Expand Down Expand Up @@ -863,7 +854,7 @@ extension RealmInternal on Realm {
}

/// @nodoc
abstract class NotificationsController implements Finalizable {
abstract class NotificationsController {
NotificationTokenHandle? handle;

NotificationTokenHandle subscribe();
Expand Down
17 changes: 3 additions & 14 deletions packages/realm_dart/lib/src/realm_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ extension RealmEntityInternal on RealmEntity {
///
/// [RealmObject] should not be used directly as it is part of the generated class hierarchy. ex: `MyClass extends _MyClass with RealmObject`.
/// {@category Realm}
mixin RealmObjectBase on RealmEntity implements RealmObjectBaseMarker, Finalizable {
mixin RealmObjectBase on RealmEntity implements RealmObjectBaseMarker {
ObjectHandle? _handle;
RealmAccessor _accessor = RealmValuesAccessor();
static final Map<Type, RealmObjectBase Function()> _factories = <Type, RealmObjectBase Function()>{
Expand Down Expand Up @@ -646,12 +646,6 @@ extension EmbeddedObjectExtension on EmbeddedObject {
/// @nodoc
//RealmObject package internal members
extension RealmObjectInternal on RealmObjectBase {
@pragma('vm:never-inline')
void keepAlive() {
_realm?.keepAlive();
_handle?.keepAlive();
}

void manage(Realm realm, ObjectHandle handle, RealmCoreAccessor accessor, bool update) {
if (_handle != null) {
//most certainly a bug hence we throw an Error
Expand Down Expand Up @@ -726,7 +720,7 @@ class UserCallbackException extends RealmException {
}

/// Describes the changes in on a single RealmObject since the last time the notification callback was invoked.
class RealmObjectChanges<T extends RealmObjectBase> implements Finalizable {
class RealmObjectChanges<T extends RealmObjectBase> {
// ignore: unused_field
final ObjectChangesHandle _handle;

Expand All @@ -749,12 +743,7 @@ class RealmObjectChanges<T extends RealmObjectBase> implements Finalizable {
}

/// @nodoc
extension RealmObjectChangesInternal<T extends RealmObject> on RealmObjectChanges<T> {
@pragma('vm:never-inline')
void keepAlive() {
_handle.keepAlive();
}
}
extension RealmObjectChangesInternal<T extends RealmObject> on RealmObjectChanges<T> {}

/// @nodoc
class RealmObjectNotificationsController<T extends RealmObjectBase> extends NotificationsController {
Expand Down
7 changes: 1 addition & 6 deletions packages/realm_dart/lib/src/results.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import 'realm_object.dart';
/// added to or deleted from the Realm that match the underlying query.
///
/// {@category Realm}
class RealmResults<T extends Object?> extends Iterable<T> with RealmEntity implements Finalizable {
class RealmResults<T extends Object?> extends Iterable<T> with RealmEntity {
final RealmObjectMetadata? _metadata;
final ResultsHandle _handle;
final int _skipOffset; // to support skip efficiently
Expand Down Expand Up @@ -278,11 +278,6 @@ extension RealmResultsOfRealmObject<T extends RealmObject> on RealmResults<T> {
/// @nodoc
//RealmResults package internal members
extension RealmResultsInternal on RealmResults {
@pragma('vm:never-inline')
void keepAlive() {
_handle.keepAlive();
}

ResultsHandle get handle {
if (_handle.released) {
throw RealmClosedError('Cannot access Results that belongs to a closed Realm');
Expand Down
7 changes: 1 addition & 6 deletions packages/realm_dart/lib/src/session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'user.dart';
/// server. Sessions are always created by the SDK and vended out through various
/// APIs. The lifespans of sessions associated with Realms are managed automatically.
/// {@category Sync}
class Session implements Finalizable {
class Session {
final SessionHandle _handle;

/// The on-disk path of the file backing the [Realm] this [Session] represents
Expand Down Expand Up @@ -98,11 +98,6 @@ class ConnectionStateChange {
}

extension SessionInternal on Session {
@pragma('vm:never-inline')
void keepAlive() {
_handle.keepAlive();
}

static Session create(SessionHandle handle) => Session._(handle);

SessionHandle get handle {
Expand Down
2 changes: 1 addition & 1 deletion packages/realm_dart/lib/src/set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import 'collections.dart';
import 'results.dart';

/// RealmSet is a collection that contains no duplicate elements.
abstract class RealmSet<T extends Object?> extends SetBase<T> with RealmEntity implements Finalizable {
abstract class RealmSet<T extends Object?> extends SetBase<T> with RealmEntity {
RealmObjectMetadata? _metadata;

/// Gets a value indicating whether this collection is still valid to use.
Expand Down
10 changes: 2 additions & 8 deletions packages/realm_dart/lib/src/subscription.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'results.dart';
/// evaluate the query that the app subscribed to and will send data
/// that matches it as well as remove data that no longer does.
/// {@category Sync}
final class Subscription implements Finalizable {
final class Subscription {
final SubscriptionHandle _handle;

Subscription._(this._handle);
Expand Down Expand Up @@ -115,7 +115,7 @@ enum SubscriptionSetState {
/// Realm is an expensive operation server-side, even if there's very little data that needs
/// downloading.
/// {@category Sync}
sealed class SubscriptionSet with Iterable<Subscription> implements Finalizable {
sealed class SubscriptionSet with Iterable<Subscription> {
final Realm _realm;
SubscriptionSetHandle __handle;
SubscriptionSetHandle get _handle => __handle.nullPtrAsNull ?? (throw RealmClosedError('Cannot access a SubscriptionSet that belongs to a closed Realm'));
Expand Down Expand Up @@ -195,12 +195,6 @@ sealed class SubscriptionSet with Iterable<Subscription> implements Finalizable
}

extension SubscriptionSetInternal on SubscriptionSet {
@pragma('vm:never-inline')
void keepAlive() {
_realm.keepAlive();
_handle.keepAlive();
}

SubscriptionSetHandle get handle => _handle;

static SubscriptionSet create(Realm realm, SubscriptionSetHandle handle) => ImmutableSubscriptionSet._(realm, handle);
Expand Down
8 changes: 1 addition & 7 deletions packages/realm_dart/lib/src/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class User {
}

/// @nodoc
class UserNotificationsController implements Finalizable {
class UserNotificationsController {
UserNotificationTokenHandle? tokenHandle;

void start() {
Expand Down Expand Up @@ -367,12 +367,6 @@ extension UserIdentityInternal on UserIdentity {

/// @nodoc
extension UserInternal on User {
@pragma('vm:never-inline')
void keepAlive() {
_handle.keepAlive();
_app?.keepAlive();
}

UserHandle get handle => _handle;

static User create(UserHandle handle, [App? app]) => User._(handle, app);
Expand Down

0 comments on commit e65cc14

Please sign in to comment.