Title: Specify extra effect dependencies without using them inside the effect function · Issue #50916 · angular/angular · GitHub
Open Graph Title: Specify extra effect dependencies without using them inside the effect function · Issue #50916 · angular/angular
X Title: Specify extra effect dependencies without using them inside the effect function · Issue #50916 · angular/angular
Description: Which @angular/* package(s) are relevant/related to the feature request? core Description Allow specifying dependencies without the need to call them inside the effect. That is needed whenever we need to react to a signal change without ...
Open Graph Description: Which @angular/* package(s) are relevant/related to the feature request? core Description Allow specifying dependencies without the need to call them inside the effect. That is needed whenever we n...
X Description: Which @angular/* package(s) are relevant/related to the feature request? core Description Allow specifying dependencies without the need to call them inside the effect. That is needed whenever we n...
Opengraph URL: https://github.com/angular/angular/issues/50916
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Specify extra effect dependencies without using them inside the effect function","articleBody":"### Which @angular/* package(s) are relevant/related to the feature request?\r\n\r\ncore\r\n\r\n### Description\r\n\r\nAllow specifying dependencies without the need to call them inside the effect. That is needed whenever we need to react to a signal change without needing to use the value of that signal inside the effect. For example:\r\n```javascript\r\n// log the below message whenever a task is completed (assuming we have a `completedTasksCount` signal)\r\neffect(() => {\r\n console.log(\"Congratulations on completing the task!!\")\r\n})\r\n```\r\n\r\n### Proposed solution\r\n\r\nadd `extraDependencies` to [CreateEffectOptions](https://angular.io/api/core/CreateEffectOptions). It will be a list of signals that trigger re-execution of the effect even though they are not used inside the effect.\r\n\r\n```javascript\r\neffect(() => {\r\n console.log(\"Congratulation on completing the task!!\")\r\n}, {extarDependencies: [completedTasksCount]})\r\n```\r\n\r\nI also thought this new option fits best as the last piece that complements what angular currently has:\r\n- automatic tracking of signals used inside the effect\r\n- ability to [untrack](https://angular.io/guide/signals#reading-without-tracking-dependencies) specific signals even though though they are used inside the effect\r\n\r\n\r\n### Alternatives considered\r\n\r\n#### Add `dependencies` to [CreateEffectOptions](https://angular.io/api/core/CreateEffectOptions).\r\nThe new option will handle both: untracking of signals used inside the effect and tracking of signals not used inside the effect. When `dependencies` is specified, angular should disable its default behavior and only track signals specified in `dependencies`. I actually think this is a better alternative if the feature is approved for implementation. That's because it provides one API for tracking and untracking as opposed to checking the `extraDependencies` to know what forces re-execution of the effect and checking the effect body to see which signals are wrapped inside `untracked`.\r\n\r\n#### tracked(completedTasksCount)\r\nmuch like there is `untracked(counter)`, add `tracked(counter)` to trigger re-execution of the effect. My problem with it is that it can be called anywhere inside the effect. So, there is no one place to check what forces re-execution of the effect.\r\n\r\n#### Check other frontend libraries/frameworks\r\n- Solidjs [on](https://www.solidjs.com/docs/latest/api#on): I went to check if solidjs has sth to deal with these use cases and `on` seemed to be the closest thing. To be honest, I didn't quite understand if it solves the same issue, so I'm only mentioning it here in case it's helpful.\r\n- Preact [effect](https://github.com/preactjs/signals#effectfn): seems like it doesn't allow re-execution of the effect unless a signal is accessed.\r\n- Svelte: the `$:` seems to re-execute only when one of the values referenced inside changes\r\n- Qwik [useTask$](https://qwik.builder.io/docs/guides/qwik-nutshell/#usetask----): doesn't run into the problem because it is explicit about what the effect tracks `taskContext.track(() => page.value)`\r\n- React `useEffect`: doesn't run into the problem because it is explicit about what the effect tracks through `dependencies`\r\n","author":{"url":"https://github.com/ghazi-git","@type":"Person","name":"ghazi-git"},"datePublished":"2023-07-02T11:20:41Z","url":"https://github.com/angular/angular/issues/50916"}
| 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:503fef5f-47d1-82d4-8c0d-6d07fee3d547 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B006:2454CC:41436F8:52B7D98:6B02244D |
| html-safe-nonce | 17d65abdcc59dd5f7e23791843f7ed3ddb3c7c330649eb6c6904b8bf6a8701bd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDA2OjI0NTRDQzo0MTQzNkY4OjUyQjdEOTg6NkIwMjI0NEQiLCJ2aXNpdG9yX2lkIjoiNTg3NjcxNzM4NTQxNDc0NzIxNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d972a9229e1788b5a7408d7f0f55bf8398fb539d3f2648b598b5828947b6d906 |
| hovercard-subject-tag | issue:1784591179 |
| 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/50916/issue_layout |
| twitter:image | https://opengraph.githubassets.com/549bc3f4d6557ffab2b7147763f2bc3b7f1edeeaa1cc17f4adcbe033aeffce0c/angular/angular/issues/50916 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/549bc3f4d6557ffab2b7147763f2bc3b7f1edeeaa1cc17f4adcbe033aeffce0c/angular/angular/issues/50916 |
| og:image:alt | Which @angular/* package(s) are relevant/related to the feature request? core Description Allow specifying dependencies without the need to call them inside the effect. That is needed whenever we n... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ghazi-git |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width