2016-02-18 19:59:34 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright 2016 Realm Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2016-01-29 08:46:25 +00:00
|
|
|
|
|
|
|
/**
|
2016-02-09 00:41:37 +00:00
|
|
|
* Instances of this class will be returned when accessing object properties whose type is `"list"`
|
2016-01-29 08:46:25 +00:00
|
|
|
* (see {@linkplain Realm~ObjectSchemaProperty ObjectSchemaProperty}).
|
2017-09-28 00:57:41 +00:00
|
|
|
*
|
|
|
|
* Lists mostly behave like normal Javascript Arrays, except for that they can
|
|
|
|
* only store values of a single type (indicated by the `type` and `optional`
|
|
|
|
* properties of the List), and can only be modified inside a {@linkplain
|
|
|
|
* Realm#write write} transaction.
|
|
|
|
*
|
2016-03-17 21:31:29 +00:00
|
|
|
* @extends Realm.Collection
|
2018-05-16 08:46:32 +00:00
|
|
|
* @class
|
|
|
|
* @name Realm.List
|
2016-01-29 08:46:25 +00:00
|
|
|
* @memberof Realm
|
|
|
|
*/
|
2016-03-17 21:31:29 +00:00
|
|
|
class List extends Collection {
|
2016-01-29 08:46:25 +00:00
|
|
|
/**
|
2017-09-28 00:57:41 +00:00
|
|
|
* Remove the **last** value from the list and return it.
|
2016-01-29 08:46:25 +00:00
|
|
|
* @throws {Error} If not inside a write transaction.
|
2017-09-28 00:57:41 +00:00
|
|
|
* @returns {T|undefined} if the list is empty.
|
2016-01-29 08:46:25 +00:00
|
|
|
*/
|
|
|
|
pop() {}
|
|
|
|
|
|
|
|
/**
|
2017-09-28 00:57:41 +00:00
|
|
|
* Add one or more values to the _end_ of the list.
|
|
|
|
*
|
|
|
|
* @param {...T} value - Values to add to the list.
|
|
|
|
* @throws {TypeError} If a `value` is not of a type which can be stored in
|
|
|
|
* the list, or if an object being added to the list does not match the
|
|
|
|
* {@linkcode Realm~ObjectSchema object schema} for the list.
|
|
|
|
*
|
2016-01-29 08:46:25 +00:00
|
|
|
* @throws {Error} If not inside a write transaction.
|
2017-09-28 00:57:41 +00:00
|
|
|
* @returns {number} equal to the new {@link Realm.List#length length} of
|
|
|
|
* the list after adding the values.
|
2016-01-29 08:46:25 +00:00
|
|
|
*/
|
2017-09-28 00:57:41 +00:00
|
|
|
push(...value) {}
|
2016-01-29 08:46:25 +00:00
|
|
|
|
2016-03-17 21:31:29 +00:00
|
|
|
/**
|
2017-09-28 00:57:41 +00:00
|
|
|
* Remove the **first** value from the list and return it.
|
2016-03-17 21:31:29 +00:00
|
|
|
* @throws {Error} If not inside a write transaction.
|
2017-09-28 00:57:41 +00:00
|
|
|
* @returns {T|undefined} if the list is empty.
|
2016-03-17 21:31:29 +00:00
|
|
|
*/
|
|
|
|
shift() {}
|
|
|
|
|
2016-03-17 21:49:12 +00:00
|
|
|
/**
|
2017-09-28 00:57:41 +00:00
|
|
|
* Changes the contents of the list by removing value and/or inserting new value.
|
|
|
|
*
|
2016-03-17 21:49:12 +00:00
|
|
|
* @see {@linkcode https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice Array.prototype.splice}
|
|
|
|
* @param {number} index - The start index. If greater than the length of the list,
|
|
|
|
* the start index will be set to the length instead. If negative, then the start index
|
|
|
|
* will be counted from the end of the list (e.g. `list.length - index`).
|
2017-09-28 00:57:41 +00:00
|
|
|
* @param {number} [count] - The number of values to remove from the list.
|
|
|
|
* If not provided, then all values from the start index through the end of
|
|
|
|
* the list will be removed.
|
|
|
|
* @param {...T} [value] - Values to insert into the list starting at `index`.
|
|
|
|
* @returns {T[]} containing the value that were removed from the list. The
|
|
|
|
* array is empty if no value were removed.
|
2016-03-17 21:49:12 +00:00
|
|
|
*/
|
|
|
|
splice(index, count, ...object) {}
|
|
|
|
|
2016-01-29 08:46:25 +00:00
|
|
|
/**
|
2017-09-28 00:57:41 +00:00
|
|
|
* Add one or more values to the _beginning_ of the list.
|
|
|
|
*
|
|
|
|
* @param {...T} value - Values to add to the list.
|
|
|
|
* @throws {TypeError} If a `value` is not of a type which can be stored in
|
|
|
|
* the list, or if an object being added to the list does not match the
|
|
|
|
* {@linkcode Realm~ObjectSchema object schema} for the list.
|
2016-01-29 08:46:25 +00:00
|
|
|
* @throws {Error} If not inside a write transaction.
|
2017-09-28 00:57:41 +00:00
|
|
|
* @returns {number} equal to the new {@link Realm.List#length length} of
|
|
|
|
* the list after adding the values.
|
2016-01-29 08:46:25 +00:00
|
|
|
*/
|
|
|
|
unshift(...object) {}
|
2017-09-28 00:57:41 +00:00
|
|
|
}
|