mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-12 07:14:23 +00:00
Rename CollectionChangeIndices to CollectionChangeSet
This commit is contained in:
parent
953e1b15a8
commit
c0350b9001
@ -49,7 +49,7 @@ private:
|
||||
size_t m_token;
|
||||
};
|
||||
|
||||
struct CollectionChangeIndices {
|
||||
struct CollectionChangeSet {
|
||||
struct Move {
|
||||
size_t from;
|
||||
size_t to;
|
||||
@ -65,7 +65,7 @@ struct CollectionChangeIndices {
|
||||
bool empty() const { return deletions.empty() && insertions.empty() && modifications.empty() && moves.empty(); }
|
||||
};
|
||||
|
||||
using CollectionChangeCallback = std::function<void (CollectionChangeIndices, std::exception_ptr)>;
|
||||
using CollectionChangeCallback = std::function<void (CollectionChangeSet, std::exception_ptr)>;
|
||||
} // namespace realm
|
||||
|
||||
#endif // REALM_COLLECTION_NOTIFICATIONS_HPP
|
||||
|
@ -557,7 +557,7 @@ struct RowInfo {
|
||||
size_t shifted_tv_index;
|
||||
};
|
||||
|
||||
void calculate_moves_unsorted(std::vector<RowInfo>& new_rows, IndexSet& removed, CollectionChangeIndices& changeset)
|
||||
void calculate_moves_unsorted(std::vector<RowInfo>& new_rows, IndexSet& removed, CollectionChangeSet& changeset)
|
||||
{
|
||||
size_t expected = 0;
|
||||
for (auto& row : new_rows) {
|
||||
@ -587,7 +587,7 @@ void calculate_moves_unsorted(std::vector<RowInfo>& new_rows, IndexSet& removed,
|
||||
|
||||
class SortedMoveCalculator {
|
||||
public:
|
||||
SortedMoveCalculator(std::vector<RowInfo>& new_rows, CollectionChangeIndices& changeset)
|
||||
SortedMoveCalculator(std::vector<RowInfo>& new_rows, CollectionChangeSet& changeset)
|
||||
: m_modified(changeset.modifications)
|
||||
{
|
||||
std::vector<Row> old_candidates;
|
||||
|
@ -34,7 +34,7 @@ namespace realm {
|
||||
class Realm;
|
||||
|
||||
namespace _impl {
|
||||
class CollectionChangeBuilder : public CollectionChangeIndices {
|
||||
class CollectionChangeBuilder : public CollectionChangeSet {
|
||||
public:
|
||||
CollectionChangeBuilder(CollectionChangeBuilder const&) = default;
|
||||
CollectionChangeBuilder(CollectionChangeBuilder&&) = default;
|
||||
@ -170,7 +170,7 @@ private:
|
||||
|
||||
std::exception_ptr m_error;
|
||||
CollectionChangeBuilder m_accumulated_changes;
|
||||
CollectionChangeIndices m_changes_to_deliver;
|
||||
CollectionChangeSet m_changes_to_deliver;
|
||||
|
||||
// Tables which this collection needs change information for
|
||||
std::vector<size_t> m_relevant_tables;
|
||||
|
@ -447,7 +447,7 @@ void Results::prepare_async()
|
||||
NotificationToken Results::async(std::function<void (std::exception_ptr)> target)
|
||||
{
|
||||
prepare_async();
|
||||
auto wrap = [=](CollectionChangeIndices, std::exception_ptr e) { target(e); };
|
||||
auto wrap = [=](CollectionChangeSet, std::exception_ptr e) { target(e); };
|
||||
return {m_notifier, m_notifier->add_callback(wrap)};
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ TEST_CASE("list") {
|
||||
r->commit_transaction();
|
||||
|
||||
SECTION("add_notification_block()") {
|
||||
CollectionChangeIndices change;
|
||||
CollectionChangeSet change;
|
||||
List lst(r, *r->config().schema->find("origin"), lv);
|
||||
|
||||
auto write = [&](auto&& f) {
|
||||
@ -72,7 +72,7 @@ TEST_CASE("list") {
|
||||
};
|
||||
|
||||
auto require_change = [&] {
|
||||
auto token = lst.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr err) {
|
||||
auto token = lst.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) {
|
||||
change = c;
|
||||
});
|
||||
advance_and_notify(*r);
|
||||
@ -81,7 +81,7 @@ TEST_CASE("list") {
|
||||
|
||||
auto require_no_change = [&] {
|
||||
bool first = true;
|
||||
auto token = lst.add_notification_callback([&, first](CollectionChangeIndices c, std::exception_ptr err) mutable {
|
||||
auto token = lst.add_notification_callback([&, first](CollectionChangeSet c, std::exception_ptr err) mutable {
|
||||
REQUIRE(first);
|
||||
first = false;
|
||||
});
|
||||
@ -198,11 +198,11 @@ TEST_CASE("list") {
|
||||
|
||||
List lists[3];
|
||||
NotificationToken tokens[3];
|
||||
CollectionChangeIndices changes[3];
|
||||
CollectionChangeSet changes[3];
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
lists[i] = get_list();
|
||||
tokens[i] = lists[i].add_notification_callback([i, &changes](CollectionChangeIndices c, std::exception_ptr) {
|
||||
tokens[i] = lists[i].add_notification_callback([i, &changes](CollectionChangeSet c, std::exception_ptr) {
|
||||
changes[i] = std::move(c);
|
||||
});
|
||||
change_list();
|
||||
@ -248,14 +248,14 @@ TEST_CASE("list") {
|
||||
// Add a callback for list1, advance the version, then add a
|
||||
// callback for list2, so that the notifiers added at each source
|
||||
// version have different tables watched for modifications
|
||||
CollectionChangeIndices changes1, changes2;
|
||||
auto token1 = lst.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr) {
|
||||
CollectionChangeSet changes1, changes2;
|
||||
auto token1 = lst.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr) {
|
||||
changes1 = std::move(c);
|
||||
});
|
||||
|
||||
r->begin_transaction(); r->commit_transaction();
|
||||
|
||||
auto token2 = lst2.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr) {
|
||||
auto token2 = lst2.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr) {
|
||||
changes2 = std::move(c);
|
||||
});
|
||||
|
||||
@ -296,8 +296,8 @@ TEST_CASE("list") {
|
||||
Results results = lst.sort({{0}, {false}});
|
||||
|
||||
int notification_calls = 0;
|
||||
CollectionChangeIndices change;
|
||||
auto token = results.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr err) {
|
||||
CollectionChangeSet change;
|
||||
auto token = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) {
|
||||
REQUIRE_FALSE(err);
|
||||
change = c;
|
||||
++notification_calls;
|
||||
@ -352,8 +352,8 @@ TEST_CASE("list") {
|
||||
Results results = lst.filter(target->where().less(0, 9));
|
||||
|
||||
int notification_calls = 0;
|
||||
CollectionChangeIndices change;
|
||||
auto token = results.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr err) {
|
||||
CollectionChangeSet change;
|
||||
auto token = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) {
|
||||
REQUIRE_FALSE(err);
|
||||
change = c;
|
||||
++notification_calls;
|
||||
|
@ -51,8 +51,8 @@ TEST_CASE("Results") {
|
||||
|
||||
SECTION("unsorted notifications") {
|
||||
int notification_calls = 0;
|
||||
CollectionChangeIndices change;
|
||||
auto token = results.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr err) {
|
||||
CollectionChangeSet change;
|
||||
auto token = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) {
|
||||
REQUIRE_FALSE(err);
|
||||
change = c;
|
||||
++notification_calls;
|
||||
@ -107,8 +107,8 @@ TEST_CASE("Results") {
|
||||
SECTION("notifications are delivered when a new callback is added from within a callback") {
|
||||
NotificationToken token2, token3;
|
||||
bool called = false;
|
||||
token2 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) {
|
||||
token3 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) {
|
||||
token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
|
||||
token3 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
|
||||
called = true;
|
||||
});
|
||||
});
|
||||
@ -119,10 +119,10 @@ TEST_CASE("Results") {
|
||||
|
||||
SECTION("notifications are not delivered when a callback is removed from within a callback") {
|
||||
NotificationToken token2, token3;
|
||||
token2 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) {
|
||||
token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
|
||||
token3 = {};
|
||||
});
|
||||
token3 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) {
|
||||
token3 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
|
||||
REQUIRE(false);
|
||||
});
|
||||
|
||||
@ -132,10 +132,10 @@ TEST_CASE("Results") {
|
||||
SECTION("removing the current callback does not stop later ones from being called") {
|
||||
NotificationToken token2, token3;
|
||||
bool called = false;
|
||||
token2 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) {
|
||||
token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
|
||||
token2 = {};
|
||||
});
|
||||
token3 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr) {
|
||||
token3 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
|
||||
called = true;
|
||||
});
|
||||
|
||||
@ -277,7 +277,7 @@ TEST_CASE("Results") {
|
||||
}
|
||||
|
||||
SECTION("the first call of a notification can include changes if it previously ran for a different callback") {
|
||||
auto token2 = results.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr) {
|
||||
auto token2 = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr) {
|
||||
REQUIRE(!c.empty());
|
||||
});
|
||||
|
||||
@ -292,8 +292,8 @@ TEST_CASE("Results") {
|
||||
|
||||
SECTION("sorted notifications") {
|
||||
int notification_calls = 0;
|
||||
CollectionChangeIndices change;
|
||||
auto token = results.add_notification_callback([&](CollectionChangeIndices c, std::exception_ptr err) {
|
||||
CollectionChangeSet change;
|
||||
auto token = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) {
|
||||
REQUIRE_FALSE(err);
|
||||
change = c;
|
||||
++notification_calls;
|
||||
@ -447,7 +447,7 @@ TEST_CASE("Async Results error handling") {
|
||||
|
||||
SECTION("error is delivered asynchronously") {
|
||||
bool called = false;
|
||||
auto token = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr err) {
|
||||
auto token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) {
|
||||
REQUIRE(err);
|
||||
called = true;
|
||||
});
|
||||
@ -461,7 +461,7 @@ TEST_CASE("Async Results error handling") {
|
||||
|
||||
SECTION("adding another callback does not send the error again") {
|
||||
bool called = false;
|
||||
auto token = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr err) {
|
||||
auto token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) {
|
||||
REQUIRE(err);
|
||||
REQUIRE_FALSE(called);
|
||||
called = true;
|
||||
@ -470,7 +470,7 @@ TEST_CASE("Async Results error handling") {
|
||||
advance_and_notify(*r);
|
||||
|
||||
bool called2 = false;
|
||||
auto token2 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr err) {
|
||||
auto token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) {
|
||||
REQUIRE(err);
|
||||
REQUIRE_FALSE(called2);
|
||||
called2 = true;
|
||||
@ -484,7 +484,7 @@ TEST_CASE("Async Results error handling") {
|
||||
SECTION("error when opening the executor SG") {
|
||||
SECTION("error is delivered asynchronously") {
|
||||
bool called = false;
|
||||
auto token = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr err) {
|
||||
auto token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) {
|
||||
REQUIRE(err);
|
||||
called = true;
|
||||
});
|
||||
@ -499,7 +499,7 @@ TEST_CASE("Async Results error handling") {
|
||||
|
||||
SECTION("adding another callback does not send the error again") {
|
||||
bool called = false;
|
||||
auto token = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr err) {
|
||||
auto token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) {
|
||||
REQUIRE(err);
|
||||
REQUIRE_FALSE(called);
|
||||
called = true;
|
||||
@ -509,7 +509,7 @@ TEST_CASE("Async Results error handling") {
|
||||
advance_and_notify(*r);
|
||||
|
||||
bool called2 = false;
|
||||
auto token2 = results.add_notification_callback([&](CollectionChangeIndices, std::exception_ptr err) {
|
||||
auto token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) {
|
||||
REQUIRE(err);
|
||||
REQUIRE_FALSE(called2);
|
||||
called2 = true;
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
m_initial.push_back(lv->get(i).get_int(0));
|
||||
}
|
||||
|
||||
CollectionChangeIndices finish(size_t ndx) {
|
||||
CollectionChangeSet finish(size_t ndx) {
|
||||
m_realm->commit_transaction();
|
||||
|
||||
_impl::CollectionChangeBuilder c;
|
||||
@ -61,7 +61,7 @@ private:
|
||||
LinkViewRef m_linkview;
|
||||
std::vector<int> m_initial;
|
||||
|
||||
void validate(CollectionChangeIndices const& info)
|
||||
void validate(CollectionChangeSet const& info)
|
||||
{
|
||||
info.insertions.verify();
|
||||
info.deletions.verify();
|
||||
@ -445,7 +445,7 @@ TEST_CASE("Transaction log parsing") {
|
||||
#define VALIDATE_CHANGES(out) \
|
||||
for (CaptureHelper helper(config.path, r, lv); helper; out = helper.finish(origin->get_index_in_group()))
|
||||
|
||||
CollectionChangeIndices changes;
|
||||
CollectionChangeSet changes;
|
||||
SECTION("single change type") {
|
||||
SECTION("add single") {
|
||||
VALIDATE_CHANGES(changes) {
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
#define REQUIRE_MOVES(c, ...) do { \
|
||||
auto actual = (c); \
|
||||
std::initializer_list<CollectionChangeIndices::Move> expected = {__VA_ARGS__}; \
|
||||
std::initializer_list<CollectionChangeSet::Move> expected = {__VA_ARGS__}; \
|
||||
REQUIRE(expected.size() == actual.moves.size()); \
|
||||
auto begin = actual.moves.begin(); \
|
||||
for (auto move : expected) { \
|
||||
|
Loading…
x
Reference in New Issue
Block a user