Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyongqiang committed Feb 29, 2024
1 parent 01f67ad commit 57eb974
Show file tree
Hide file tree
Showing 11 changed files with 21,954 additions and 26,902 deletions.
53 changes: 53 additions & 0 deletions app/components/task-list/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { A } from '@ember/array';
import { run, schedule } from '@ember/runloop';
import { action } from '@ember/object';

interface TaskListSignature {
// The arguments accepted by the component
Args: {};
// Any blocks yielded by the component
Blocks: {
default: [];
};
// The element to which `...attributes` is applied in the component template
Element: null;
}

export default class TaskListComponent extends Component<TaskListSignature> {
@tracked model: number[] = [];

constructor() {
super(...arguments);
// this.model used in component TaskListComponent, but it had already been used previously in the same computation
// 如果这调用
// this.loadTask();
}

@action
reloadTask() {
console.log('reload task fire');
this.loadTask();
// schedule('afterRender', () => {
// this.loadTask();
// });
}

@action
loadTask() {
console.log('load task fire');
const task = [];
console.log(this.model);
for (let index = 0; index < 10; index++) {
const num = index * Math.random() * 10;
task.push(num);
}
this.model = [...task];
}

willDestroy(): void {
super.willDestroy(...arguments);
console.log('willdestroy');
}
}
6 changes: 6 additions & 0 deletions app/components/task-list/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div {{did-update this.reloadTask @tag}} ></div>
<div {{did-insert this.loadTask}}>
{{#each this.model as |item|}}
<div>{{item}}</div>
{{/each}}
</div>
6 changes: 6 additions & 0 deletions app/controllers/task.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Controller from '@ember/controller';

export default class TaskController extends Controller {
queryParams = ['tag'];
tag = null;
}
1 change: 1 addition & 0 deletions app/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export default class Router extends EmberRouter {
Router.map(function () {
this.route('about');
this.route('concact', { path: '/getting-in-touch' });
this.route('task');
});
4 changes: 4 additions & 0 deletions app/routes/task.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Route from '@ember/routing/route';

export default class TaskRoute extends Route {
}
14 changes: 14 additions & 0 deletions app/templates/task.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<ul>
<li>
<LinkTo @route="task" @query={{hash tag="tag1"}}>tag1</LinkTo>
</li>
<li>
<LinkTo @route="task" @query={{hash tag="tag2"}}>tag2</LinkTo>
</li>
</ul>

<span>{{this.tag}}</span>

{{!-- {{component "task-list" tag=this.tag}} --}}

<TaskList @tag={{this.tag}} />
Loading

0 comments on commit 57eb974

Please sign in to comment.