-
Notifications
You must be signed in to change notification settings - Fork 37
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
Require an owner to exist to be wired through to the resource. #1101
Conversation
|
Estimated impact to a consuming app, depending on which bundle is imported
|
Preview URLsreadme: https://e7d0fdcf.ember-resources.pages.dev |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Oof, I have exactly this usage, and am seeing the assertion failure (in dev) In particular, I have various trackedFunctions defined in vanilla classes like this export class LessonPreview implements PreviewEngine {
manifestBundle = trackedFunction(this, (): Promise<ActivityManifestBundle> => {
return this.loader.fetchManifest(this.manifestPath)
})
} The class is instantiated in a component class extends Component {
constructor() {
this.preview = new LessonPreview()
}
get previewBundle() {
return this.preview.manifestBundle.value ? this.manifestBundle.value : {}
}
<template>{{this.previewBundle}}</template>
} Am I using trackedFunction incorrectly here? I know that from the sample code above it would seem I could just define the trackedFunction in the component, or even in a service, but the vanilla class provides a useful level of abstraction around configuration of each engine (I have many preview engines that need to be used across multiple components). |
The approach I am taking is to use constructor() {
this.preview = new LessonPreview()
setOwner(this.preview, getOwner(this))
} |
Yes, that's a good way to set the owner |
I ran into this issue with import type Owner from '@ember/owner';
import { setOwner } from '@ember/owner';
import Service, { service, type Scope } from 'ember-polaris-service';
import { use } from 'ember-resources';
import MyResource from './my-resource';
class MyService extends Service {
constructor(scope: Scope) {
super(scope);
// ember-resources requires that we have an owner
setOwner(this, scope as Owner);
}
myResource = use(this, MyResource);
} |
why doesn't ember-polaris-service set its own owner? (like other services?) 🤔 |
Without this it's possible to break the public API of
resource
for example:
would fail if the resource is constructed in a vanilla class that doesn't have an owner.
This likely will only affect tests.