Add object interceptor API to allow missing model and missing my-items handling (#3522)

* Extends Object API to allow adding interceptors

Co-authored-by: Andrew Henry <akhenry@gmail.com>
This commit is contained in:
Shefali Joshi
2020-11-30 10:50:24 -08:00
committed by GitHub
parent 176226ddef
commit 9da750c3bb
10 changed files with 242 additions and 3 deletions

View File

@@ -26,6 +26,7 @@ define([
'./MutableObject',
'./RootRegistry',
'./RootObjectProvider',
'./InterceptorRegistry',
'EventEmitter'
], function (
_,
@@ -33,6 +34,7 @@ define([
MutableObject,
RootRegistry,
RootObjectProvider,
InterceptorRegistry,
EventEmitter
) {
@@ -48,6 +50,7 @@ define([
this.rootRegistry = new RootRegistry();
this.rootProvider = new RootObjectProvider.default(this.rootRegistry);
this.cache = {};
this.interceptorRegistry = new InterceptorRegistry.default();
}
/**
@@ -177,6 +180,10 @@ define([
return objectPromise.then(result => {
delete this.cache[keystring];
const interceptors = this.listGetInterceptors(identifier, result);
interceptors.forEach(interceptor => {
result = interceptor.invoke(identifier, result);
});
return result;
});
@@ -312,6 +319,27 @@ define([
});
};
/**
* Register an object interceptor that transforms a domain object requested via module:openmct.ObjectAPI.get
* The domain object will be transformed after it is retrieved from the persistence store
* The domain object will be transformed only if the interceptor is applicable to that domain object as defined by the InterceptorDef
*
* @param {module:openmct.InterceptorDef} interceptorDef the interceptor definition to add
* @method addGetInterceptor
* @memberof module:openmct.InterceptorRegistry#
*/
ObjectAPI.prototype.addGetInterceptor = function (interceptorDef) {
this.interceptorRegistry.addInterceptor(interceptorDef);
};
/**
* Retrieve the interceptors for a given domain object.
* @private
*/
ObjectAPI.prototype.listGetInterceptors = function (identifier, object) {
return this.interceptorRegistry.getInterceptors(identifier, object);
};
/**
* Uniquely identifies a domain object.
*