Change order of Connection notification parameters (#1961)

This commit is contained in:
Christian Melchior 2018-08-15 15:52:37 +02:00 committed by GitHub
parent 81dd5931d5
commit adf6bb58c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 9 deletions

View File

@ -597,8 +597,12 @@ class Session {
removeProgressNotification(progressCallback) {}
/**
* Registers a connection notification on the session object. This will be notified about changes to the
* underlying connection to the Realm Object Server.
*
* @param connectionCallback
* @param {callback(newState, oldState)} callback - called with the following arguments:
* - `newState` - the new state of the connection
* - `oldState` - the state the connection transitioned from.
*/
addConnectionNotification(connectionCallback) {}

2
lib/index.d.ts vendored
View File

@ -440,7 +440,7 @@ declare namespace Realm.Sync {
type ProgressDirection = 'download' | 'upload';
type ProgressMode = 'reportIndefinitely' | 'forCurrentlyOutstandingWork';
type ConnectionNotificationCallback = (oldState: ConnectionState, newState: ConnectionState) => void;
type ConnectionNotificationCallback = (newState: ConnectionState, oldState: ConnectionState) => void;
/**
* Session

View File

@ -214,7 +214,7 @@ public:
std::string const name = "Session";
using ProgressHandler = void(uint64_t transferred_bytes, uint64_t transferrable_bytes);
using StateHandler = void(SyncSession::PublicState old_state, SyncSession::PublicState new_state);
using ConnectionHandler = void(SyncSession::ConnectionState old_state, SyncSession::ConnectionState new_state);
using ConnectionHandler = void(SyncSession::ConnectionState new_state, SyncSession::ConnectionState old_state);
static FunctionType create_constructor(ContextType);
@ -600,8 +600,8 @@ void SessionClass<T>::add_connection_notification(ContextType ctx, FunctionType,
EventLoopDispatcher<ConnectionHandler> connection_handler([=](SyncSession::ConnectionState old_state, SyncSession::ConnectionState new_state) {
HANDLESCOPE
ValueType callback_arguments[2];
callback_arguments[0] = Value::from_string(protected_ctx, get_connection_state_value(old_state));
callback_arguments[1] = Value::from_string(protected_ctx, get_connection_state_value(new_state));
callback_arguments[0] = Value::from_string(protected_ctx, get_connection_state_value(new_state));
callback_arguments[1] = Value::from_string(protected_ctx, get_connection_state_value(old_state));
Function<T>::callback(protected_ctx, protected_callback, typename T::Object(), 2, callback_arguments);
});

View File

@ -945,7 +945,7 @@ module.exports = {
};
Realm.open(config).then(realm => {
realm.syncSession.addConnectionNotification((oldState, newState) => {
realm.syncSession.addConnectionNotification((newState, oldState) => {
if (oldState === Realm.Sync.ConnectionState.Connected && newState === Realm.Sync.ConnectionState.Disconnected) {
resolve('Done');
}
@ -972,10 +972,10 @@ module.exports = {
};
Realm.open(config).then(realm => {
let callback1 = (oldState, newState) => {
let callback1 = () => {
reject("Should not be called");
};
let callback2 = (oldState, newState) => {
let callback2 = (newState, oldState) => {
if (oldState === Realm.Sync.ConnectionState.Connected && newState === Realm.Sync.ConnectionState.Disconnected) {
resolve('Done');
}
@ -1009,7 +1009,7 @@ module.exports = {
let session = realm.syncSession;
TestCase.assertEqual(session.connectionState, Realm.Sync.ConnectionState.Disconnected);
TestCase.assertFalse(session.isConnected());
session.addConnectionNotification((oldState, newState) => {
session.addConnectionNotification((newState, oldState) => {
switch (newState) {
case Realm.Sync.ConnectionState.Disconnected:
TestCase.assertEqual(session.connectionState, Realm.Sync.ConnectionState.Disconnected);