{"action":"created","issue":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/5188","labels_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/5188/labels{/name}","comments_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/5188/comments","events_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/5188/events","html_url":"https://github.com/rethinkdb/rethinkdb/issues/5188","id":121356245,"number":5188,"title":"Add a \"type\" field to changefeed entries","user":{"login":"deontologician","id":1366,"avatar_url":"https://avatars.githubusercontent.com/u/1366?v=3","gravatar_id":"","url":"https://api.github.com/users/deontologician","html_url":"https://github.com/deontologician","followers_url":"https://api.github.com/users/deontologician/followers","following_url":"https://api.github.com/users/deontologician/following{/other_user}","gists_url":"https://api.github.com/users/deontologician/gists{/gist_id}","starred_url":"https://api.github.com/users/deontologician/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deontologician/subscriptions","organizations_url":"https://api.github.com/users/deontologician/orgs","repos_url":"https://api.github.com/users/deontologician/repos","events_url":"https://api.github.com/users/deontologician/events{/privacy}","received_events_url":"https://api.github.com/users/deontologician/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/labels/tp:ReQL_proposal","name":"tp:ReQL_proposal","color":"0052cc"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/milestones/112","html_url":"https://github.com/rethinkdb/rethinkdb/milestones/2.3-polish","labels_url":"https://api.github.com/repos/rethinkdb/rethinkdb/milestones/112/labels","id":1419038,"number":112,"title":"2.3-polish","description":"","creator":{"login":"danielmewes","id":505365,"avatar_url":"https://avatars.githubusercontent.com/u/505365?v=3","gravatar_id":"","url":"https://api.github.com/users/danielmewes","html_url":"https://github.com/danielmewes","followers_url":"https://api.github.com/users/danielmewes/followers","following_url":"https://api.github.com/users/danielmewes/following{/other_user}","gists_url":"https://api.github.com/users/danielmewes/gists{/gist_id}","starred_url":"https://api.github.com/users/danielmewes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielmewes/subscriptions","organizations_url":"https://api.github.com/users/danielmewes/orgs","repos_url":"https://api.github.com/users/danielmewes/repos","events_url":"https://api.github.com/users/danielmewes/events{/privacy}","received_events_url":"https://api.github.com/users/danielmewes/received_events","type":"User","site_admin":false},"open_issues":87,"closed_issues":2,"state":"open","created_at":"2015-11-19T01:13:10Z","updated_at":"2015-12-18T20:23:33Z","due_on":null,"closed_at":null},"comments":41,"created_at":"2015-12-09T22:32:47Z","updated_at":"2015-12-18T21:10:40Z","closed_at":null,"body":"Every program I've written using changefeeds has had boilerplate akin to the following in it:\r\n\r\n```js\r\nif (change.new_val != null && change.old_val == null ) {\r\n  change.type = 'added'\r\n} else if ( change.new_val == null && change.old_val != null ) {\r\n  change.type = 'removed'\r\n} else if (change.new_val != null && change.old_val != null ) {\r\n  change.type = 'changed'\r\n// And the new guys:\r\n} else if (change.new_val != undefined && change.old_val == undefined) {\r\n  change.type = 'initial'\r\n} else if (change.new_val == undefined && change.old_val != undefined) {\r\n  change.type = 'uninitial'\r\n}\r\n```\r\n\r\nThis is pretty mind-numbing, and I would guess almost always necessary ( @segphault and @dalanmiller have written way more apps than me and could comment). In addition, it's also error prone. (There are two errors I made in the example above, can you spot them?) The drivers can provide convenience wrappers, but I think we should just make the changefeeds themselves more user friendly.\r\n\r\nI propose we add a `type` field to changefeed entries, and just put the type in as a string. This would also be a natural place to put `type: \"error\"` (see #5041).\r\n\r\nCons:\r\n1. slightly more cluttered\r\n2. slightly more bandwidth\r\n3. *sometimes* you can just delete old_val, add the new_val and you don't need to exactly classify the type. Even in this case, you can just ignore the type field.\r\n\r\nPros:\r\n1. Obviously what everyone really wants\r\n2. Come on\r\n\r\n(I would also extend this behavior to the results from `return_changes` but I would guess the code is shared and so this would just happen as a side-effect)"},"comment":{"url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/comments/165898494","html_url":"https://github.com/rethinkdb/rethinkdb/issues/5188#issuecomment-165898494","issue_url":"https://api.github.com/repos/rethinkdb/rethinkdb/issues/5188","id":165898494,"user":{"login":"mlucy","id":1777134,"avatar_url":"https://avatars.githubusercontent.com/u/1777134?v=3","gravatar_id":"","url":"https://api.github.com/users/mlucy","html_url":"https://github.com/mlucy","followers_url":"https://api.github.com/users/mlucy/followers","following_url":"https://api.github.com/users/mlucy/following{/other_user}","gists_url":"https://api.github.com/users/mlucy/gists{/gist_id}","starred_url":"https://api.github.com/users/mlucy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlucy/subscriptions","organizations_url":"https://api.github.com/users/mlucy/orgs","repos_url":"https://api.github.com/users/mlucy/repos","events_url":"https://api.github.com/users/mlucy/events{/privacy}","received_events_url":"https://api.github.com/users/mlucy/received_events","type":"User","site_admin":false},"created_at":"2015-12-18T21:10:40Z","updated_at":"2015-12-18T21:10:40Z","body":"It sounds like we have a slight majority in favor of 5 types that default to off.  (That also seems like the safer option, because it will break literally 0 existing code even if somebody is counting the keys in the change documents for some reason, maybe to distinguish inserts from initial vals.)"}}