What gets into the variable "s"? And if not difficult, then in steps to explain this code (Below is an explanation of the code, but they are not clear enough for me).

usersAddedOrRemoved: function(changeRecord) { if (changeRecord) { changeRecord.indexSplices.forEach(function(s) { s.removed.forEach(function(user) { console.log(user.name + ' was removed'); }); 

From Polymer documentation:

It is a polymer's array mutation methods. It has been a set of array splices.

Your observer method should accept a single argument. The record of the mutations Each change record provides the following property:

indexSplices. In terms of array indexes. Each indexSplices record contains the following properties:

index. Position where the splice started. removed. Array of removed items. addedCount. Number of new items inserted at index. object: A reference to the array in question. type: The string literal 'splice'.

Example:

 Polymer({ is: 'x-custom', properties: { users: { type: Array, value: function() { return []; } } }, observers: [ 'usersAddedOrRemoved(users.splices)' ], usersAddedOrRemoved: function(changeRecord) { if (changeRecord) { changeRecord.indexSplices.forEach(function(s) { s.removed.forEach(function(user) { console.log(user.name + ' was removed'); }); for (var i=0; i<s.addedCount; i++) { var index = s.index + i; var newUser = s.object[index]; console.log('User ' + newUser.name + ' added at index ' + index); } }, this); } }, ready: function() { this.push('users', {name: "Jack Aubrey"}); }, }); 
  • one
    Can't you launch and output to the console? - Zhi V
  • forEach first argument in callback passes the current element of the sequence - Grundy

0