Title: Support cold event streams in templates · Issue #13248 · angular/angular · GitHub
Open Graph Title: Support cold event streams in templates · Issue #13248 · angular/angular
X Title: Support cold event streams in templates · Issue #13248 · angular/angular
Description: Requirements [R1] Observables must be cold (ie if there is no subscription then there should be no listeners.) USE CASE: drag and drop. No need to listen on mousemove if drag has not been initiated. [R2] It must be possible to execute an...
Open Graph Description: Requirements [R1] Observables must be cold (ie if there is no subscription then there should be no listeners.) USE CASE: drag and drop. No need to listen on mousemove if drag has not been initiated...
X Description: Requirements [R1] Observables must be cold (ie if there is no subscription then there should be no listeners.) USE CASE: drag and drop. No need to listen on mousemove if drag has not been initiated...
Opengraph URL: https://github.com/angular/angular/issues/13248
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support cold event streams in templates","articleBody":"# Requirements\r\n* [R1] Observables must be cold (ie if there is no subscription then there should be no listeners.)\r\nUSE CASE: drag and drop. No need to listen on mousemove if drag has not been initiated.\r\n* [R2] It must be possible to execute an expression which computes the action which will be next-ed into the observable.\r\n - USE CASE: ngFor shows a list of todos with a remove button. Clicking the remove should notify the stream not with the DOM event, but with the item to be removed.\r\n* [R3] It must be possible to set up observable recipes to run inside/outside of angular zone.\r\n - USE CASE: \r\n - drag and drop. Don't run CD on mousemove. \r\n - Throttle; debounce; etc..: Only run CD on subscription which pass throttle, debounce; etc.\r\n* [R4] It would be strongly preferable if there was something in the template which would indicate that an observable is listening at a given location. \r\n - USE CASE: it should be easy for the developer/tooling to see where in the source code the event will be processed.\r\n\r\n\r\n# Design\r\n\r\n* Component will annotate fields which will represent Observable Streams which will be created by the Template's ViewFactory. [R4] (This will also determine the parameterization for the Observables. (ie `Observable\u003cMyType>)`)\r\n - The Framework will set those fields right after constructing the object. We need a new hook (`ngOnCreate`) which would be called right after setting the fields but before running first change detection (`ngOnChanges`, `ngOnInit`).\r\n* Create new syntax which will describe [R4]:\r\n - Which events should the template listen on [R4].\r\n - How should the action be computed [R2].\r\n - Which stream should receive the action\r\n*Split Angular Zone into `NgErrorZone` for error handling and `NgChangeDetectionZone` for CD. [R3]\r\n - Provide convenience method running code in `NgErrorZone` and `NgChangeDetectionZone`. [R3]\r\n\r\n```ts\r\n@Component({\r\n template: `\r\n \u003cul>\r\n \u003cli *ngFor=\"let user of users; let i = index\">\r\n {{user.name}}\r\n \u003cbutton (*click|remove)=\"{item: user, index: i}\">X\u003c/button>\r\n \u003cli>\r\n \u003cul>\r\n`\r\n})\r\nclass MyComponent implements OnCreate{\r\n users: User[] = ...;\r\n\r\n\r\n // Specify that this will have property injection.\r\n @Inject()\r\n remove: Observable\u003c{item: User, index: number}>;\r\n\r\n\r\n actions: Observable\u003cAction>;\r\n\r\n\r\n ngOnCreate() {\r\n // An example of building up a recipe.\r\n // Notice that we are making sure that Rx operators have no CD.\r\n this.actions = noChangeDetection(() => remove.map(() => ...));\r\n }\r\n}\r\n```\r\n\r\n* ViewFactory creates an instance of Observable which then is property injected into component\r\n - Observable names and types (Type parameters) are declared in the component\r\n - `@Inject()` identifies that the observable has to be generated in the `ViewContainer`.\r\n - Need a `ngOnCreate()` hook to create recipes.\r\n* Need `noChangeDetection()` method for going in and out of CD. Separate Design Doc TBD.\r\n* `(*click|remove)=\"{item: user, index: i}\"` Placeholder syntax, see discussion later. This is used to generate cold event registration for DOM events. The expression is used to compute the value which will be next ed into the observable.\r\n - Notice that even though there are zero or more instance of places where we listen into DOM events, there is always only one observable instance given that name.\r\n\r\n# Syntax Discussion\r\n\r\nNOTE: The above syntax is used only as a placeholder\r\n\r\nThe Syntax Requirements:\r\n* The syntax needs to encode three items:\r\n - `event`: The DOM event\r\n - `stream`: The destination stream\r\n - `actionExp`: The action object\r\n* Given that we need to encode three things and that `key=\"value\"` only takes two by default we have to figure out how to encode three things into two. The choices are:\r\n - `event+stream=\"actionExp\"`: [favorite]\r\n - This format combines event and stream on the LHS. \r\n - Both event and stream are just symbols (ie foo) not complex expressions (ie `{name: foo + 2}`) and so they can be on the LHS. \r\n - Event is already on LHS in `(event)=\"stmt\"` so it should stay there.\r\n - There is already a precedence for compound LHS in `style.width.px=\"123\"`.\r\n - Example: `(*click|remove)=\"actionExp\"`. \r\n - The `*` is preferred (not necessary) as it hints that it is cold (not always listening)\r\n - The `(...)` should be retained to be consistent with normal event listeners\r\n - `event=\"stream+actionExp\"`: [probably not]\r\n - Micro Syntax has precedence for combining multiple formats on the RHS (but it requires special symbol on the LHS to activate it.) \r\n - Microsyntax is shorthand for an expanded canonical form. Here there would be no canonical form. \r\n - Example: `(*click)=\"actionExp into remove\"`\r\n - The `*` is required as it hints that it is cold (not always listening) and that it is different from normal listener.\r\n - The `(...)` should be retained to be consistent with normal event listeners\r\n* `stream-action=\"actionExp\" stream-event=\"event\"`: [strongly against]\r\n - Require two key-value pairs.\r\n - This format is just very wordy and cumbersome. \r\n - Puts event on the RHS whereas it is on LHS in `(event)=\"stmt\"`.\r\n\r\n","author":{"url":"https://github.com/mhevery","@type":"Person","name":"mhevery"},"datePublished":"2016-12-05T19:51:34Z","url":"https://github.com/angular/angular/issues/13248"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b980ae53-add5-4db9-7ea6-7d7ba1f0f618 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C310:19AA62:1B09D11:225A7F5:6B014FDB |
| html-safe-nonce | 8d26559ccec7fb66bdf4749e2e8b8cf368a641f60d63eb8e01b94432d2c93735 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzEwOjE5QUE2MjoxQjA5RDExOjIyNUE3RjU6NkIwMTRGREIiLCJ2aXNpdG9yX2lkIjoiNzUwMjE3OTA2MDMwNzU0NjA3NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 015f189910f1559e742c191339053ad83d2b35f75d3818872f23929ba25347e8 |
| hovercard-subject-tag | issue:193593423 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/13248/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e797d1ab1b54674062040ca21f153ee14f2632fd132cffb07b3111953225e558/angular/angular/issues/13248 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e797d1ab1b54674062040ca21f153ee14f2632fd132cffb07b3111953225e558/angular/angular/issues/13248 |
| og:image:alt | Requirements [R1] Observables must be cold (ie if there is no subscription then there should be no listeners.) USE CASE: drag and drop. No need to listen on mousemove if drag has not been initiated... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mhevery |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width