Merge pull request #271 from realm/sk-docs-update

Update API docs with sorted/filtered changes
This commit is contained in:
Scott Kyle 2016-02-21 19:03:49 -08:00
commit 89ce54799f
4 changed files with 65 additions and 26 deletions

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

View File

@ -32,6 +32,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

@ -60,18 +60,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

@ -33,18 +33,40 @@ class Results {
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. * The sort descriptors may either just be a string representing the property name, **or** an
* @param {string} name - The property name to sort results by. * array with two items: `[propertyName, reverse]`
* @param {boolean} [ascending=true] * @typedef Realm.Results~SortDescriptor
* @throws {Error} If the specified property does not exist. * @type {string|Array}
*/ */
sortByProperty(name, ascending) {}
}