Skip to content

Commit 717d922

Browse files
author
Erin Singer
committed
Made sample app code less verbose
1 parent e0106f5 commit 717d922

File tree

5 files changed

+50
-133
lines changed

5 files changed

+50
-133
lines changed
Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
11
import Component, { hbs, tracked } from '@glimmerx/component';
2-
import { action } from '@glimmerx/modifier';
2+
import { on, action } from '@glimmerx/modifier';
3+
34
import './App.css';
5+
import GreetingHeader from './GreetingHeader';
6+
7+
function formatName(name) {
8+
return `${name} the Great and Powerful`;
9+
}
10+
11+
class FormattedName extends Component {
12+
static template = hbs`
13+
{{formatName this.args.name}}!
14+
`;
415

5-
import Carousel from './Carousel';
16+
get name() {
17+
return this.args.name || 'glimmerx';
18+
}
19+
}
20+
21+
const I_AM_CONSTANT = 'and I am a constant';
22+
const ComponentAsArg = hbs`
23+
<h1>I am {{@title}}</h1>
24+
{{I_AM_CONSTANT}}
25+
`;
26+
export default class HelloWorld extends Component {
27+
static template = hbs`
28+
<ComponentAsArg @title={{component FormattedName name="Oz"}}/>
29+
<GreetingHeader @greeting="hello"/>
30+
<IncrementableButton @startCount={{100}}/>
31+
`;
32+
}
633

7-
export default class App extends Component {
8-
@tracked count = 1;
34+
class IncrementableButton extends Component {
35+
@tracked count = this.args.startCount;
936

1037
@action increment() {
1138
this.count++;
1239
}
1340

1441
static template = hbs`
15-
<h1>Welcome to the untyped JS GlimmerX demo app!</h1>
16-
<Carousel @title="My Awesome Carousel"/>
42+
<p>You have clicked the button {{this.count}} times.</p>
43+
<button {{on "click" this.increment}}>Click</button>
1744
`;
1845
}

test-packages/demo-untyped-glimmerx-app/src/Carousel.css

Lines changed: 0 additions & 15 deletions
This file was deleted.

test-packages/demo-untyped-glimmerx-app/src/Carousel.js

Lines changed: 0 additions & 111 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Component from '@glimmerx/component';
2+
import { hbs } from '@glimmerx/component';
3+
import { helper } from '@glimmerx/helper';
4+
5+
const or = helper(([a, b]) => a || b);
6+
7+
export default class GreetingHeader extends Component {
8+
static template = hbs`
9+
<h1>{{@greeting}}, {{or @target 'glimmerx'}}</h1>
10+
<img src={{this.src}}/>
11+
`;
12+
13+
get src() {
14+
return this.args.src || 'https://picsum.photos/250';
15+
}
16+
}

test-packages/demo-untyped-glimmerx-app/tests/rendering/App.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ module('App test', () => {
66
test('it works', async (assert) => {
77
await renderComponent(App);
88

9-
assert.dom('h1').containsText('Welcome to the untyped JS GlimmerX demo app!');
9+
assert.dom('h1').containsText('I am Oz the Great and Powerful!');
1010
});
1111
});

0 commit comments

Comments
 (0)