| 41 | * Advanced array like class used when you want to be notified when a change occurs. |
| 42 | */ |
| 43 | export class ObservableArray<T> extends Observable { |
| 44 | /** |
| 45 | * String value used when hooking to change event. |
| 46 | */ |
| 47 | public static changeEvent = CHANGE; |
| 48 | |
| 49 | private _array: Array<T>; |
| 50 | private _addArgs: ChangedData<T>; |
| 51 | private _deleteArgs: ChangedData<T>; |
| 52 | |
| 53 | /** |
| 54 | * Create ObservableArray<T> with specified length. |
| 55 | */ |
| 56 | constructor(arrayLength?: number); |
| 57 | |
| 58 | /** |
| 59 | * Create ObservableArray<T> from source Array<T>. |
| 60 | */ |
| 61 | constructor(items: T[]); |
| 62 | |
| 63 | /** |
| 64 | * Create ObservableArray<T> from T items. |
| 65 | */ |
| 66 | constructor(...items: T[]); |
| 67 | |
| 68 | constructor(_args?: any) { |
| 69 | super(); |
| 70 | |
| 71 | if (arguments.length === 1 && Array.isArray(arguments[0])) { |
| 72 | this._array = arguments[0].slice(); |
| 73 | } else { |
| 74 | // eslint-disable-next-line prefer-spread |
| 75 | this._array = Array.apply(null, arguments); |
| 76 | } |
| 77 | |
| 78 | this._addArgs = { |
| 79 | eventName: CHANGE, |
| 80 | object: this, |
| 81 | action: ChangeType.Add, |
| 82 | index: null, |
| 83 | removed: [], |
| 84 | addedCount: 1, |
| 85 | }; |
| 86 | |
| 87 | this._deleteArgs = { |
| 88 | eventName: CHANGE, |
| 89 | object: this, |
| 90 | action: ChangeType.Delete, |
| 91 | index: null, |
| 92 | removed: null, |
| 93 | addedCount: 0, |
| 94 | }; |
| 95 | } |
| 96 | |
| 97 | *[Symbol.iterator]() { |
| 98 | for (const item of this._array) { |
| 99 | yield item; |
| 100 | } |
nothing calls this directly
no outgoing calls
no test coverage detected