Search…
⌃K

Writing your own features

As I mentioned the feature is a simple function which returns ResourceOptions. Simple as that.
But since features can be chained they also take ResourceOptions generated by the previous features as a parameter.
Simple feature implementation (idea):
const feature = (prevResourceOptions) {
return {
...prevResourceOptions,
actions: {
...prevResourceOptions.actions,
edit: {
...(prevResourceOptions.actions && prevResourceOptions.actions.edit),
//..
}
//..
}
}
}
export { feature }
As you can see, in the example above, that you have to take care of merging previous options, which could be problematic. Fortunately AdminJS gives you the helper functions for that:
This is how a feature could look when we use buildFeature function:
const { buildFeature } = require('adminjs')
const feature = buildFeature({
actions: {
before: myBeforeHook
}
})