Skip to content

Commit

Permalink
Fix instances where SubscriptionSet was still referred to as Subscrip…
Browse files Browse the repository at this point in the history
…tions (#4298)
  • Loading branch information
tomduncalf authored Feb 2, 2022
1 parent 74b06e0 commit 748e9e8
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ x.x.x Release notes (yyyy-MM-dd)
* <Upgraded Realm Core from vX.Y.Z to vA.B.C>
* Fixed documentation publishing ([#4276](https://github.com/realm/realm-js/pull/4276))
* Enabled mixed tests for flexible sync ([#4279](https://github.com/realm/realm-js/pull/4279))
* Fixed an issue where some references were not updated from `Subscriptions` to `SubscriptionSet` ([#4298](https://github.com/realm/realm-js/pull/4298))

10.12.0 Release notes (2022-1-24)
=============================================================
Expand Down
2 changes: 1 addition & 1 deletion docs/realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Realm {

/**
* Get the latest set of flexible sync subscriptions.
* @type {Realm.App.Sybc.Subscriptions}
* @type {Realm.App.Sybc.SubscriptionSet}
* @throws if flexible sync is not enabled for this app
* @readonly
*/
Expand Down
11 changes: 9 additions & 2 deletions integration-tests/tests/src/tests/sync/flexible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe.skipIf(environment.missingServer, "Flexible sync", function () {

describe("Realm#subscriptions", function () {
it("returns a SubscriptionSet instance", function (this: RealmContext) {
expect(this.realm.subscriptions).to.be.instanceOf(Realm.App.Sync.Subscriptions);
expect(this.realm.subscriptions).to.be.instanceOf(Realm.App.Sync.SubscriptionSet);
});

it("throws an error if the Realm does not have a sync config", function (this: RealmContext) {
Expand Down Expand Up @@ -655,7 +655,7 @@ describe.skipIf(environment.missingServer, "Flexible sync", function () {
});

// TODO waiting on https://github.com/realm/realm-core/pull/5162
xit("throws an error if a mutating method is called outside of an update() callback by holding a reference to the MutableSubscriptions", function (this: RealmContext) {
xit("throws an error if a mutating method is called outside of an update() callback by holding a reference to the MutableSubscriptionSet", function (this: RealmContext) {
const subs = this.realm.subscriptions;
let mutableSubs: Realm.App.Sync.MutableSubscriptionSet;

Expand All @@ -681,6 +681,13 @@ describe.skipIf(environment.missingServer, "Flexible sync", function () {
});
});

it("passes a MutableSubscriptionSet instance as an argument", function (this: RealmContext) {
const subs = this.realm.subscriptions;
subs.update((mutableSubs) => {
expect(mutableSubs).to.be.instanceOf(Realm.App.Sync.MutableSubscriptionSet);
});
});

it("mutates the SubscriptionSet instance", function (this: RealmContext) {
const subs = this.realm.subscriptions;
subs.update((mutableSubs) => {
Expand Down
10 changes: 5 additions & 5 deletions lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,14 @@ module.exports = function (realmConstructor) {
Object.defineProperties(realmConstructor.User, getOwnPropertyDescriptors(userMethods.static));
Object.defineProperties(realmConstructor.User.prototype, getOwnPropertyDescriptors(userMethods.instance));

let subscriptionsMethods = require("./subscriptions");
let subscriptionSetMethods = require("./subscription-set");

Object.defineProperties(
realmConstructor.App.Sync.Subscriptions,
getOwnPropertyDescriptors(subscriptionsMethods.static),
realmConstructor.App.Sync.SubscriptionSet,
getOwnPropertyDescriptors(subscriptionSetMethods.static),
);
Object.defineProperties(realmConstructor.App.Sync.Subscriptions.prototype, {
...getOwnPropertyDescriptors(subscriptionsMethods.instance),
Object.defineProperties(realmConstructor.App.Sync.SubscriptionSet.prototype, {
...getOwnPropertyDescriptors(subscriptionSetMethods.instance),
...require("./collection-methods")(realmConstructor),
});

Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/js_subscriptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class SubscriptionSetClass : public ClassDefinition<T, SubscriptionSet<T>> {
using Arguments = js::Arguments<T>;

public:
const std::string name = "Subscriptions";
const std::string name = "SubscriptionSet";
using StateChangeHandler = void(StatusWith<realm::sync::SubscriptionSet::State> state);

static ObjectType create_instance(ContextType, realm::sync::SubscriptionSet, std::shared_ptr<SyncSession>);
Expand Down Expand Up @@ -529,7 +529,7 @@ class MutableSubscriptionSet : public realm::sync::MutableSubscriptionSet {
*
* @note This is not modelled as an inheritance relationship in JS (using the third
* ClassDefinition template arg to set the parent), because we are not exposing all
* the methods of Subscriptions, so it is not strictly inheritance.
* the methods of SubscriptionSet, so it is not strictly inheritance.
*/
template <typename T>
class MutableSubscriptionSetClass : public ClassDefinition<T, MutableSubscriptionSet<T>> {
Expand All @@ -543,7 +543,7 @@ class MutableSubscriptionSetClass : public ClassDefinition<T, MutableSubscriptio
using Arguments = js::Arguments<T>;

public:
const std::string name = "MutableSubscriptions";
const std::string name = "MutableSubscriptionSet";

static ObjectType create_instance(ContextType, realm::sync::MutableSubscriptionSet);

Expand Down
4 changes: 2 additions & 2 deletions src/js_sync.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,9 +829,9 @@ inline typename T::Function SyncClass<T>::create_constructor(ContextType ctx)
attributes);
Object::set_property(ctx, sync_constructor, "Subscription",
ObjectWrap<T, SubscriptionClass<T>>::create_constructor(ctx), attributes);
Object::set_property(ctx, sync_constructor, "Subscriptions",
Object::set_property(ctx, sync_constructor, "SubscriptionSet",
ObjectWrap<T, SubscriptionSetClass<T>>::create_constructor(ctx), attributes);
Object::set_property(ctx, sync_constructor, "MutableSubscriptions",
Object::set_property(ctx, sync_constructor, "MutableSubscriptionSet",
ObjectWrap<T, MutableSubscriptionSetClass<T>>::create_constructor(ctx), attributes);

return sync_constructor;
Expand Down
6 changes: 3 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ declare namespace Realm {
update: (callback: (mutableSubs: MutableSubscriptionSet) => void) => Promise<void>;
}

const Subscriptions: {
const SubscriptionSet: {
new(): never; // This type isn't supposed to be constructed manually by end users.
readonly prototype: SubscriptionSet;
};
Expand Down Expand Up @@ -893,9 +893,9 @@ declare namespace Realm {
removeAll: () => number;
}

const MutableSubscriptions: {
const MutableSubscriptionSet: {
new(): never; // This type isn't supposed to be constructed manually by end users.
readonly prototype: SubscriptionSet;
readonly prototype: MutableSubscriptionSet;
};
}

Expand Down

0 comments on commit 748e9e8

Please sign in to comment.