Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(observer-locator): ability to create getter based observer #1750

Merged
merged 2 commits into from Apr 24, 2023

Conversation

bigopon
Copy link
Member

@bigopon bigopon commented Apr 24, 2023

πŸ“– Description

Resolves #1747

🎫 Issues

At the moment, most of our observer locator are still around the interface .getObserver(object, key). Sometimes this doesnt suffice, as there may be the need to observe more than 1 key at once. One can resolve to a getter property and observe that property, but it's cumbersome and not always appropriate/doable.
This PR adds a new overload on the getObserver of the observer locator, where it allows the 2nd parameter to be a function, treated as a getter, to be passed in. When a function is passed in the 2nd parameter, a different kind of observer that can deal with getter observation will be used instead.
This API also makes it simpler to create higher level API on top, so add a new API watch on IObservation for a common case:

observation.watch(obj, o => o.some.expression, (newValue) => doSomething(newValue));

⏭ Next Steps

See if other APIs can reuse this .getObserver(obj, getter) to remove unnecessary infra as much as possible.

@bigopon bigopon merged commit ba40b2d into master Apr 24, 2023
23 checks passed
@bigopon bigopon deleted the feat/getter-observer branch April 24, 2023 07:19
AureliaEffect pushed a commit that referenced this pull request Apr 27, 2023
2.0.0-beta.5 (2023-04-27)

**Features:**

* **observer-locator:** ability to create getter based observer (#1750) ([ba40b2d](ba40b2d))
* **effect:** add watch ([ba40b2d](ba40b2d))
* **di:** property injection with `resolve` (#1748) ([a22826a](a22826a))
* **aurelia:** ability to inject with `Aurelia` export beside `IAurelia` ([a22826a](a22826a))

**Bug Fixes:**

* **plugin-conventions:** ensure esm cjs compat (#1751) ([f808503](f808503))
* **compat-v1:** dont use both writable and getter/setter ([b58f967](b58f967))

**Refactorings:**

* **build:** preserve pure annotation for better tree shaking (#1745) ([0bc5cd6](0bc5cd6))
* **router-lite:** alias registrations (#1741) ([f5e7140](f5e7140))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] Ability to create computed observer with the observer locator
1 participant