# Class CopyOnWriteCollection<T>

A collection that represents a copy of an existing collection. For efficiency, the collection will just shadow the original collection until a modification is about to be made, at which point it will actually create a copy of the original.

#### Type Parameters

- T

#### Hierarchy (view full)

- CollectionProxy<T>
  - CopyOnWriteCollection

#####
Index

### Constructors

constructor

### Accessors

_collection
declaredClass
destroyed
initialized
isModified
length
originalCollection

### Methods

_get
_set
[iterator]
add
addHandles
addMany
at
clone
concat
destroy
every
filter
find
findIndex
flatten
forEach
get
getItemAt
hasHandles
includes
indexOf
join
lastIndexOf
map
notifyChange
on
pop
push
reduce
reduceRight
remove
removeAll
removeAt
removeHandles
removeMany
reorder
reset
reverse
set
shift
slice
some
sort
splice
toArray
unshift
watch

##
Constructors

### constructor

- new CopyOnWriteCollection<T>(collection): CopyOnWriteCollection<T>

- #### Type Parameters

  - T

  #### Parameters

  - collection: Collection<T>

  #### Returns CopyOnWriteCollection<T>

  Overrides CollectionProxy.constructor

##
Accessors

### `Protected`_collection

- get _collection(): Collection<T>

- The underlying collection that this class delegates to.

  #### Returns Collection<T>

  Inherited from CollectionProxy._collection

- set _collection(collection): void

- #### Parameters

  - collection: Collection<T>

  #### Returns void

  Inherited from CollectionProxy._collection

### declaredClass

- get declaredClass(): string

- The declared class name. This is always `"esri.core.Collection"` for compatibility with Esri's API.

  #### Returns string

  Inherited from CollectionProxy.declaredClass

### destroyed

- get destroyed(): boolean

- Whether the collection has been destroyed.

  #### Returns boolean

  Inherited from CollectionProxy.destroyed

- set destroyed(value): void

- #### Parameters

  - value: boolean

  #### Returns void

  Inherited from CollectionProxy.destroyed

### initialized

- get initialized(): boolean

- Whether the collection has been initialized.

  #### Returns boolean

  Inherited from CollectionProxy.initialized

- set initialized(value): void

- #### Parameters

  - value: boolean

  #### Returns void

  Inherited from CollectionProxy.initialized

### isModified

- get isModified(): boolean

- Determines whether the collection has been modified.

  #### Returns boolean

### length

- get length(): number

- The number of items in the collection.

  #### Returns number

  Inherited from CollectionProxy.length

### originalCollection

- get originalCollection(): Collection<T>

- The original collection that this collection is a copy of.

  #### Returns Collection<T>

- set originalCollection(value): void

- #### Parameters

  - value: Collection<T>

  #### Returns void

##
Methods

### `Protected`_get

- _get(propertyName): any

- #### Parameters

  - propertyName: string

  #### Returns any

  #### Deprecated

  - Unsupported on CollectionProxy.

  #### Inherit Doc

  Inherited from CollectionProxy._get

- _get<T>(propertyName): T

- #### Type Parameters

  - T

  #### Parameters

  - propertyName: string

  #### Returns T

  Inherited from CollectionProxy._get

### `Protected`_set

- _set<T>(propertyName, value): this

- #### Type Parameters

  - T

  #### Parameters

  - propertyName: string
  - value: T

  #### Returns this

  #### Deprecated

  - Unsupported on CollectionProxy.

  #### Inherit Doc

  Inherited from CollectionProxy._set

### [iterator]

- [iterator](): IterableIterator<T, any, any>

- #### Returns IterableIterator<T, any, any>

  #### Inherit Doc

  Inherited from CollectionProxy.[iterator]

### add

- add(item, index?): this

- Adds a single item to the collection.

  #### Parameters

  - item: T

    The item to add.

  - `Optional` index: number

    Zero-based index of where in the collection to add the item. If not specified, the items will be added at the end.

  #### Returns this

  Overrides CollectionProxy.add

### addHandles

- addHandles<T>(handles, groupKey?): void

- #### Type Parameters

  - T

  #### Parameters

  - handles: IHandle | IHandle[]
  - `Optional` groupKey: Exclude<T, IHandle>

  #### Returns void

  Inherited from CollectionProxy.addHandles

### addMany

- addMany(items, index?): this

- Adds multiple items to the collection.

  #### Parameters

  - items: Collection<T> | ArrayLike<T>

    An array or collection of items to add.

  - `Optional` index: number

    Zero-based index of where in the collection to add the items. If not specified, the items will be added at the end.

  #### Returns this

  Inherited from CollectionProxy.addMany

### at

- at(index): T

- Returns the item at the specified index.

  #### Parameters

  - index: number

    Zero-based index of the item in the Collection to retrieve.

  #### Returns T

  The item in the Collection stored at the specified index.

  Inherited from CollectionProxy.at

### clone

- clone(): CopyOnWriteCollection<T>

- Creates a deep clone of the Collection. To create a shallow clone of the collection, use slice().

  #### Returns CopyOnWriteCollection<T>

  Overrides CollectionProxy.clone

### concat

- concat(value): Collection<T>

- Creates a new Collection containing the items in the original Collection joined with the items in the input array or Collection.

  #### Parameters

  - value: Collection<T> | T[]

    The array or Collection to append to the existing Collection.

  #### Returns Collection<T>

  Inherited from CollectionProxy.concat

### destroy

- destroy(): void

- Removes all event listeners and destroys the collection.

  #### Returns void

  Inherited from CollectionProxy.destroy

### every

- every(callback): boolean

- Determines whether all items in the Collection pass a test defined by callback. Each item in the Collection is passed into the callback until one returns a value of false.

  #### Parameters

  - callback: ItemTestCallback<T>

    The function to call for each item in the Collection.

  #### Returns boolean

  Inherited from CollectionProxy.every

### filter

- filter(callback): Collection<T>

- Filters the Collection's items based on a test defined by the callback function. Each item is passed into the callback function, which returns true if the item passes the test and false if it does not.

  #### Parameters

  - callback: ItemTestCallback<T>

    The function that defines a test for determining whether to return the item in a new Collection.

  #### Returns Collection<T>

  Inherited from CollectionProxy.filter

### find

- find(callback): T

- Returns an item in the Collection if that item passes a test as defined in the callback function. Each item is passed into the callback function, which returns true if the item passes the test and false if it does not.

  #### Parameters

  - callback: ItemTestCallback<T>

    The testing function that will assess each item in the Collection. Returns true if an item passes the test and false if it fails.

  #### Returns T

  Inherited from CollectionProxy.find

### findIndex

- findIndex(callback): number

- Returns the index of an item in the Collection if that item passes a test as defined in the callback function. Each item is passed into the callback function, which returns true if the item passes the test and false if it does not.

  #### Parameters

  - callback: ItemTestCallback<T>

    The testing function that will assess each item in the Collection. Returns true if an item passes the test and false if it fails.

  #### Returns number

  Returns the index of the Collection item that satisfies the test function. If an item fails the test, -1 is returned.

  Inherited from CollectionProxy.findIndex

### flatten

- flatten(callback): Collection<T>

- Flattens a hierarchical Collection containing at least one child collection. Each item in the collection is passed into the callback function, which should check for child collections specified by the developer. A flat collection of all items (parent and children) is returned.

  #### Parameters

  - callback: ((item: T, index: number) => Collection<T> | T[])

    A function that will assess each item in the Collection.

    - - (item, index): Collection<T> | T[]

      - #### Parameters

        - item: T
        - index: number

        #### Returns Collection<T> | T[]

  #### Returns Collection<T>

  Inherited from CollectionProxy.flatten

### forEach

- forEach(callback): void

- Executes the input function for each item in the Collection.

  #### Parameters

  - callback: ItemCallback<T>

    The function to call for each item in the Collection.

  #### Returns void

  Inherited from CollectionProxy.forEach

### get

- get<T>(propertyPath): T

- #### Type Parameters

  - T

  #### Parameters

  - propertyPath: string

  #### Returns T

  #### Deprecated

  - Unsupported on CollectionProxy.

  #### Inherit Doc

  Inherited from CollectionProxy.get

- get(propertyPath): unknown

- #### Parameters

  - propertyPath: string

  #### Returns unknown

  #### Deprecated

  - Unsupported on CollectionProxy.

  #### Inherit Doc

  Inherited from CollectionProxy.get

### getItemAt

- getItemAt(index): T

- Returns the item at the specified index.

  #### Parameters

  - index: number

    Zero-based index of the item in the Collection to retrieve.

  #### Returns T

  The item in the Collection stored at the specified index.

  Inherited from CollectionProxy.getItemAt

### hasHandles

- hasHandles<T>(groupKey?): boolean

- #### Type Parameters

  - T

  #### Parameters

  - `Optional` groupKey: Exclude<T, IHandle>

  #### Returns boolean

  Inherited from CollectionProxy.hasHandles

### includes

- includes(searchElement): boolean

- Tests if an item is present in the Collection.

  #### Parameters

  - searchElement: T

    The item to search for in the collection.

  #### Returns boolean

  Inherited from CollectionProxy.includes

### indexOf

- indexOf(searchElement, fromIndex?): number

