Welcome, guest! Login / Register - Why register?

Paste

Pasted as JavaScript by x ( 3 years ago )
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);
    }

}

 

Revise this Paste

Your Name: Code Language: