mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-12 15:24:18 +00:00
Merge branch 'master' of github.com:realm/realm-js into kneth/update-sync-3.0.0
This commit is contained in:
commit
480b2cfdee
@ -18,8 +18,8 @@ Please see the detailed instructions in our docs to use [Realm Javascript](https
|
|||||||
|
|
||||||
### Realm React Native and Node.js
|
### Realm React Native and Node.js
|
||||||
|
|
||||||
The documentation can be found at [realm.io/docs/javascript/latest](https://realm.io/docs/javascript/latest).
|
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 API reference is located at [realm.io/docs/javscript/latest/api/](https://realm.io/docs/javascript/latest/api/).
|
||||||
|
|
||||||
## Getting Help
|
## Getting Help
|
||||||
|
|
||||||
|
2
lib/index.d.ts
vendored
2
lib/index.d.ts
vendored
@ -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) => void): void;
|
||||||
function addListener(serverURL: string, adminUser: Realm.Sync.User, regex: string, name: string, changeCallback: (changeEvent: ChangeEvent) => Promise<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 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 setLogLevel(logLevel: 'all' | 'trace' | 'debug' | 'detail' | 'info' | 'warn' | 'error' | 'fatal' | 'off'): void;
|
||||||
function initiateClientReset(path: string): void;
|
function initiateClientReset(path: string): void;
|
||||||
function setFeatureToken(token: string): void;
|
function setFeatureToken(token: string): void;
|
||||||
|
@ -34,10 +34,11 @@ class FunctionListener {
|
|||||||
this.event = event;
|
this.event = event;
|
||||||
this.fn = fn;
|
this.fn = fn;
|
||||||
this.seen = {};
|
this.seen = {};
|
||||||
|
this.pending = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
return Promise.resolve();
|
return Promise.all(this.pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
matches(regex, event, fn) {
|
matches(regex, event, fn) {
|
||||||
@ -64,7 +65,12 @@ class FunctionListener {
|
|||||||
changes.release();
|
changes.release();
|
||||||
return;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let refCount = this.callbacks.length;
|
let refCount = 1;
|
||||||
changes.release = () => {
|
changes.release = () => {
|
||||||
if (--refCount === 0) {
|
if (--refCount === 0) {
|
||||||
changes.close();
|
changes.close();
|
||||||
@ -136,8 +142,10 @@ class Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const callback of this.callbacks) {
|
for (const callback of this.callbacks) {
|
||||||
|
++refCount;
|
||||||
callback.onchange(changes);
|
callback.onchange(changes);
|
||||||
}
|
}
|
||||||
|
changes.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
available(virtualPath) {
|
available(virtualPath) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user