- Returns the index of an element in the collection.

  #### Parameters

  - searchElement: T

    Item to search for in the collection.

  - `Optional` fromIndex: number

    Use if you don't want to search the whole collection or you don't want to search from the start.

  #### Returns number

  Inherited from CollectionProxy.indexOf

### join

- join(separator?): string

- Creates a string representation of the items in the Collection.

  #### Parameters

  - `Optional` separator: string

    The separator used between each item in the final string. The default is ",".

  #### Returns string

  Inherited from CollectionProxy.join

### lastIndexOf

- lastIndexOf(searchElement, fromIndex?): number

- Returns the last index of an element in the collection.

  #### Parameters

  - searchElement: T

    Item to search for in the collection.

  - `Optional` fromIndex: number

    Use if you don't want to search the whole collection, or you don't want to search from the end.

  #### Returns number

  The location of the last match found in the collection, or -1 if there is no match.

  Inherited from CollectionProxy.lastIndexOf

### map

- map<U>(callback): Collection<U>

- Passes each Collection item into the callback function and returns a new array of the returned values.

  #### Type Parameters

  - U

  #### Parameters

  - callback: ItemMapCallback<T, U>

    The function that processes each item in the Collection and returns a new value at the same index of the original item.

  #### Returns Collection<U>

  Inherited from CollectionProxy.map

### `Protected` notifyChange

- notifyChange(propertyKey): void

- #### Parameters

  - propertyKey: string

  #### Returns void

  #### Deprecated

  - Unsupported on CollectionProxy.

  #### Inherit Doc

  Inherited from CollectionProxy.notifyChange

- notifyChange(propertyKey): void

- #### Parameters

  - propertyKey: keyof CopyOnWriteCollection<T>

  #### Returns void

  Inherited from CollectionProxy.notifyChange

### on

- on(type, listener): IHandle

- #### Parameters

  - type: "after-add"
  - listener: CollectionAfterAddEventHandler<T>

  #### Returns IHandle

  #### Inherit Doc

  Inherited from CollectionProxy.on

- on(type, listener): IHandle

- #### Parameters

  - type: "after-changes"
  - listener: CollectionAfterChangesEventHandler

  #### Returns IHandle

  Inherited from CollectionProxy.on

- on(type, listener): IHandle

- #### Parameters

  - type: "after-remove"
  - listener: CollectionAfterRemoveEventHandler<T>

  #### Returns IHandle

  Inherited from CollectionProxy.on

- on(type, listener): IHandle

- #### Parameters

  - type: "before-add"
  - listener: CollectionBeforeAddEventHandler<T>

  #### Returns IHandle

  Inherited from CollectionProxy.on

- on(type, listener): IHandle

- #### Parameters

  - type: "before-changes"
  - listener: CollectionBeforeChangesEventHandler

  #### Returns IHandle

  Inherited from CollectionProxy.on

- on(type, listener): IHandle

- #### Parameters

  - type: "before-remove"
  - listener: CollectionBeforeRemoveEventHandler<T>

  #### Returns IHandle

  Inherited from CollectionProxy.on

- on(type, listener): IHandle

- #### Parameters

  - type: "change"
  - listener: CollectionChangeEventHandler<T>

  #### Returns IHandle

  Inherited from CollectionProxy.on

- on(type, listener): IHandle

- #### Parameters

  - type: string
  - listener: EventHandler

  #### Returns IHandle

  Inherited from CollectionProxy.on

### pop

- pop(): T

- Removes the last item from the collection and returns it.

  #### Returns T

  Inherited from CollectionProxy.pop

### push

- push(item): number

- Adds an item to the end of the collection.

  #### Parameters

  - item: T

    The item to add.

  #### Returns number

  Inherited from CollectionProxy.push

### reduce

- reduce<U>(callback, initialValue?): U

- Reduces all items in the collection (from left to right) into a single variable using callback.

  #### Type Parameters

  - U

  #### Parameters

  - callback: ItemReduceCallback<T, U>

    The function that processes each item in the Collection and appends it to the previous item.

  - `Optional` initialValue: U

    Item to use as the first element to process in callback.

  #### Returns U

  Inherited from CollectionProxy.reduce

### reduceRight

- reduceRight<U>(callback, initialValue?): U

- Reduces all items in the collection (from right to left) into a single variable using callback.

  #### Type Parameters

  - U

  #### Parameters

  - callback: ItemReduceCallback<T, U>

    The function that processes each item in the Collection and appends it to the previous item.

  - `Optional` initialValue: U

    Item to use as the first element to process in callback.

  #### Returns U

  Inherited from CollectionProxy.reduceRight

### remove

- remove(item): T

- Removes an item from the collection.

  #### Parameters

  - item: T

    The item to remove.

  #### Returns T

  Inherited from CollectionProxy.remove

