2021-11-18 15:52:39 +00:00
|
|
|
import Component from '@glimmer/component';
|
2020-05-11 15:37:11 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2021-11-18 15:52:39 +00:00
|
|
|
|
2020-05-11 15:37:11 +00:00
|
|
|
import { fromPromise } from 'consul-ui/utils/dom/event-source';
|
|
|
|
|
2021-11-18 15:52:39 +00:00
|
|
|
// TODO: We could probably update this to be a template only component now
|
|
|
|
// rather than a JS only one.
|
|
|
|
export default class JWTSource extends Component {
|
|
|
|
@service('repository/oidc-provider') repo;
|
|
|
|
@service('dom') dom;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
2020-05-11 15:37:11 +00:00
|
|
|
if (this.source) {
|
|
|
|
this.source.close();
|
|
|
|
}
|
2021-11-18 15:52:39 +00:00
|
|
|
this._listeners = this.dom.listeners();
|
2020-05-11 15:37:11 +00:00
|
|
|
// TODO: Could this use once? Double check but I don't think it can
|
2021-11-18 15:52:39 +00:00
|
|
|
this.source = fromPromise(this.repo.findCodeByURL(this.args.src));
|
2020-05-11 15:37:11 +00:00
|
|
|
this._listeners.add(this.source, {
|
|
|
|
message: e => this.onchange(e),
|
|
|
|
error: e => this.onerror(e),
|
|
|
|
});
|
2021-11-18 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onchange(e) {
|
|
|
|
if(typeof this.args.onchange === 'function') {
|
|
|
|
this.args.onchange(...arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onerror(e) {
|
|
|
|
if(typeof this.args.onerror === 'function') {
|
|
|
|
this.args.onerror(...arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
willDestroy() {
|
|
|
|
super.willDestroy(...arguments);
|
|
|
|
if (this.source) {
|
|
|
|
this.source.close();
|
|
|
|
}
|
|
|
|
this.repo.close();
|
|
|
|
this._listeners.remove();
|
|
|
|
}
|
|
|
|
}
|