2018-01-29 11:37:54 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2018-01-29 11:37:54 +00:00
|
|
|
exports.getFinalState = function(ctx) {
|
|
|
|
if (ctx.isNewInstance)
|
|
|
|
return ctx.instance;
|
2018-11-20 09:32:54 +00:00
|
|
|
if (ctx.currentInstance) {
|
2018-01-29 11:37:54 +00:00
|
|
|
return Object.assign({},
|
|
|
|
ctx.currentInstance.__data,
|
|
|
|
ctx.data || ctx.instance
|
|
|
|
);
|
2018-11-20 09:32:54 +00:00
|
|
|
}
|
2018-01-29 11:37:54 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2018-01-29 11:37:54 +00:00
|
|
|
exports.isMultiple = function(ctx) {
|
|
|
|
return !ctx.isNewInstance && !ctx.currentInstance;
|
|
|
|
};
|