As you can see, in the example above you have to take care of merging previous options, which could be problematic. Fortunately AdminJS gives you helper functions which help with this:
a factory function ,
optional helper (when you need more control)
import { buildFeature, FeatureType } from 'adminjs';
import SomeModel from 'some-model.entity.js';
const someBeforeHook = () => { /* noop */ };
const myFeature = (config = {}): FeatureType => {
// do something with your feature config?
return buildFeature({
actions: {
edit: {
before: [someBeforeHook],
},
}
});
}
const SomeResource: ResourceWithOptions = {
resource: SomeModel,
features: [myFeature({})],
};
/* "someBeforeHook" will be used as a "before" hook in "edit" actions
for every resource where "myFeature" is added */
This is how a feature could look like when is used: