Skip to content

Commit fc239ab

Browse files
Merge pull request #678 from lovetostrike/icollection-observer-splice-interface-doc
fix(doc): ICollectionObserverSplice Typescript interface
2 parents 47ea3c2 + b4f7b28 commit fc239ab

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

doc/article/en-US/binding-observables.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Use the Collection Observer to observe changes to a collection. Collection types
186186
}
187187
</source-code>
188188
<source-code lang="TypeScript">
189-
import {BindingEngine, autoinject, IArrayObserverSplice} from 'aurelia-framework';
189+
import {BindingEngine, autoinject, ICollectionObserverSplice} from 'aurelia-framework';
190190

191191
@autoinject
192192
export class App {
@@ -198,7 +198,7 @@ Use the Collection Observer to observe changes to a collection. Collection types
198198
.subscribe(this.collectionChanged.bind(this));
199199
}
200200

201-
collectionChanged(splices: Array<IArrayObserverSplice<string>>) {
201+
collectionChanged(splices: Array<ICollectionObserverSplice<string>>) {
202202
// This will fire any time the collection is modified.
203203
}
204204
}
@@ -227,9 +227,9 @@ The callback will receive an array of splices which provides information about t
227227
}
228228
</source-code>
229229
<source-code lang="TypeScript">
230-
collectionChanged(splices: Array<IArrayObserverSplice<string>>) {
230+
collectionChanged(splices: Array<ICollectionObserverSplice<string>>) {
231231
for (var i = 0; i < splices.length; i++) {
232-
var splice: IArrayObserverSplice<string> = splices[i];
232+
var splice: ICollectionObserverSplice<string> = splices[i];
233233

234234
var valuesAdded = this.myCollection.slice(splice.index, splice.index + splice.addedCount);
235235
if (valuesAdded.length > 0) {
@@ -270,9 +270,9 @@ The callback will receive an array of splices which provides information about t
270270
}
271271
</source-code>
272272
<source-code lang="TypeScript">
273-
collectionChanged(splices: Array<IMapObserverSplice<number, string>>) {
273+
collectionChanged(splices: Array<ICollectionObserverSplice<Map<number, string>>>) {
274274
for (var i = 0; i < splices.length; i++) {
275-
var splice: IMapObserverSplice<number, string> = splices[i];
275+
var splice: ICollectionObserverSplice<Map<number, string>> = splices[i];
276276

277277
if(splice.type == "add"){
278278
var valuesAdded = this.myCollection.get(splice.key);
@@ -312,9 +312,9 @@ The callback will receive an array of splices which provides information about t
312312
}
313313
</source-code>
314314
<source-code lang="TypeScript">
315-
collectionChanged(splices: Array<ISetObserverSplice<number>>) {
315+
collectionChanged(splices: Array<ICollectionObserverSplice<Set<number>>>) {
316316
for (var i = 0; i < splices.length; i++) {
317-
var splice: ISetObserverSplice<number> = splices[i];
317+
var splice: ICollectionObserverSplice<Set<number>> = splices[i];
318318

319319
if(splice.type == "add"){
320320
console.log(`'${splice.value}' was added to the set`);

src/aurelia-binding.d.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export declare interface CollectionObserver {
146146
* The change record of a collection mutation.
147147
*/
148148
export declare interface ICollectionObserverSplice<T = any> {
149-
149+
/* ArrayObserverSplice */
150150
/**
151151
* Number of items added to the collection.
152152
*/
@@ -161,6 +161,33 @@ export declare interface ICollectionObserverSplice<T = any> {
161161
* A collection of items that were removed from the collection.
162162
*/
163163
removed: Array<T>;
164+
/* End ArrayObserverSplice */
165+
166+
/**
167+
* The observed Set or Map after the change.
168+
*/
169+
object: Set<T> | Map<K, V>;
170+
171+
/**
172+
* The value of the Map item prior to the change.
173+
*/
174+
oldValue: V;
175+
176+
/**
177+
* The key of the Map item that was changed.
178+
*/
179+
key: K;
180+
181+
/**
182+
* The Set value that was either added or removed.
183+
*/
184+
value: T;
185+
186+
/**
187+
* The type of change that has taken place. Valid options are "add", "delete", and "update".
188+
* "update" is invalid for Set.
189+
*/
190+
type: "add" | "delete" | "update";
164191
}
165192

166193
/**

0 commit comments

Comments
 (0)