Validation and hooks
Overview
It is possible to add hooks in various stages of the saving process. There are three general hooks in addition to the more special validation. All hooks must return a Promise()
that is either resolved or rejected by the hook. Any reject()
will cancel the process and show an error message to the user.
Any plugin can provide hooks or validation. The order of multiple hooks in the same stage is not guaranteed so no assumption should be made on the execution order.
All plugins must register their hooks and validations in PluginPackage.js
when the plugin registers.
The general stages of the saving process is
Before Validation hooks
Validation
Before save hooks
Saving...
After save hooks
Before validation
In the before validation hooks it is allowed to alter the article programmatically through the API. This is useful if you want to change something automatically before the validation and saving process continues.
Validation
These are not technically hooks. The NPWriter executes one or many provided validation methods. These methods add messages, warnings and errors which are then presented to the user. Any error message will stop the process.
Before save hook
Before save hooks are executed After potential changes of the article and when the valitation passed.
After save hook
When the article has been successfully saved the after save hooks are executed.
Example
A compact example with one hook of each type and a validation in one package file.
Last updated