Skip to content
This repository has been archived by the owner on Dec 14, 2019. It is now read-only.

Commit

Permalink
Closes #175 - beforeDestroy method returns a promise to allow animati…
Browse files Browse the repository at this point in the history
…ons to complete before the Node is removed
  • Loading branch information
Kyle Andrews committed Jun 17, 2019
1 parent 81cfa79 commit 8d327ff
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@

- Adds: better NPM package code splitting for Webpack [#177](https://github.com/Pageworks/papertrain/issues/177)
- Adds: adds base path config to the generator script [#176](https://github.com/Pageworks/papertrain/issues/176)
- Adds: the `beforeDestroy()` method returns a promise and doesn't remove the Node until the promise resolves [#175](https://github.com/Pageworks/papertrain/issues/175)

## 0.2.0 - 2019-06-10

Expand Down
4 changes: 0 additions & 4 deletions build-tools/generator/files/script.js
Expand Up @@ -21,10 +21,6 @@ export class REPLACE_ME extends Module{
afterMount(){

}

beforeDestroy(){

}
}

// Adds module to the global Modules object
Expand Down
4 changes: 0 additions & 4 deletions build-tools/generator/files/script.ts
Expand Up @@ -21,10 +21,6 @@ export class REPLACE_ME extends Module{
afterMount(){

}

beforeDestroy(){

}
}

// Adds module to the global Modules object
Expand Down
24 changes: 17 additions & 7 deletions utils/scripts/Application.ts
Expand Up @@ -119,13 +119,23 @@ export class Application{
const index = this.modules.indexOf(module);

/** Fire the before destroy event */
module.beforeDestroy();

/** Fire the destroy event */
module.destroy();

/** Splice the module from the array */
this.modules.splice(index, 1);
module.beforeDestroy().then(() => {
/** Fire the destroy event */
module.destroy();

/** Splice the module from the array */
this.modules.splice(index, 1);
})
.catch(e => {
if(Env.isDebug){
console.error('Something went wrong while destroying a module', e);
}
/** Fire the destroy event */
module.destroy();

/** Splice the module from the array */
this.modules.splice(index, 1);
});
}
});
}else{
Expand Down
4 changes: 3 additions & 1 deletion utils/scripts/Module.ts
Expand Up @@ -67,7 +67,9 @@ export class Module {
* Called by the runtime application before the module is destroyed.
* Used to remove event listeners and end infinite callbacks.
*/
public beforeDestroy():void{}
public beforeDestroy():Promise<unknown>{
return Promise.resolve();
}

/** Called by the runtime application when the module needs to be destroyed. */
public destroy():void{
Expand Down

0 comments on commit 8d327ff

Please sign in to comment.