TransformOperation.js
/**
* @copyright 2018 Tridium, Inc. All Rights Reserved.
* @author Logan Byam
*/
/**
* @module nmodule/export/rc/TransformOperation
*/
define([ 'Promise' ], function (Promise) {
'use strict';
/**
* API Status: **Development**
*
* A TransformOperation encapsulates the lifecycle of transforming an object
* into data, and sending that data to a destination.
*
* @class
* @alias module:nmodule/export/rc/TransformOperation
*/
class TransformOperation {
/**
* @param {module:nmodule/export/rc/Transformer} transformer the transformer that will perform the transform operation
* @param {*} object the object to be transformed
*/
constructor(transformer, object) {
this.$transformer = transformer;
this.$transformedObject = object;
}
/**
* @returns {module:nmodule/export/rc/Transformer} the transformer that will perform the transform operation
*/
getTransformer() {
return this.$transformer;
}
/**
* @returns {*} the object to be transformed
*/
getTransformedObject() {
return this.$transformedObject;
}
/**
* @param {object} cx transform context. This will be passed to the {@link module:nmodule/export/rc/Transformer#transform transform()} method.
* @returns {Promise}
*/
doTransform(cx) {
return Promise.resolve(
this.getTransformer().transform(this.getTransformedObject(), cx));
}
/**
* @returns {String} the display name to be shown to the user to allow him or her to choose to perform this transform operation
*/
getDisplayName() {
return this.$transformer.getDisplayName();
}
}
return TransformOperation;
});