Skip to content

Commit 3bf933f

Browse files
author
ignace
committed
convert my-table to gjs
1 parent a3e3219 commit 3bf933f

File tree

3 files changed

+138
-133
lines changed

3 files changed

+138
-133
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import Component from '@glimmer/component';
2+
import { action } from '@ember/object';
3+
import { tracked } from '@glimmer/tracking';
4+
import { inject as service } from '@ember/service';
5+
6+
import BsButton from 'ember/components/bs-button';
7+
import { on } from '@ember/modifier';
8+
import { fn } from '@ember/helper';
9+
10+
import {
11+
run, runLots, add, update, swapRows, deleteRow,
12+
} from 'ember-temp/utils/benchmark-helpers';
13+
14+
export default class MyTable extends Component {
15+
@tracked
16+
id = 1;
17+
18+
@tracked
19+
data = [];
20+
21+
@tracked
22+
_selected = undefined;
23+
24+
@service('state') state;
25+
26+
get selected() {
27+
return this._selected;
28+
}
29+
set selected(value) {
30+
this.state.updateSelection(value);
31+
this._selected = value;
32+
}
33+
34+
@action create() {
35+
const result = run(this.id);
36+
37+
this.id = result.id;
38+
this.data = result.data;
39+
this.selected = undefined;
40+
}
41+
42+
@action add() {
43+
const result = add(this.id, this.data);
44+
this.id = result.id;
45+
this.data = result.data;
46+
}
47+
48+
@action update() {
49+
update(this.data);
50+
}
51+
52+
@action runLots() {
53+
const result = runLots(this.id);
54+
55+
this.data = result.data;
56+
this.id = result.id;
57+
this.selected = undefined;
58+
}
59+
60+
@action clear() {
61+
this.data = [];
62+
this.selected = undefined;
63+
}
64+
65+
@action swapRows() {
66+
this.data = swapRows(this.data);
67+
}
68+
69+
@action remove({id}) {
70+
this.data = deleteRow(this.data, id);
71+
this.selected = undefined;
72+
}
73+
74+
@action select({id}) {
75+
this.selected = id;
76+
}
77+
78+
<template>
79+
<div class="jumbotron">
80+
<div class="row">
81+
<div class="col-md-6">
82+
<h1>Ember</h1>
83+
</div>
84+
<div class="col-md-6">
85+
<div class="row">
86+
<div class="col-sm-6 smallpad">
87+
<BsButton id="run" {{on 'click' this.create}}>
88+
Create 1,000 rows
89+
</BsButton>
90+
</div>
91+
<div class="col-sm-6 smallpad">
92+
<BsButton id="runlots" {{on 'click' this.runLots}}>
93+
Create 10,000 rows
94+
</BsButton>
95+
</div>
96+
<div class="col-sm-6 smallpad">
97+
<BsButton id="add" {{on 'click' this.add}}>
98+
Append 1,000 rows
99+
</BsButton>
100+
</div>
101+
<div class="col-sm-6 smallpad">
102+
<BsButton id="update" {{on 'click' this.update}}>
103+
Update every 10th row
104+
</BsButton>
105+
</div>
106+
<div class="col-sm-6 smallpad">
107+
<BsButton id="clear" {{on 'click' this.clear}}>
108+
Clear
109+
</BsButton>
110+
</div>
111+
<div class="col-sm-6 smallpad">
112+
<BsButton id="swaprows" {{on 'click' this.swapRows}}>
113+
Swap Rows
114+
</BsButton>
115+
</div>
116+
</div>
117+
</div>
118+
</div>
119+
</div>
120+
121+
{{#if this.data.length}}
122+
<table class="table table-hover table-striped test-data">
123+
<tbody>
124+
{{#each this.data key="id" as |item|}}
125+
<tr class={{if (eq item) 'danger'}}>
126+
<td class="col-md-1">{{item.id}}</td>
127+
<td class="col-md-4"><a {{on 'click' (fn this.select item)}}>{{item.label}}</a></td>
128+
<td class="col-md-1"><a {{on 'click' (fn this.remove item)}}><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td>
129+
<td class="col-md-6"></td>
130+
</tr>
131+
{{/each}}
132+
</tbody>
133+
</table>
134+
{{/if}}
135+
136+
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
137+
</template>
138+
}

frameworks/keyed/ember/app/components/my-table.hbs

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

frameworks/keyed/ember/app/components/my-table.js

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

0 commit comments

Comments
 (0)