Skip to content

Commit

Permalink
chore: fixup more template usage
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Nov 11, 2024
1 parent 66484a4 commit 071a331
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,39 @@ import Component from '@glimmer/component';
// eslint-disable-next-line no-restricted-imports
import { tracked } from '@glimmer/tracking';

import { hbs } from 'ember-cli-htmlbars';

export default async function createTrackingContext(owner, props) {
// eslint-disable-next-line @typescript-eslint/require-await
export default async function createTrackingContext(props) {
let instance;
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const testKeys = Object.keys(props);
class TestComponent extends Component {
@tracked count = 1;

constructor() {
super(...arguments);
// eslint-disable-next-line @typescript-eslint/no-this-alias
instance = this;
}

get ___value() {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
this.count;
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return testKeys.map((key) => this[key]);
}

<template>
<div class="test">{{this.count}}<ul>{{#each this.___value as |prop|}}<li>{{prop}}</li>{{/each}}</ul></div>
</template>
}

const defs = {};
testKeys.forEach((key) => (defs[key] = Object.getOwnPropertyDescriptor(props, key)));

Object.defineProperties(TestComponent.prototype, defs);

owner.register('component:test-component', TestComponent);
owner.register(
'template:components/test-component',
hbs`<div class="test">{{this.count}}<ul>{{#each this.___value as |prop|}}<li>{{prop}}</li>{{/each}}</ul></div>`
);

async function initialRender() {
await render(hbs`<TestComponent/>`);
await render(<template><TestComponent /></template>);
}

return {
Expand Down
2 changes: 1 addition & 1 deletion tests/main/tests/integration/references/has-many-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ module('integration/references/has-many', function (hooks) {

const personsReference = family.hasMany('persons');
let renderedValue;
const context = await createTrackingContext(this.owner, {
const context = await createTrackingContext({
get value() {
renderedValue = personsReference.value();
return renderedValue;
Expand Down
6 changes: 6 additions & 0 deletions tests/warp-drive__schema-record/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check
import { globalIgnores } from '@warp-drive/internal-config/eslint/ignore.js';
import * as gts from '@warp-drive/internal-config/eslint/gts.js';
import * as node from '@warp-drive/internal-config/eslint/node.js';
import * as typescript from '@warp-drive/internal-config/eslint/typescript.js';
import * as qunit from '@warp-drive/internal-config/eslint/qunit.js';
Expand All @@ -15,6 +16,11 @@ export default [
allowedImports: ['@ember/application', '@ember/object', '@ember/owner'],
}),

gts.browser({
srcDirs: ['app', 'tests'],
allowedImports: ['@ember/application', '@ember/object', '@ember/owner'],
}),

// node (module) ================
node.esm(),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type { TestContext } from '@ember/test-helpers';
import { render } from '@ember/test-helpers';
import Component from '@glimmer/component';

import { hbs } from 'ember-cli-htmlbars';

import type { ResourceRelationship } from '@warp-drive/core-types/cache/relationship';
import type { OpaqueRecordInstance } from '@warp-drive/core-types/record';
import type { FieldSchema, IdentityField, ResourceSchema } from '@warp-drive/core-types/schema/fields';
Expand Down Expand Up @@ -32,6 +30,10 @@ export async function reactiveContext<T extends OpaqueRecordInstance>(
get __allFields() {
return _fields;
}

<template>
<div class="reactive-context"><ul>{{#each this.__allFields as |prop|}}<li>{{prop}}: {{get this prop}}</li>{{/each}}</ul></div>
</template>
}
const counters: Record<string, number> = {};

Expand Down Expand Up @@ -96,13 +98,7 @@ export async function reactiveContext<T extends OpaqueRecordInstance>(
});
});

this.owner.register('component:reactive-component', ReactiveComponent);
this.owner.register(
'template:components/reactive-component',
hbs`<div class="reactive-context"><ul>{{#each this.__allFields as |prop|}}<li>{{prop}}: {{get this prop}}</li>{{/each}}</ul></div>`
);

await render(hbs`<ReactiveComponent />`);
await render(<template><ReactiveComponent /></template>);

function reset() {
fields.forEach((field) => {
Expand Down

0 comments on commit 071a331

Please sign in to comment.