imp: add willUpdateProps hook to components

This commit is contained in:
Géry Debongnie
2019-04-09 13:51:04 +02:00
parent 816ffe1b44
commit bc07c49a5f
3 changed files with 48 additions and 9 deletions
+12
View File
@@ -149,6 +149,17 @@ export class Component<
*/
mounted() {}
/**
* The willUpdateProps is an asynchronous hook, called just before new props
* are set. This is useful if the component needs some asynchronous task
* performed, depending on the props (for example, assuming that the props are
* some record Id, fetching the record data).
*
* This hook is not called during the first render (but willStart is called
* and performs a similar job).
*/
async willUpdateProps(nextProps: Props) {}
/**
* The willPatch hook is called just before the DOM patching process starts.
* It is not called on the initial render. This is useful to get some
@@ -350,6 +361,7 @@ export class Component<
//--------------------------------------------------------------------------
async _updateProps(nextProps: Props): Promise<void> {
await this.willUpdateProps(nextProps);
this.props = nextProps;
await this.render();
this.patched();