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

Allow link to receive owner directly #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 9 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions reactiveweb/src/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ function directLink(child: object, parent: object) {

let owner = getOwner(parent);

// the parent *is* the owner
// These checks are based on the `@public` interface of what
// an owner is
if (!owner && 'lookup' in parent && 'register' in parent && 'ownerInjection' in parent) {
// SAFETY: there is no JS-mode way to narrow an object
// to an owner.
// SEE: @ember/-internal/owner.d.ts
owner = parent as any;
}

if (owner) {
setOwner(child, owner);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"lint:prettier": "prettier -c .",
"lint:prettier:fix": "prettier -w .",
"_syncPnpm": "pnpm sync-dependencies-meta-injected",
"start": "concurrently 'ember serve' 'pnpm _syncPnpm --watch' --names 'tests serve,tests sync deps'",
"start": "concurrently 'ember serve' 'pnpm sync-dependencies-meta-injected --watch' --names 'tests serve,tests sync deps'",
"test:ember": "pnpm _syncPnpm && ember test --test-port 0"
},
"dependenciesMeta": {
Expand Down Expand Up @@ -82,7 +82,6 @@
"prettier": "^3.0.3",
"qunit": "^2.20.0",
"qunit-dom": "^3.0.0",
"reactiveweb": "workspace:*",
"stylelint": "^15.11.0",
"stylelint-config-standard": "^34.0.0",
"stylelint-prettier": "^4.0.2",
Expand All @@ -101,6 +100,7 @@
"@nullvoxpopuli/eslint-configs": "^3.2.2",
"ember-concurrency": "^3.1.1",
"ember-resources": "^6.4.2",
"reactiveweb": "workspace:*",
"msw": "^1.3.2"
},
"msw": {
Expand Down
14 changes: 14 additions & 0 deletions tests/test-app/tests/utils/link-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,18 @@ module('link', function (hooks) {

assert.strictEqual(demo.foo.foo, 2);
});

test('can be passed the owner', async function (assert) {
this.owner.register('service:foo', FooService);

class Demo {
@service declare foo: FooService;
}

let demo = new Demo();

link(demo, this.owner);

assert.strictEqual(demo.foo.foo, 2);
});
});
Loading