### removeAll

- removeAll(): T[]

- Removes all items from the collection.

  #### Returns T[]

  Inherited from CollectionProxy.removeAll

### removeAt

- removeAt(index): T

- Removes an item from the collection at a specified index.

  #### Parameters

  - index: number

    The index of the element to remove.

  #### Returns T

  Overrides CollectionProxy.removeAt

### removeHandles

- removeHandles<T>(groupKey?): void

- #### Type Parameters

  - T

  #### Parameters

  - `Optional` groupKey: Exclude<T, IHandle>

  #### Returns void

  Inherited from CollectionProxy.removeHandles

### removeMany

- removeMany(items): T[]

- Removes each item in the input array. If an item is present multiple times in the collection, only the first occurrence is removed.

  #### Parameters

  - items: Collection<T> | ArrayLike<T>

    The items to remove.

  #### Returns T[]

  Inherited from CollectionProxy.removeMany

### reorder

- reorder(item, index): T

- Moves an item in the Collection to a specified index. The change event is fired after an item is moved in the Collection.

  #### Parameters

  - item: T

    The item to move.

  - index: number

    The index to move the item to.

  #### Returns T

  Overrides CollectionProxy.reorder

### reset

- reset(): void

- Undoes all local modifications and resets the collection to the original.

  #### Returns void

### reverse

- reverse(): this

- Reverses the collection in place.

  #### Returns this

  Inherited from CollectionProxy.reverse

### set

- set<T>(propertyPath, value): this

- #### Type Parameters

  - T

  #### Parameters

  - propertyPath: string
  - value: T

  #### Returns this

  #### Deprecated

  - Unsupported on CollectionProxy.

  #### Inherit Doc

  Inherited from CollectionProxy.set

- set(properties): this

- #### Parameters

  - properties: HashMap<unknown>

  #### Returns this

  #### Deprecated

  - Unsupported on CollectionProxy.

  #### Inherit Doc

  Inherited from CollectionProxy.set

### shift

- shift(): T

- Removes the first item from the collection (at index 0), and returns it. The remaining items of the collection are then shifted down one index from their previous location.

  #### Returns T

  Inherited from CollectionProxy.shift

### slice

- slice(begin?, end?): Collection<T>

- Creates a new Collection comprised of a portion of the original Collection.

  #### Parameters

  - `Optional` begin: number

    The index of the first item to extract.

  - `Optional` end: number

    The index of the last item to extract.

  #### Returns Collection<T>

  Inherited from CollectionProxy.slice

### some

- some(callback): boolean

- Determines whether an item in the Collection passes a test defined by callback. Each item in the Collection is passed into the callback until one returns a value of true.

  #### Parameters

  - callback: ItemTestCallback<T>

    The function that defines the test for each Collection item.

  #### Returns boolean

  Inherited from CollectionProxy.some

### sort

- sort(compareFunction?): this

- Sorts the Collection in place.

  #### Parameters

  - `Optional` compareFunction: ((a: T, b: T) => number)

    The function that defines a comparison of two items in the collection.

    - - (a, b): number

      - #### Parameters

        - a: T
        - b: T

        #### Returns number

  #### Returns this

  Overrides CollectionProxy.sort

### splice

- splice(start, deleteCount, ...items): T[]

- Removes existing items and/or adds new items to the collection.

  #### Parameters

  - start: number

    Index at which to start changing the collection.

  - deleteCount: number

    Indicates the number of collection items to remove. If 0 is used then no elements are removed and at least one new item should be added in the items parameter.

  - `Rest`...items: T[]

    The item or comma-separated list of items to add to the collection.

  #### Returns T[]

  An array of the deleted items formerly part of the collection.

  Inherited from CollectionProxy.splice

### toArray

- toArray(): T[]

- Returns a new array object containing the Collection's items.

  #### Returns T[]

  Inherited from CollectionProxy.toArray

### unshift

- unshift(item): number

- Adds an item to the beginning of the collection.

  #### Parameters

  - item: T

    The item to add.

  #### Returns number

  Inherited from CollectionProxy.unshift

### watch

- watch(path, callback, sync?): IHandle

- #### Parameters

  - path: string | string[]
  - callback: ((newValue: any, oldValue: any, propertyName: string, target: any) => void)
    - - (newValue, oldValue, propertyName, target): void

      - #### Parameters

        - newValue: any
        - oldValue: any
        - propertyName: string
        - target: any

        #### Returns void

  - `Optional` sync: boolean

  #### Returns IHandle

  #### Deprecated

  - Unsupported on CollectionProxy.

  #### Inherit Doc

  Inherited from CollectionProxy.watch