Pageworks / papertrain

Papertrain: a Craft CMS 3 framework
http://download.papertrain.io
MIT License
5 stars 2 forks source link

Promised Destruction #175

Closed codewithkyle closed 5 years ago

codewithkyle commented 5 years ago

The beforeDestroy() method should return a promise that always resolves. By default the beforeDestroy() method should not be defined in any new JavaScript/TypeScript files and the default defined on the base Module class should be:

public beforeDestroy():Promise<unknown>{
    return Promise.resolve();
}

That way when we need to actually do something (such as an animation) we can allow the developer to do what they need to do before resolving the promise, see example below.

beforeDestroy(){
    return new Promise((resolve)=>{
        anime({
            targets: this.view,
            duration: 175,
            easing: Env.EASING.out,
            opacity: [1, 0],
            scale: [1, 0.87],
            complete: ()=>{
                resolve();
            }
        });
    });
}