Merge branch 'master' of github.com:realm/realm-js into kneth/update-sync-3.0.0

This commit is contained in:
Kenneth Geisshirt 2018-02-01 15:33:11 +01:00
commit 480b2cfdee
3 changed files with 14 additions and 6 deletions

View File

@ -18,8 +18,8 @@ Please see the detailed instructions in our docs to use [Realm Javascript](https
### Realm React Native and Node.js
The documentation can be found at [realm.io/docs/javascript/latest](https://realm.io/docs/javascript/latest).
The API reference is located at [realm.io/docs/javscript/latest/api](https://realm.io/docs/javascript/latest/api).
The documentation can be found at [realm.io/docs/javascript/latest/](https://realm.io/docs/javascript/latest/).
The API reference is located at [realm.io/docs/javscript/latest/api/](https://realm.io/docs/javascript/latest/api/).
## Getting Help

2
lib/index.d.ts vendored
View File

@ -417,7 +417,7 @@ declare namespace Realm.Sync {
function addListener(serverURL: string, adminUser: Realm.Sync.User, regex: string, name: string, changeCallback: (changeEvent: ChangeEvent) => void): void;
function addListener(serverURL: string, adminUser: Realm.Sync.User, regex: string, name: string, changeCallback: (changeEvent: ChangeEvent) => Promise<void>): void;
function removeAllListeners(): Promise<void>;
function removeListener(regex: string, name: string, changeCallback: (changeEvent: ChangeEvent) => void): void;
function removeListener(regex: string, name: string, changeCallback: (changeEvent: ChangeEvent) => void): Promise<void>;
function setLogLevel(logLevel: 'all' | 'trace' | 'debug' | 'detail' | 'info' | 'warn' | 'error' | 'fatal' | 'off'): void;
function initiateClientReset(path: string): void;
function setFeatureToken(token: string): void;

View File

@ -34,10 +34,11 @@ class FunctionListener {
this.event = event;
this.fn = fn;
this.seen = {};
this.pending = [];
}
stop() {
return Promise.resolve();
return Promise.all(this.pending);
}
matches(regex, event, fn) {
@ -64,7 +65,12 @@ class FunctionListener {
changes.release();
return;
}
Promise.resolve(this.fn(changes)).then(() => changes.release());
const promise = Promise.resolve(this.fn(changes));
this.pending.push(promise);
promise.then(() => {
changes.release();
this.pending.splice(this.pending.indexOf(promise), 1);
});
}
};
@ -128,7 +134,7 @@ class Listener {
return;
}
let refCount = this.callbacks.length;
let refCount = 1;
changes.release = () => {
if (--refCount === 0) {
changes.close();
@ -136,8 +142,10 @@ class Listener {
}
for (const callback of this.callbacks) {
++refCount;
callback.onchange(changes);
}
changes.release();
}
available(virtualPath) {