-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
Thoughts on this more ergonomic way to wire up the owner + destroyable association? #905
Comments
Implement experiment for: emberjs/rfcs#905 (link)
If anyone wants to this out, you can Mastodon | Twitter | Implementation PR and Changelog you'll need an Something not mentioned anywhere is that if you want reactive arguments, you'd want this form: export default class Demo extends Component {
@link myInstance = new MyClass({
foo: () => this.someTrackedProp,
});
}
class MyClass {
constructor(args) { this.args = args; }
get reactiveGetterConsumingSomeTrackedProp() {
return this.args.foo();
}
} |
So much cleaner and helps centralize some of the nastiness, where bugs could be fixed in one spot. I love this |
Problem
there is a lot of boilerplate for creating vanilla classes that are properly wired up to the container.
For example:
Solution
this would be a new feature to ember in my ideal world, and not in a user-land package (even though it could live there)
Usage:
associateDestroyableChild
andsetOwner
Implementation:
Disclaimer: I've given up with "properly typing" Stage 1 decorators, and instead
assert
my way in to the shapes I need.Thoughts?
Some may wonder how you'd reactively manage args passed to
MyClass
, and the answer there is a Resource.Reason being is that you can't use this pattern:
because you only get constructions of
MyClass
, and no destructions or updates when the args change.This may be perfectly fine for some cases, but Resources are specifically for managing this destruction-or-update scenario where as the
@cached
getter is constructions only, until the parent class is destroyed (then all relevant destructors still remaining in memory would be called)Sure, you could manage an "update" pattern via a local un-tracked variable such as:
But wouldn't it feel much better to do this instead:
ember-resources supports both of these APIs (with and without the decorator), and both are 100% TS safe / make sense to consumers. I need more feedback before one could be decided on -- and no matter what happens, there will be codemods <3
The text was updated successfully, but these errors were encountered: