export default class FooService {
static instance;
constructor() {
if (instance) {
return instance;
}
this.instance = this;
}
loadFoo() {
return fetch();
}
getFoo(forceReload) {
if (this.foo && !forceReload) {
return Promise.resolve(this.foo);
}
return this.loadFoo()
.then(foo => this.foo = foo)
.then(() => this.foo);
}
}
Add a code snippet to your website: www.paste.org