{"action":"created","issue":{"url":"https://api.github.com/repos/angular/angularfire2/issues/848","repository_url":"https://api.github.com/repos/angular/angularfire2","labels_url":"https://api.github.com/repos/angular/angularfire2/issues/848/labels{/name}","comments_url":"https://api.github.com/repos/angular/angularfire2/issues/848/comments","events_url":"https://api.github.com/repos/angular/angularfire2/issues/848/events","html_url":"https://github.com/angular/angularfire2/issues/848","id":211546319,"number":848,"title":"Feature Request: Map() or Extend function to FirebaseListObservable() for list items","user":{"login":"DennisSmolek","id":1397052,"avatar_url":"https://avatars1.githubusercontent.com/u/1397052?v=4","gravatar_id":"","url":"https://api.github.com/users/DennisSmolek","html_url":"https://github.com/DennisSmolek","followers_url":"https://api.github.com/users/DennisSmolek/followers","following_url":"https://api.github.com/users/DennisSmolek/following{/other_user}","gists_url":"https://api.github.com/users/DennisSmolek/gists{/gist_id}","starred_url":"https://api.github.com/users/DennisSmolek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DennisSmolek/subscriptions","organizations_url":"https://api.github.com/users/DennisSmolek/orgs","repos_url":"https://api.github.com/users/DennisSmolek/repos","events_url":"https://api.github.com/users/DennisSmolek/events{/privacy}","received_events_url":"https://api.github.com/users/DennisSmolek/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":14,"created_at":"2017-03-02T23:07:15Z","updated_at":"2017-10-02T18:22:13Z","closed_at":null,"author_association":"NONE","body":"Hey guys, I'm doing a few things with `FirebaseListObservables` that I'd like to be able to extend or map other things onto the items themselves but can't.\r\n\r\nconsider:\r\n``` javascript\r\nlet obj = this.af.database.object('/numberseven'); // the number 7\r\nlet multi = obj.map(inner => inner * 10);\r\nmulti.subscribe(multiplied => console.log('Should be 70:', multiplied)); // console says 70\r\n```\r\n\r\nYou can't do this to the list object as it always returns an Array so you have to double wrap it:\r\n``` javascript\r\nlet obj = this.af.database.list('/numbers'); // [5, 6, 7, 8];\r\nlet multi = obj.map(innerArray => innerArray.map(num => num * 10));\r\nmulti.subscribe(multiplied => console.log('Should be list of numbers:', multiplied)); // [50, 60, 70, 80]\r\n```\r\nThe problem is that it has to run for EVERY item in the array and with more complex mapped functions this becomes a huge performance suck.\r\n\r\nWhat would be cool is a way to do it like:\r\n``` javascript\r\nlet mapped = this.af.database.list('/numbers').map((num) => num * 10);\r\nmapped.subscribe(mappedArray => console.log('mapped array:', mappedArray)); // [50, 60, 70, 80]\r\n```\r\nThat only runs once as the item is actually changed/updated/whatever.\r\n\r\nNow, I haven't spent a lot of time on this, but I think something like this would work:\r\n``` javascript\r\nfunction mapFn(num) { return num * 10};\r\nlet mapped = this.af.database.list('/numbers', {map: mapFn});\r\n```\r\n\r\nThen modify either the `utils.unwrapMapFn` in `firebase_list_factory` or just add it to the `FirebaseListFactoryOps` class and modify the `toValue()`\r\n\r\nsomething like:\r\n``` javascript\r\nconst toValue = preserveSnapshot ? (snapshot => snapshot) : (mapFn ? mapFn((snapshot => utils.unwrapMapFn(snapshot))) ? utils.unwrapMapFn);\r\n```\r\n\r\nThis way we can apply functions directly to the children as they get added to the inner array only once.\r\n\r\nThere are a million ways to do this I know, but I think it would be helpful in the main codebase somewhere..."},"comment":{"url":"https://api.github.com/repos/angular/angularfire2/issues/comments/333621062","html_url":"https://github.com/angular/angularfire2/issues/848#issuecomment-333621062","issue_url":"https://api.github.com/repos/angular/angularfire2/issues/848","id":333621062,"user":{"login":"davideast","id":4570265,"avatar_url":"https://avatars0.githubusercontent.com/u/4570265?v=4","gravatar_id":"","url":"https://api.github.com/users/davideast","html_url":"https://github.com/davideast","followers_url":"https://api.github.com/users/davideast/followers","following_url":"https://api.github.com/users/davideast/following{/other_user}","gists_url":"https://api.github.com/users/davideast/gists{/gist_id}","starred_url":"https://api.github.com/users/davideast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davideast/subscriptions","organizations_url":"https://api.github.com/users/davideast/orgs","repos_url":"https://api.github.com/users/davideast/repos","events_url":"https://api.github.com/users/davideast/events{/privacy}","received_events_url":"https://api.github.com/users/davideast/received_events","type":"User","site_admin":false},"created_at":"2017-10-02T18:22:13Z","updated_at":"2017-10-02T18:22:13Z","author_association":"MEMBER","body":"@DennisSmolek Would the new API with `.stateChanges()` suit your needs?"}}
{"actor":{"display_login":"davideast"}}