{"action":"created","issue":{"url":"https://api.github.com/repos/vuejs/vue/issues/4386","repository_url":"https://api.github.com/repos/vuejs/vue","labels_url":"https://api.github.com/repos/vuejs/vue/issues/4386/labels{/name}","comments_url":"https://api.github.com/repos/vuejs/vue/issues/4386/comments","events_url":"https://api.github.com/repos/vuejs/vue/issues/4386/events","html_url":"https://github.com/vuejs/vue/issues/4386","id":193376157,"number":4386,"title":"add reactive array swap","user":{"login":"jfcg","id":1410597,"avatar_url":"https://avatars.githubusercontent.com/u/1410597?v=3","gravatar_id":"","url":"https://api.github.com/users/jfcg","html_url":"https://github.com/jfcg","followers_url":"https://api.github.com/users/jfcg/followers","following_url":"https://api.github.com/users/jfcg/following{/other_user}","gists_url":"https://api.github.com/users/jfcg/gists{/gist_id}","starred_url":"https://api.github.com/users/jfcg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jfcg/subscriptions","organizations_url":"https://api.github.com/users/jfcg/orgs","repos_url":"https://api.github.com/users/jfcg/repos","events_url":"https://api.github.com/users/jfcg/events{/privacy}","received_events_url":"https://api.github.com/users/jfcg/received_events","type":"User","site_admin":false},"labels":[{"id":487748339,"url":"https://api.github.com/repos/vuejs/vue/labels/2.x","name":"2.x","color":"c2e0c6","default":false},{"id":217551163,"url":"https://api.github.com/repos/vuejs/vue/labels/feature%20request","name":"feature request","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-12-04T21:14:28Z","updated_at":"2016-12-05T09:19:25Z","closed_at":null,"body":"I am writing a simple todo list component with:\r\n```javascript\r\nVue.component('todo-list', {\r\n    props: ['todos'],\r\n    template:\r\n    `<ol>\r\n        <li v-for=\"(td, ix) in todos\">\r\n            {{td}}\r\n            <button title=\"delete\"  @click=\"todos.splice(ix,1)\">X</button>\r\n            <button title=\"move up\" @click=\"todos.swap(ix,ix-1)\" v-show=\"ix>0\">^</button>\r\n        </li>\r\n    </ol>`,\r\n})\r\n```\r\nFor this to work I need (in core/observer/array.js) something like:\r\n```javascript\r\nArray.prototype.swap = function(x,y) {\r\n  var t = this[x]\r\n  this[x] = this[y]\r\n  this[y] = t\r\n}\r\nconst arrayProto = Array.prototype\r\nexport const arrayMethods = Object.create(arrayProto)\r\n\r\n/**\r\n * Intercept mutating methods and emit events\r\n */\r\n;[\r\n  'push',\r\n  'pop',\r\n  'shift',\r\n  'unshift',\r\n  'splice',\r\n  'swap', // added\r\n  'sort',\r\n  'reverse'\r\n]\r\n```\r\nIt works when I (lazily) fixed dist/vue.js, but did not run the tests.\r\nI think it is worth to add swap this way because notify() is run just once, am I wrong?"},"comment":{"url":"https://api.github.com/repos/vuejs/vue/issues/comments/264803444","html_url":"https://github.com/vuejs/vue/issues/4386#issuecomment-264803444","issue_url":"https://api.github.com/repos/vuejs/vue/issues/4386","id":264803444,"user":{"login":"HerringtonDarkholme","id":2883231,"avatar_url":"https://avatars.githubusercontent.com/u/2883231?v=3","gravatar_id":"","url":"https://api.github.com/users/HerringtonDarkholme","html_url":"https://github.com/HerringtonDarkholme","followers_url":"https://api.github.com/users/HerringtonDarkholme/followers","following_url":"https://api.github.com/users/HerringtonDarkholme/following{/other_user}","gists_url":"https://api.github.com/users/HerringtonDarkholme/gists{/gist_id}","starred_url":"https://api.github.com/users/HerringtonDarkholme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HerringtonDarkholme/subscriptions","organizations_url":"https://api.github.com/users/HerringtonDarkholme/orgs","repos_url":"https://api.github.com/users/HerringtonDarkholme/repos","events_url":"https://api.github.com/users/HerringtonDarkholme/events{/privacy}","received_events_url":"https://api.github.com/users/HerringtonDarkholme/received_events","type":"User","site_admin":false},"created_at":"2016-12-05T09:19:25Z","updated_at":"2016-12-05T09:19:25Z","body":"Why not just write \r\n```ts\r\nVue.swap = function(arr, x, y) {\r\n   var origin = arr[x]\r\n   arr.splice(x, 1, arr[y])\r\n   Vue.set(arr, y, origin)\r\n}\r\n```\r\n\r\nhttps://jsfiddle.net/L92w2372/2/"}}
{"actor":{"display_login":"HerringtonDarkholme"}}