-
-
Notifications
You must be signed in to change notification settings - Fork 69
Open
Description
Here is a path for libraries to support both (with typescript):
import { appEmberSatisfies, importSync, macroCondition } from '@embroider/macros';
import type Owner from '@ember/owner';
interface CompatOwner {
getOwner: (context: unknown) => Owner | undefined;
setOwner: (context: unknown, owner: Owner) => void;
}
export const compatOwner = {} as CompatOwner;
if (macroCondition(appEmberSatisfies('>=4.12.0'))) {
// In no version of ember where `@ember/owner` tried to be imported did it exist
// Using 'any' here because importSync can't lookup types correctly
compatOwner.getOwner = (importSync('@ember/owner') as any).getOwner;
compatOwner.setOwner = (importSync('@ember/owner') as any).setOwner;
} else {
// Using 'any' here because importSync can't lookup types correctly
compatOwner.getOwner = (importSync('@ember/application') as any).getOwner;
compatOwner.setOwner = (importSync('@ember/application') as any).setOwner;
}
// usage
compatOwner.getOwner(this)and for app devs, here is how they can use libraries that use @ember/owner, even if they're behind 4.11 (when @ember/owner landed in stable)
https://github.com/NullVoxPopuli/ember-polyfill-get-and-set-owner-from-ember-owner
Requires:
@embroider/macros1.19.4 (which does not require embroider)
Metadata
Metadata
Assignees
Labels
No labels