Parse-server: Adding multiple Hooks for the same class

Created on 26 Nov 2016  路  4Comments  路  Source: parse-community/parse-server

How to reproduce

  1. Add two (or more) beforeSave hooks for the same class:
Parse.Cloud.beforeSave('TestClass', (req, res) => {
  console.log('Test');
  res.success();
});

Parse.Cloud.beforeSave('TestClass', (req, res) => {
  console.log('Test 2');
  res.success();
});
  1. Save some object of this class

Expected outcome:
Two console logs - Test and Test2

Actual outcome:
Only one console log of last added hook - Test2

So is it not possible to have multiple hooks for the same object?

All 4 comments

Why would you like to do that anyways?

@jonas-db - Why old 'event' is deleted when I add new one? It's like removing all click events on page, when adding new one.

I add beforeSave event from more than one place in my codebase.

Those are not events, but hooks. Only the last one will be processed.

And no, this is not possible also, that prevents aweful side effects as you can't really guarantee the order of execution

Was this page helpful?
0 / 5 - 0 ratings