From 3fb20537b5f3409c57f919ff01e8f3a2f09ca1b9 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Tue, 6 Dec 2016 17:42:15 +0100 Subject: [PATCH] update notifier docs --- docs/conf.json | 2 +- docs/sync.js | 72 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 61 insertions(+), 13 deletions(-) diff --git a/docs/conf.json b/docs/conf.json index 4da9afa0..5551074d 100644 --- a/docs/conf.json +++ b/docs/conf.json @@ -7,7 +7,7 @@ }, "source": { "include": ["docs"], - "exclude": ["docs/jsdoc-template", "docs/output", "docs/sync.js"] + "exclude": ["docs/jsdoc-template", "docs/output"] }, "tags": { "allowUnknownTags": false diff --git a/docs/sync.js b/docs/sync.js index 0bb9d9be..52e28764 100644 --- a/docs/sync.js +++ b/docs/sync.js @@ -20,21 +20,28 @@ * @memberof Realm */ class Sync { + /** + * Add a sync listener to listen to changes across multiple Realms + * @param {string} server_url - the sync server to listen to + * @param {SyncUser} admin_user - an admin user obtained by calling `new Realm.Sync.User.adminUser` + * @param {string} regex - a regular expression used to determine which cahnged Realms should trigger events - + * Use `.*` to match all all Realms + * @param {function(change_object)} change_callback - called on when changes are made to any Realm which + * match the given regular expression + */ + static addListener(server_url, admin_user, regex, change_callback) {} /** - * Set a global listener function. - * @param {string} local_path - The path to the directory where realm files are stored [deprecated] - * @param {string} server_url - The sync server to listen to - * @param {SyncUser} admin_user - An admin user obtained by calling `new Realm.Sync.User.Admin` - * @param {function(realm_name)} filter_callback - Return true to recieve changes for the given realm - * @param {function(realm_name, realm, change_set)} change_callback - called on any realm changes with - * the following arguments: - * - `realm_name` - path of the Realm on which changes occurred - * - `realm` - a `Realm` object for the changed Realm - * - `change_set` - a dictionary of object names to arays of indexes indicating the indexes of objects of each type - * which have been added, removed, or modified + * Remove a previously registered sync listener + * @param {string} regex - the regular expression previously used to register the listener + * @param {function(change_object)} change_callback - the previously registered callback to be removed */ - static setGlobalListener(local_path, server_url, admin_user, filter_callback, change_callback) {} + static removeListener(regex, change_callback) {} + + /** + * Remove all previously regiestered listeners + */ + static removeAllListeners() {} /** * Set the sync log level. @@ -44,6 +51,47 @@ class Sync { } +/** + * Object passed + * @memberof Realm.Sync + */ +class ChangeObject { + /** + * The path of the changed Realm + * @type {string} + */ + get path() {} + + /** + * The changed realm + * @type {Realm} + */ + get realm() {} + + /** + * The changed Realm at the old state before the changes were applied + * @type {Realm} + */ + get oldRealm() {} + + /** + * The change indexes for all added, removed, and modified objects in the changed Realm. + * This object is a hashmap of object types to arrays of indexes for all changed objects: + * @example + * { + * object_type_1: { + * insertions: [indexes...], + * deletions: [indexes...], + * modifications: [indexes...] + * }, + * object_type_2: + * ... + * } + * @type {object} + */ + get changes() {} +} + /** * @typedef Realm.Sync~LogLevel * @type {("error"|"info"|"debug")}