Update API docs with sorted/filtered changes

This commit is contained in:
Scott Kyle 2016-02-19 01:44:52 -08:00
parent ba0ff5fbaf
commit c1e5cb03cf
4 changed files with 65 additions and 26 deletions

@ -1 +1 @@
Subproject commit f21b8a34130c287429ba1e8f120e3645b45766c8 Subproject commit 951723451f8ff082d657135486b6fb30de8c2a26

View File

@ -18,6 +18,30 @@ class List {
*/ */
get length() {} get length() {}
/**
* Returns new results that represent this list being filtered by the provided query.
* ```js
* let merlots = wines.filtered('varietal == "Merlot" && vintage <= $0', maxYear);
* ```
* @param {string} query - Query used to filter results.
* @param {...any} [arg] - Each subsequent argument is used by the placeholders
* (e.g. `$0`, `$1`, `$2`, ) in the query.
* @throws {Error} If the query or any other argument passed into this method is invalid.
* @returns {Realm.Results} filtered according to the provided query.
*/
filtered(query, ...arg) {}
/**
* Returns new results that represent this list being sorted by the provided property
* (or properties) of each object.
* @param {string|Realm.Results~SortDescriptor[]} descriptor - The property name(s) to sort
* results by.
* @param {boolean} [reverse=false] - May only be provided if `descriptor` is a string.
* @throws {Error} If a specified property does not exist.
* @returns {Realm.Results} sorted according to the arguments passed in
*/
sorted(descriptor, reverse) {}
/** /**
* Create a frozen snapshot of the list. This means changes to the list will not be * Create a frozen snapshot of the list. This means changes to the list will not be
* reflected in the results returned by this method. However, deleted objects will become * reflected in the results returned by this method. However, deleted objects will become

View File

@ -46,18 +46,11 @@ class Realm {
deleteAll() {} deleteAll() {}
/** /**
* Returns all objects of the given `type` in the Realm, optionally filtered by the provided * Returns all objects of the given `type` in the Realm.
* `query`.
* ```js
* let merlots = realm.objects('Wine', 'varietal == "Merlot" && vintage <= $0', maxYear);
* ```
* @param {string} type - The type of object as specified by its `name` in the * @param {string} type - The type of object as specified by its `name` in the
* {@link Realm~ObjectSchema ObjectSchema} definition. * {@link Realm~ObjectSchema ObjectSchema} definition.
* @param {string} [query] - Query used to filter results. * @throws {Error} If type passed into this method is invalid.
* @param {...any} [arg] - Each subsequent argument is used by the placeholders * @returns {Realm.Results} that will live-update as objects are created and destroyed.
* (e.g. `$0`, `$1`, `$2`, ) in the query.
* @throws {Error} If type, query, or any other argument passed into this method is invalid.
* @returns {Realm.Results}
*/ */
objects(type, query, ...arg) {} objects(type, query, ...arg) {}

View File

@ -11,26 +11,48 @@
* @memberof Realm * @memberof Realm
*/ */
class Results { class Results {
/** /**
* The number of objects in the results. * The number of objects in the results.
* @type {number} * @type {number}
* @readonly * @readonly
*/ */
get length() {} get length() {}
/** /**
* Create a frozen snapshot of the list. This means changes to the list will not be * Returns new results that are filtered by the provided query.
* ```js
* let merlots = wines.filtered('varietal == "Merlot" && vintage <= $0', maxYear);
* ```
* @param {string} query - Query used to filter results.
* @param {...any} [arg] - Each subsequent argument is used by the placeholders
* (e.g. `$0`, `$1`, `$2`, ) in the query.
* @throws {Error} If the query or any other argument passed into this method is invalid.
* @returns {Realm.Results} filtered according to the provided query.
*/
filtered(query, ...arg) {}
/**
* Returns new results that are sorted by the provided property (or properties) of each object.
* @param {string|Realm.Results~SortDescriptor[]} descriptor - The property name(s) to sort
* results by.
* @param {boolean} [reverse=false] - May only be provided if `descriptor` is a string.
* @throws {Error} If a specified property does not exist.
* @returns {Realm.Results} sorted according to the arguments passed in
*/
sorted(descriptor, reverse) {}
/**
* Create a frozen snapshot of the results. This means changes to the list will not be
* reflected in the results returned by this method. However, deleted objects will become * reflected in the results returned by this method. However, deleted objects will become
* `null` at their respective indices. * `null` at their respective indices.
* @returns {Realm.Results} which will **not** live update. * @returns {Realm.Results} which will **not** live update.
*/ */
snapshot() {} snapshot() {}
/**
* Modifies this collection to be sorted by the provided property of each object.
* @param {string} name - The property name to sort results by.
* @param {boolean} [ascending=true]
* @throws {Error} If the specified property does not exist.
*/
sortByProperty(name, ascending) {}
} }
/**
* The sort descriptors may either just be a string representing the property name, **or** an
* array with two items: `[propertyName, reverse]`
* @typedef Realm.Results~SortDescriptor
* @type {string|Array}
*/