Skip to content

Commit 311e4b2

Browse files
authored
Merge pull request #113 from bustle/type-improvements
chore(types): adopt Ember 5.1 stable types, add local typings and CI lint
2 parents ec91659 + 6e2d278 commit 311e4b2

9 files changed

Lines changed: 217 additions & 77 deletions

File tree

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
name: CI
22

3+
on:
4+
push:
5+
branches: ["**"]
6+
pull_request:
7+
branches: ["**"]
8+
9+
jobs:
10+
lint:
11+
name: Lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: '20'
21+
cache: 'pnpm'
22+
23+
- name: Setup pnpm
24+
uses: pnpm/action-setup@v2
25+
with:
26+
version: '10'
27+
28+
- name: Install dependencies
29+
run: pnpm install --frozen-lockfile
30+
31+
- name: Run lint
32+
run: pnpm run lint
33+
name: CI
34+
335
on:
436
push:
537
branches:

addon/components/render-mobiledoc.gts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ type RenderMobiledocArgs = {
5555
onWillDestroy?: () => void;
5656
};
5757

58+
type Signature = {
59+
Args: RenderMobiledocArgs;
60+
Element: HTMLElement;
61+
Blocks: never;
62+
};
63+
5864
type HookArgs = [
5965
{
6066
env: {
@@ -107,7 +113,7 @@ function createComponentAtom(name: string) {
107113
};
108114
}
109115

110-
export default class RenderMobiledocComponent extends Component<RenderMobiledocArgs> {
116+
export default class RenderMobiledocComponent extends Component<Signature> {
111117
@tracked private componentCardsStore: CardRegistration[] = [];
112118
@tracked private componentAtomsStore: AtomRegistration[] = [];
113119
private teardownRender: (() => void) | null = null;
@@ -382,22 +388,21 @@ export default class RenderMobiledocComponent extends Component<RenderMobiledocA
382388

383389
{{#each this.componentCards as |card|}}
384390
{{#in-element card.destinationElement}}
385-
{{component
386-
card.componentDefinition
387-
options=(readonly card.options)
388-
payload=(readonly card.payload)
389-
}}
391+
{{#let card.componentDefinition as |CardComponent|}}
392+
<CardComponent @options={{card.options}} @payload={{card.payload}} />
393+
{{/let}}
390394
{{/in-element}}
391395
{{/each}}
392396

393397
{{#each this.componentAtoms as |atom|}}
394398
{{#in-element atom.destinationElement}}
395-
{{component
396-
atom.componentDefinition
397-
options=(readonly atom.options)
398-
payload=(readonly atom.payload)
399-
value=(readonly atom.value)
400-
}}
399+
{{#let atom.componentDefinition as |AtomComponent|}}
400+
<AtomComponent
401+
@options={{atom.options}}
402+
@payload={{atom.payload}}
403+
@value={{atom.value}}
404+
/>
405+
{{/let}}
401406
{{/in-element}}
402407
{{/each}}
403408
</template>

addon/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import Renderer from 'ember-mobiledoc-dom-renderer/mobiledoc-dom-renderer/index';
2-
import { RENDER_TYPE } from 'ember-mobiledoc-dom-renderer/mobiledoc-dom-renderer/index';
1+
// Re-export the runtime mobiledoc-dom-renderer package's default export and
2+
// named exports. Importing directly from the runtime package makes the
3+
// module resolution straightforward during type-checking and at runtime.
4+
import Renderer, { RENDER_TYPE } from 'mobiledoc-dom-renderer';
35

46
export { RENDER_TYPE };
57
export default Renderer;

addon/utils/document.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import { getOwner } from '@ember/application';
22

33
// Private Ember API usage. Get the dom implementation used by the current
44
// renderer, be it native browser DOM or Fastboot SimpleDOM
5-
export function getDocument(context) {
6-
const documentService = getOwner(context).lookup('service:-document');
5+
export function getDocument(context: object) {
6+
// getOwner can return undefined in some edge cases; use a minimal Owner-like
7+
// shape to call `lookup` safely without using `any`.
8+
type OwnerLike = { lookup?(name: string): unknown } | undefined;
9+
const owner = getOwner(context as object) as OwnerLike;
10+
const documentService = owner?.lookup && owner.lookup('service:-document');
711
if (!documentService) {
812
throw new Error('ember-mobiledoc-dom-renderer could not get DOM');
913
}

tests/fastboot/rendering-mobiledoc-test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
13
import { module, test } from 'qunit';
24
import { setup, visit } from 'ember-cli-fastboot-testing/test-support';
35

46
module('FastBoot | rendering tests', function (hooks) {
57
setup(hooks);
68

79
test('renders', async function (assert) {
8-
const res = await visit('/fastboot');
10+
const res = (await visit('/fastboot')) as any;
911
assert.strictEqual(res.statusCode, 200);
1012

1113
assert.dom('body', res.htmlDocument).exists({ count: 1 });
@@ -14,7 +16,7 @@ module('FastBoot | rendering tests', function (hooks) {
1416

1517
test('renders simple mobiledoc', async function (assert) {
1618
const name = 'simple';
17-
const { htmlDocument } = await visit('/fastboot');
19+
const { htmlDocument } = (await visit('/fastboot')) as any;
1820
const wrapper = `.render-mobiledoc-wrapper.${name}`;
1921
assert.dom(wrapper, htmlDocument).exists({ count: 1 });
2022

@@ -25,7 +27,7 @@ module('FastBoot | rendering tests', function (hooks) {
2527

2628
test('renders mobiledoc with markup', async function (assert) {
2729
const name = 'with-markup';
28-
const { htmlDocument } = await visit('/fastboot');
30+
const { htmlDocument } = (await visit('/fastboot')) as any;
2931

3032
const wrapper = `.render-mobiledoc-wrapper.${name}`;
3133
assert.dom(wrapper, htmlDocument).exists({ count: 1 });
@@ -37,7 +39,7 @@ module('FastBoot | rendering tests', function (hooks) {
3739

3840
test('renders mobiledoc with link', async function (assert) {
3941
const name = 'with-link';
40-
const { htmlDocument } = await visit('/fastboot');
42+
const { htmlDocument } = (await visit('/fastboot')) as any;
4143

4244
const wrapper = `.render-mobiledoc-wrapper.${name}`;
4345
assert.dom(wrapper, htmlDocument).exists({ count: 1 });
@@ -52,7 +54,7 @@ module('FastBoot | rendering tests', function (hooks) {
5254

5355
test('renders mobiledoc with unsafe link', async function (assert) {
5456
const name = 'with-unsafe-link';
55-
const { htmlDocument } = await visit('/fastboot');
57+
const { htmlDocument } = (await visit('/fastboot')) as any;
5658

5759
const wrapper = `.render-mobiledoc-wrapper.${name}`;
5860
assert.dom(wrapper, htmlDocument).exists({ count: 1 });
@@ -70,7 +72,7 @@ module('FastBoot | rendering tests', function (hooks) {
7072
const componentClassName = 'test-card-component';
7173
const payloadClassName = 'test-card-component-payload';
7274

73-
const { htmlDocument, statusCode } = await visit('/fastboot');
75+
const { htmlDocument, statusCode } = (await visit('/fastboot')) as any;
7476
assert.strictEqual(statusCode, 200);
7577

7678
const wrapper = `.render-mobiledoc-wrapper.${name}`;
@@ -89,7 +91,7 @@ module('FastBoot | rendering tests', function (hooks) {
8991
const payloadClassName = 'test-atom-component-payload';
9092
const valueClassName = 'test-atom-component-value';
9193

92-
const { htmlDocument, statusCode } = await visit('/fastboot');
94+
const { htmlDocument, statusCode } = (await visit('/fastboot')) as any;
9395
assert.strictEqual(statusCode, 200);
9496

9597
const wrapper = `.render-mobiledoc-wrapper.${name}`;

0 commit comments

Comments
 (0)