{"action":"created","issue":{"url":"https://api.github.com/repos/jashkenas/backbone/issues/3808","repository_url":"https://api.github.com/repos/jashkenas/backbone","labels_url":"https://api.github.com/repos/jashkenas/backbone/issues/3808/labels{/name}","comments_url":"https://api.github.com/repos/jashkenas/backbone/issues/3808/comments","events_url":"https://api.github.com/repos/jashkenas/backbone/issues/3808/events","html_url":"https://github.com/jashkenas/backbone/issues/3808","id":108592906,"number":3808,"title":"changedAttributes() behaving weird","user":{"login":"jeffijoe","id":2505474,"avatar_url":"https://avatars1.githubusercontent.com/u/2505474?v=4","gravatar_id":"","url":"https://api.github.com/users/jeffijoe","html_url":"https://github.com/jeffijoe","followers_url":"https://api.github.com/users/jeffijoe/followers","following_url":"https://api.github.com/users/jeffijoe/following{/other_user}","gists_url":"https://api.github.com/users/jeffijoe/gists{/gist_id}","starred_url":"https://api.github.com/users/jeffijoe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeffijoe/subscriptions","organizations_url":"https://api.github.com/users/jeffijoe/orgs","repos_url":"https://api.github.com/users/jeffijoe/repos","events_url":"https://api.github.com/users/jeffijoe/events{/privacy}","received_events_url":"https://api.github.com/users/jeffijoe/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2015-09-28T05:45:50Z","updated_at":"2018-03-14T10:12:02Z","closed_at":null,"author_association":"NONE","body":"I am using `Model.changedAttributes()` to write a computed field helper, but there's an issue where `changedAttributes` returns false when not expected (at least not by me).\n\nReproduced in [this pen](http://codepen.io/anon/pen/PPbRpO?editors=001).\n\n``` javascript\nconsole.clear();\nlet Backbone = window.Backbone;\nvar m = new Backbone.Model();\n\nlet log = (txt, obj) => document.write(txt + ' ', JSON.stringify(obj)+ '<br/>');\n\nlet lastChange;\nm.on('change', () => {\n  log('Before', lastChange);\n  lastChange = m.changedAttributes(lastChange);\n  log('After', lastChange);\n});\n\nm.set('search', 'some text');\n// Why does this emit \"false\"? It was changed!\nm.set('search', '');\nm.set('search', 'some other text');\n\n```\n\nI need the `lastChange` because there are multiple instances of that code on a model instance. I use it to determine dependency changes (for computed fields).\n\nIs this expected behavior?\n"},"comment":{"url":"https://api.github.com/repos/jashkenas/backbone/issues/comments/372969272","html_url":"https://github.com/jashkenas/backbone/issues/3808#issuecomment-372969272","issue_url":"https://api.github.com/repos/jashkenas/backbone/issues/3808","id":372969272,"user":{"login":"skeptic35","id":1461744,"avatar_url":"https://avatars1.githubusercontent.com/u/1461744?v=4","gravatar_id":"","url":"https://api.github.com/users/skeptic35","html_url":"https://github.com/skeptic35","followers_url":"https://api.github.com/users/skeptic35/followers","following_url":"https://api.github.com/users/skeptic35/following{/other_user}","gists_url":"https://api.github.com/users/skeptic35/gists{/gist_id}","starred_url":"https://api.github.com/users/skeptic35/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/skeptic35/subscriptions","organizations_url":"https://api.github.com/users/skeptic35/orgs","repos_url":"https://api.github.com/users/skeptic35/repos","events_url":"https://api.github.com/users/skeptic35/events{/privacy}","received_events_url":"https://api.github.com/users/skeptic35/received_events","type":"User","site_admin":false},"created_at":"2018-03-14T10:12:02Z","updated_at":"2018-03-14T10:12:02Z","author_association":"NONE","body":"Stumbled upon this very problem today and imho it is a bug. \r\nAccording to documentation the change event ist triggered \"when a model's attributes have changed\". \"have changed\" - not \"are about to change\". So a call to ```changedAttributes``` in a change handler should imho compare to the current attributes, not the previous ones.\r\nAlas the internal ```_changing``` property is reset to ```false``` only *after* the change event is triggered. Thus changedAttributes, when being called with the ```diff``` parameter, compares to the previous Attributes."}}
{"actor":{"display_login":"skeptic35"}}