feat: create bucket service to register, deregister and store breadcrumbs

This commit is contained in:
Jai Bhagat 2021-11-30 15:09:16 -05:00
parent 1887e34b75
commit 0ffd638d19
3 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1 @@
{{yield this.crumbs}}

View File

@ -0,0 +1,10 @@
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
export default class Breadcrumbs extends Component {
@service bucket;
get crumbs() {
return this.bucket.crumbs;
}
}

21
ui/app/services/bucket.js Normal file
View File

@ -0,0 +1,21 @@
import Service from '@ember/service';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { schedule } from '@ember/runloop';
export default class BucketService extends Service {
@tracked crumbs = [];
@action registerBreadcrumb(crumb) {
schedule('actions', this, () => {
console.log('register crumb: ', crumb);
this.crumbs = [...this.crumbs, crumb];
});
}
@action deregisterBreadcrumb(crumb) {
const newCrumbs = this.crumbs.filter(c => c !== crumb);
this.crumbs = newCrumbs;
}
}