{"action":"created","issue":{"url":"https://api.github.com/repos/canjs/can-event/issues/11","repository_url":"https://api.github.com/repos/canjs/can-event","labels_url":"https://api.github.com/repos/canjs/can-event/issues/11/labels{/name}","comments_url":"https://api.github.com/repos/canjs/can-event/issues/11/comments","events_url":"https://api.github.com/repos/canjs/can-event/issues/11/events","html_url":"https://github.com/canjs/can-event/issues/11","id":174804336,"number":11,"title":"Make events fire asynchronously and dispatched during request animation frame or setImmediate ~34","user":{"login":"justinbmeyer","id":78602,"avatar_url":"https://avatars.githubusercontent.com/u/78602?v=3","gravatar_id":"","url":"https://api.github.com/users/justinbmeyer","html_url":"https://github.com/justinbmeyer","followers_url":"https://api.github.com/users/justinbmeyer/followers","following_url":"https://api.github.com/users/justinbmeyer/following{/other_user}","gists_url":"https://api.github.com/users/justinbmeyer/gists{/gist_id}","starred_url":"https://api.github.com/users/justinbmeyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinbmeyer/subscriptions","organizations_url":"https://api.github.com/users/justinbmeyer/orgs","repos_url":"https://api.github.com/users/justinbmeyer/repos","events_url":"https://api.github.com/users/justinbmeyer/events{/privacy}","received_events_url":"https://api.github.com/users/justinbmeyer/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/canjs/can-event/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/canjs/can-event/labels/P2","name":"P2","color":"f9d0c4"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2016-09-02T16:57:10Z","updated_at":"2016-09-02T18:06:22Z","closed_at":null,"body":"## Proposal\r\n\r\nThis proposal seeks to do away with the need for `canBatch.start()` and `canBatch.stop()` by making batching the default.  \r\n\r\nAt the end of a request animation frame, all events would be dispatched, and live bound templates updated.\r\n\r\n## Why Now?\r\n\r\nBecause this has to be done during a major release.  If don't do it now, it will be hard or impossible to do before a 4.0.  CanJS's event system is used by everything.\r\n\r\n## Benefits\r\n\r\nNo more calling `canBatch.start()` and `canBatch.stop()`.  This is likely very confusing to users.  We want people to fall into the pit of success.\r\n\r\nThings like animations driven by state changes will run more smoothly.\r\n\r\n## Drawbacks\r\n\r\n- Debugging what mutation caused what even might be more difficult because you can't look up the call stack. This is already difficult with the new batch queuing system.  There is no longer a 1-1 relationship between change and dispatch.  Some work could be done so a trace of an event is available in dev mode.\r\n\r\n### Migration\r\n\r\nThis would break nearly all of CanJS's tests which rely on synchronous events.  For example, a test that renders a template, changes some observable, investigate the updated DOM immediately.\r\n\r\nA `event.flush()` can help like:\r\n\r\n```js\r\nvar frag = template(map);\r\nmap.foo = \"bar\";\r\nevent.flush();\r\nfrag.firstChild.nodeValue //-> \"bar\"\r\n```\r\n\r\nThis will almost certainly break old apps.\r\n\r\nA `event.legacy()` which operates the old way would help.\r\n\r\n## Alternatives\r\n\r\n- Make `can-view-live` where the real async behavior happens.  Flush will be more difficult, but possible.  The benefit here is that the state can change a whole bunch, but the template would wait until its all done. We could then dispatch data events on `setImmediate` and DOM updates on `RAF`.\r\n- We could release 3.0 and immediately set out to release a 4.0 with this change.\r\n- We could have people turn this on.  `event.async()`\r\n\r\n## Implementation details\r\n\r\nI would probably merge can-event and can-event/batch.\r\n\r\nThe 1st event dispatched would need to requestAnimationFrame.  This event and all future events until that point would be put in the batch queue similar to how they are done now.\r\n\r\nWhen the requestAnimationFrame is complete, the batch would be stopped similar to what is done now.  That would fire off that batch's events and any other events that were dispatched at this time would also be dispatched immediately (not async because we need computes of computes to update).\r\n\r\nOTHER:\r\n\r\n - what if event listeners are removed - we are dispatching the event at a time point, so that's ok."},"comment":{"url":"https://api.github.com/repos/canjs/can-event/issues/comments/244447528","html_url":"https://github.com/canjs/can-event/issues/11#issuecomment-244447528","issue_url":"https://api.github.com/repos/canjs/can-event/issues/11","id":244447528,"user":{"login":"justinbmeyer","id":78602,"avatar_url":"https://avatars.githubusercontent.com/u/78602?v=3","gravatar_id":"","url":"https://api.github.com/users/justinbmeyer","html_url":"https://github.com/justinbmeyer","followers_url":"https://api.github.com/users/justinbmeyer/followers","following_url":"https://api.github.com/users/justinbmeyer/following{/other_user}","gists_url":"https://api.github.com/users/justinbmeyer/gists{/gist_id}","starred_url":"https://api.github.com/users/justinbmeyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinbmeyer/subscriptions","organizations_url":"https://api.github.com/users/justinbmeyer/orgs","repos_url":"https://api.github.com/users/justinbmeyer/repos","events_url":"https://api.github.com/users/justinbmeyer/events{/privacy}","received_events_url":"https://api.github.com/users/justinbmeyer/received_events","type":"User","site_admin":false},"created_at":"2016-09-02T18:06:22Z","updated_at":"2016-09-02T18:06:22Z","body":"@pYr0x on the mocha thing ... that can at least be done individually in each repo."}}
{"actor":{"display_login":"justinbmeyer"}}