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

refactor: remove hard dependency of DI on FASTElement #6280

Merged
merged 7 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "refactor: remove dependency of DI on FASTElement",
"packageName": "@microsoft/fast-element",
"email": "roeisenb@microsoft.com",
"dependentChangeType": "prerelease"
}
1 change: 1 addition & 0 deletions packages/web-components/fast-element/src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const debugMessages = {
[1511 /* invalidKey */]: "Key/value cannot be null or undefined. Are you trying to inject/register something that doesn't exist with DI?",
[1512 /* noDefaultResolver */]: "'${key}' not registered. Did you forget to add @singleton()?",
[1513 /* cyclicDependency */]: "Cyclic dependency found '${name}'.",
[1514 /* connectUpdateRequiresController */]: "Injected properties that are updated on changes to DOM connectivity require the target object to be an instance of FASTElement.",
};

const allPlaceholders = /(\$\{\w+?})/g;
Expand Down
10 changes: 7 additions & 3 deletions packages/web-components/fast-element/src/di/di.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Big thanks to https://github.com/fkleuver and the https://github.com/aurelia/aurelia project
* for the bulk of this code and many of the associated tests.
*/
import { FASTElement } from "../components/fast-element.js";
import { Context, ContextDecorator, ContextEvent, UnknownContext } from "../context.js";
import { Class, Constructable, Message } from "../interfaces.js";
import { Metadata } from "../metadata.js";
Expand Down Expand Up @@ -777,8 +776,13 @@ export const DI = Object.freeze({
value = container.get(key);
this[diPropertyKey] = value;

if (respectConnection && this instanceof FASTElement) {
const notifier = (this as FASTElement).$fastController;
if (respectConnection) {
const notifier = (this as any).$fastController;

if (!notifier) {
throw FAST.error(Message.connectUpdateRequiresController);
}

const handleChange = () => {
const newContainer = DI.findResponsibleContainer(this);
const newValue = newContainer.get(key) as any;
Expand Down
1 change: 1 addition & 0 deletions packages/web-components/fast-element/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export const enum Message {
invalidKey = 1511,
noDefaultResolver = 1512,
cyclicDependency = 1513,
connectUpdateRequiresController = 1514,
}

/**
Expand Down