salix/loopback/util/hook.js

30 lines
704 B
JavaScript
Raw Normal View History

2018-12-27 11:54:16 +00:00
/**
* Computes the final instance state after hook is executed.
*
* @param {Object} ctx The hook context
* @return {Object} The final instance state
*/
exports.getFinalState = function(ctx) {
if (ctx.isNewInstance)
return ctx.instance;
if (ctx.currentInstance) {
return Object.assign({},
ctx.currentInstance.__data,
ctx.data || ctx.instance
);
}
return null;
};
2018-12-27 11:54:16 +00:00
/**
* Determines if hook is affecting multiple instances.
*
* @param {Object} ctx The hook context
* @return {Boolean} %true for multiple instances, %false otherwhise
*/
exports.isMultiple = function(ctx) {
return !ctx.isNewInstance && !ctx.currentInstance;
};