Title: Allow `computed` computation function to access previous value · Issue #54339 · angular/angular · GitHub
Open Graph Title: Allow `computed` computation function to access previous value · Issue #54339 · angular/angular
X Title: Allow `computed` computation function to access previous value · Issue #54339 · angular/angular
Description: Which @angular/* package(s) are relevant/related to the feature request? core Description A long, interesting, and possibly unfinished discussion developed in sub-RFC 2 about signal APIs, pure functions, and hysteresis. Can, and should, ...
Open Graph Description: Which @angular/* package(s) are relevant/related to the feature request? core Description A long, interesting, and possibly unfinished discussion developed in sub-RFC 2 about signal APIs, pure func...
X Description: Which @angular/* package(s) are relevant/related to the feature request? core Description A long, interesting, and possibly unfinished discussion developed in sub-RFC 2 about signal APIs, pure func...
Opengraph URL: https://github.com/angular/angular/issues/54339
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow `computed` computation function to access previous value","articleBody":"### Which @angular/* package(s) are relevant/related to the feature request?\n\ncore\n\n### Description\n\nA long, interesting, and possibly unfinished [discussion](https://github.com/angular/angular/discussions/49683#discussioncomment-5598532) developed in sub-RFC 2 about signal APIs, pure functions, and [hysteresis](https://github.com/angular/angular/discussions/49683#discussioncomment-5612162).\r\n\r\nCan, and should, `computed` computation functions have access to their previous computation's result?\r\n\r\nI haven't personally run into an use-case for this, and I don't have enough knowledge to post an opinion, but figured we could resurface this, whether it's to continue the discourse or for visibility into why it can't (or won't) be done.\r\n\r\nResources:\r\n- Sub-RFC 2: https://github.com/angular/angular/discussions/49683\r\n- Thread in RFC (again): https://github.com/angular/angular/discussions/49683#discussioncomment-5598532\r\n- Comment where @alxhub says this is \"worth considering\" 😬: https://github.com/angular/angular/discussions/49683#discussioncomment-5612162\r\n- SO question: https://stackoverflow.com/questions/77689615/is-there-a-way-to-use-the-previous-value-of-a-computed-angular-signal\r\n- `ngxtension-platform`'s since-deprecated `computedExtended`: https://github.com/nartc/ngxtension-platform/blob/main/libs/ngxtension/computed/src/computed.ts\n\n### Proposed solution\n\nPass the value to the computation function. I realize it's not as straightforward as this; I'm just trying to bring forth all the information I've gathered.\r\n\r\nhttps://github.com/angular/angular/blob/ca239e8b62017b8460d73e58085d0f1c53a642ff/packages/core/primitives/signals/src/computed.ts#L110-L117\r\n\r\n```ts\r\ntype SomeUnsetRepresentation = undefined; // or UNSET which is currently not exported?\r\nexport declare function computed\u003cT>(\r\n computation: (previousValue: T | SomeUnsetRepresentation) => T, \r\n options?: CreateComputedOptions\u003cT>\r\n): Signal\u003cT>;\r\n```\n\n### Alternatives considered\n\nLots of potential solutions were proposed in [that thread](https://github.com/angular/angular/discussions/49683#discussioncomment-5598532) of the sub-RFC but none are ideal. (using RxJS; delaying computed; tracking the values independently; etc.)","author":{"url":"https://github.com/rlmestre","@type":"Person","name":"rlmestre"},"datePublished":"2024-02-08T13:55:16Z","url":"https://github.com/angular/angular/issues/54339"}
| 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:dd9fcedf-3e78-79f0-8213-fc710524229c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B17A:2E3FEE:38D6736:47FC7F8:6B01F026 |
| html-safe-nonce | 38ff274e29fe47cadbcf22785b5677fab69cc095ba9d3339b2385cb29cf45074 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMTdBOjJFM0ZFRTozOEQ2NzM2OjQ3RkM3Rjg6NkIwMUYwMjYiLCJ2aXNpdG9yX2lkIjoiMjI4NDUxMjA5NDU4ODEwNDc0MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e8ca7e7f34ff835c72619600d88225c236f2d276a3834930663428fef0d7a8c8 |
| hovercard-subject-tag | issue:2125244173 |
| 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/54339/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e8eb636aaecf078613ee11fc9bae1cca97267278a14b242c569099fe9213530e/angular/angular/issues/54339 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e8eb636aaecf078613ee11fc9bae1cca97267278a14b242c569099fe9213530e/angular/angular/issues/54339 |
| og:image:alt | Which @angular/* package(s) are relevant/related to the feature request? core Description A long, interesting, and possibly unfinished discussion developed in sub-RFC 2 about signal APIs, pure func... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rlmestre |
| 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