rawmodel/framework

before and after hooks

xpepermint opened this issue · 3 comments

We could add beforeAction and afterAction hooks for instanceMethods.

Sounds good :)

Syntax proposal:

export const hooks = [
  {
    instanceMethods: ['save'],
    classMethods: ['create'],
    async beforeAction (next) {
      // do something
      return await next();
    },
    async afterAction (action) {
      // do something
      return await next();
    }
  }
];

export const schema = new Schema({
  ...
  hooks
});

I think that hooks add too much magic thus your code gets less understandable. I'll close this request for now.