Simplifies using an ILookupDecorator.
Remarks
This class provides methods that help in performing common tasks related to decorating the lookup method for a certain TDecoratedType
:
- Set a single implementation
- Set a factory that creates item-specific implementations
- Wrap the default implementation
- Hide the default implementation
Each of these methods adds a new IContextLookupChainLink to the lookup chain which adds the wanted behavior. The link can be removed again by either calling the removeLookup method on the decorator or by calling the remove method on the parent decorator, e.g. the NodeDecorator.
Typically, one does not create instances of this class but uses the item specific implementations provided by GraphDecorator: nodeDecorator, edgeDecorator, labelDecorator, portDecorator, and bendDecorator.
Examples
Type Parameters
- TDecoratedType
- The type of the instances whose
behavior should be modified. - TInterface
- The interface or type that clients will use during the
call. Note that this is normally an interface and not the implementation of the interface since client code will use the interface for the query.
Type Details
- yfiles module
- view-component
- yfiles-umd modules
- All view modules
- Legacy UMD name
- yfiles.graph.LookupDecorator
See Also
Constructors
LookupDecorator
(decoratedType: Class, interfaceType: Class, decorator: ILookupDecorator, decorateNulls: boolean, nullIsFallback: boolean)Initializes a new instance of the LookupDecorator<TDecoratedType,TInterface> class.
Parameters
A map of options to pass to the method.
- decoratedType - Class
- The type of the instances whose lookup behavior should be modified.
- interfaceType - Class
- The interface or type that clients will use during the lookup call. Note that this is normally an interface and not the implementation of the interface since client code will use the interface for the query.
- decorator - ILookupDecorator
- The decorator instance that will be used to extend the Lookup mechanism.
- decorateNulls - boolean
- The initial value of the decorateNulls property.
- nullIsFallback - boolean
- The initial value of the nullIsFallback property.
Properties
Gets or sets a value indicating whether the setImplementationWrapper methods will wrap null
values from the rest of the lookup chain or those values will simply be returned instead.
Remarks
If this is false
, then the SetImplementationWrapper methods will not wrap null
values from the rest of the lookup chain and the result of the call to lookup will simply be null
. If this is true
, the wrapper will get null
as the implementation to wrap and should handle this accordingly.
Note that changing this value does not affect wrappers which are already set. Changing the value will only affect wrappers which are set after the change.
Examples
/**
* @param {!INode} node1
* @param {!INode} node2
* @param {!IGraph} graph
*/
function decorateNulls(node1, node2, graph) {
// let's assume for this example, that node1's lookup returns an implementation by default
// and node2's lookup returns null
let provider1 = node1.lookup(INodeSizeConstraintProvider.$class) // not null
let provider2 = node2.lookup(INodeSizeConstraintProvider.$class) // null
// set the decorator to wrap null values and wrap the default size constraint provider
const decorator =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator
decorator.decorateNulls = true
decorator.setImplementationWrapper(
(node, provider) => new SizeConstraintProviderWrapper(node, provider)
)
// a SizeConstraintProviderWrapper which wraps the default
provider1 = node1.lookup(INodeSizeConstraintProvider.$class)
// a SizeConstraintProviderWrapper which wraps null
provider2 = node2.lookup(INodeSizeConstraintProvider.$class)
}
/**
* @param {!INode} node1
* @param {!INode} node2
* @param {!IGraph} graph
*/
function dontDecorateNulls(node1, node2, graph) {
let provider1
let provider2
// let's assume for this example, that node1's lookup returns an implementation by default
// and node2's lookup returns null
provider1 = node1.lookup(INodeSizeConstraintProvider.$class) // not null
provider2 = node2.lookup(INodeSizeConstraintProvider.$class) // null
// set the decorator not to wrap null values and wrap the default size constraint provider
const decorator =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator
decorator.decorateNulls = false
decorator.setImplementationWrapper(
(node, provider) => new SizeConstraintProviderWrapper(node, provider)
)
// a SizeConstraintProviderWrapper which wraps the default
provider1 = node1.lookup(INodeSizeConstraintProvider.$class) // not null
provider2 = node2.lookup(INodeSizeConstraintProvider.$class) // null
}
function decorateNulls(node1: INode, node2: INode, graph: IGraph): void {
// let's assume for this example, that node1's lookup returns an implementation by default
// and node2's lookup returns null
let provider1: INodeSizeConstraintProvider = node1.lookup(
INodeSizeConstraintProvider.$class
)! // not null
let provider2: INodeSizeConstraintProvider | null = node2.lookup(
INodeSizeConstraintProvider.$class
) // null
// set the decorator to wrap null values and wrap the default size constraint provider
const decorator =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator
decorator.decorateNulls = true
decorator.setImplementationWrapper(
(node: INode | null, provider: INodeSizeConstraintProvider | null) =>
new SizeConstraintProviderWrapper(node, provider)
)
// a SizeConstraintProviderWrapper which wraps the default
provider1 = node1.lookup(INodeSizeConstraintProvider.$class)!
// a SizeConstraintProviderWrapper which wraps null
provider2 = node2.lookup(INodeSizeConstraintProvider.$class)
}
function dontDecorateNulls(node1: INode, node2: INode, graph: IGraph): void {
let provider1: INodeSizeConstraintProvider
let provider2: INodeSizeConstraintProvider | null
// let's assume for this example, that node1's lookup returns an implementation by default
// and node2's lookup returns null
provider1 = node1.lookup(INodeSizeConstraintProvider.$class)! // not null
provider2 = node2.lookup(INodeSizeConstraintProvider.$class) // null
// set the decorator not to wrap null values and wrap the default size constraint provider
const decorator =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator
decorator.decorateNulls = false
decorator.setImplementationWrapper(
(node: INode | null, provider: INodeSizeConstraintProvider | null) =>
new SizeConstraintProviderWrapper(node, provider)
)
// a SizeConstraintProviderWrapper which wraps the default
provider1 = node1.lookup(INodeSizeConstraintProvider.$class)! // not null
provider2 = node2.lookup(INodeSizeConstraintProvider.$class) // null
}
See Also
Gets the ILookupDecorator instance that is used.
Remarks
null
. In this case all methods of this class do nothing.Gets or sets a value indicating whether a null
result value of the setFactory methods should be interpreted as taking the fallback value, or actually return null
.
Remarks
If this is true
, then null
values returned from the factory set with setFactory are not returned, but rather interpreted as a hint to query the rest of the lookup chain. If this is false
, then null
values are returned as is.
Changing this value only affects decorations which are set after the change. Existing decorations remain unaffected.
Examples
/**
* @param {!INode} node
* @param {!IGraph} graph
*/
function nullIsFallback(node, graph) {
// set to return the fallback if the decoration returns null and set a factory which returns always null
const decorator =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator
decorator.nullIsFallback = true
decorator.setFactory((n) => null)
// the default INodeSizeConstraintProvider implementation
const provider = node.lookup(INodeSizeConstraintProvider.$class)
}
/**
* @param {!INode} node
* @param {!IGraph} graph
*/
function nullIsNotFallback(node, graph) {
// set the decorator to always use the returned value, even if its null and set a factory which returns always null
const decorator =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator
decorator.nullIsFallback = false
decorator.setFactory((n) => null)
const provider = node.lookup(INodeSizeConstraintProvider.$class) // null
}
function nullIsFallback(node: INode, graph: IGraph): void {
// set to return the fallback if the decoration returns null and set a factory which returns always null
const decorator =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator
decorator.nullIsFallback = true
decorator.setFactory((n: INode) => null)
// the default INodeSizeConstraintProvider implementation
const provider = node.lookup(INodeSizeConstraintProvider.$class)
}
function nullIsNotFallback(node: INode, graph: IGraph): void {
// set the decorator to always use the returned value, even if its null and set a factory which returns always null
const decorator =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator
decorator.nullIsFallback = false
decorator.setFactory((n: INode) => null)
const provider = node.lookup(INodeSizeConstraintProvider.$class) // null
}
See Also
Methods
Tries to add the provided chain link to the decorator.
Parameters
A map of options to pass to the method.
- lookup - IContextLookupChainLink
- The link to add.
Returns
See Also
Sets the lookup of all TDecoratedType
items matching a predicate
to return null
if TInterface
is queried during the lookup.
Remarks
This can be used to temporarily or permanently disable a certain behavior for all items. To do this only for items matching a predicate, use hideImplementation instead.
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's (e.g. NodeDecorator remove method.
Parameters
A map of options to pass to the method.
- predicate - function(TDecoratedType):boolean
- The predicate that determines for which items the implementation shall be hidden.
Signature Details
function(obj: TDecoratedType) : boolean
Represents the method that defines a set of criteria and determines whether the specified object meets those criteria.Parameters
- obj - TDecoratedType
- The object to compare against the criteria defined within the method represented by this delegate.
Returns
- boolean
true
if obj meets the criteria defined within the method represented by this delegate; otherwise,false
.
Returns
- ↪IContextLookupChainLink
- An IContextLookupChainLink that has been added to the decorator as a result of this call, or
null
if decoration was unsuccessful.
Examples
This method can be used to disable the default behavior by hiding the default implementation returned by the lookup. The following example prevents all nodes from being moved by hiding their position handler:
graph.decorator.nodeDecorator.positionHandlerDecorator.hideImplementation()
The following example prevents only nodes with a tag from being moved:
graph.decorator.nodeDecorator.positionHandlerDecorator.hideImplementation(
(node) => node.tag !== null
)
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's (e.g. NodeDecorator remove method:
constructor() {}
/**
* @param {!IGraph} graph
*/
registerLookup(graph) {
this.chainLink =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.hideImplementation()
}
/**
* @param {!IGraph} graph
*/
deregisterLookup(graph) {
graph.decorator.nodeDecorator.remove(this.chainLink)
}
constructor() {}
registerLookup(graph: IGraph): void {
this.chainLink =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.hideImplementation()!
}
deregisterLookup(graph: IGraph): void {
graph.decorator.nodeDecorator.remove(this.chainLink)
}
See Also
setFactory
(predicate: function(TDecoratedType):boolean, factory: function(TDecoratedType):TInterface) : IContextLookupChainLinkSets the lookup of items matching a predicate
with a factory
that creates a TInterface
instance if TInterface
is queried during the lookup.
Remarks
This can be used to modify the lookup of all items matching a certain predicate where the returned instance either depends on the item or uses it in some way.
To adjust the lookup of all items in this manner, use setFactory instead. To adjust the lookup of a single item, use setImplementation.
Note that depending on the value of the nullIsFallback property a null
return value from the factory
will be either returned directly, or interpreted as a hint to return a fallback value which is obtained by querying the remainder of the lookup chain.
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's (e.g. NodeDecorator remove method.
Parameters
A map of options to pass to the method.
- predicate - function(TDecoratedType):boolean
- The predicate that determines for which items the factory shall be called.
Signature Details
function(obj: TDecoratedType) : boolean
Represents the method that defines a set of criteria and determines whether the specified object meets those criteria.Parameters
- obj - TDecoratedType
- The object to compare against the criteria defined within the method represented by this delegate.
Returns
- boolean
true
if obj meets the criteria defined within the method represented by this delegate; otherwise,false
.
- factory - function(TDecoratedType):TInterface
- The factory that is queried to create the result.
Signature Details
function(arg: TDecoratedType) : TInterface
Encapsulates a method that has one parameters and returns a value of the type specified by theTResult
parameter.Parameters
- arg - TDecoratedType
- The parameter of the method that this delegate encapsulates.
Returns
- TInterface
- The return value of the method that this delegate encapsulates.
Returns
- ↪IContextLookupChainLink
- An IContextLookupChainLink that has been added to the decorator as a result of this call, or
null
if decoration was unsuccessful.
Examples
The following example shows how to decorate the lookup to create different instances for different types of nodes when queried. The example creates a red selection decorator for nodes with tag "type 1", a blue one for nodes with tag "type 2", and the default for all other nodes.
graph.decorator.nodeDecorator.selectionDecorator.setFactory(
(node) => node.tag === 'type 1',
(node) => new RedSelectionInstaller(node)
)
graph.decorator.nodeDecorator.selectionDecorator.setFactory(
(node) => node.tag === 'type 2',
(node) => new BlueSelectionInstaller(node)
)
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's (e.g. NodeDecorator remove method:
/**
* @param {!IGraph} graph
*/
registerLookup(graph) {
this.chainLink =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setFactory(
(node) => new CustomSizeConstraintProvider(node)
)
}
/**
* @param {!IGraph} graph
*/
deregisterLookup(graph) {
graph.decorator.nodeDecorator.remove(this.chainLink)
}
registerLookup(graph: IGraph): void {
this.chainLink =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setFactory(
(node) => new CustomSizeConstraintProvider(node)
)!
}
deregisterLookup(graph: IGraph): void {
graph.decorator.nodeDecorator.remove(this.chainLink)
}
See Also
Sets the lookup of all TDecoratedType
items, so that factory
is used to create a TInterface
instance if TInterface
is queried during the lookup.
Remarks
This can be used to modify the lookup of all items where the returned instance either depends on the item or uses it in some way.
To only adjust the lookup of items matching a predicate in this manner, use setFactory instead. To adjust the lookup of a single item, use setImplementation.
Note that depending on the value of the nullIsFallback property a null
return value from the factory
will be either returned directly, or interpreted as a hint to return a fallback value which is obtained by querying the remainder of the lookup chain.
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's (e.g. NodeDecorator remove method.
Parameters
A map of options to pass to the method.
- factory - function(TDecoratedType):TInterface
- The factory that is queried to create the result.
Signature Details
function(item: TDecoratedType) : TInterface
A function which provides a custom into a custom implementation ofTInterface
for the givenitem
.Parameters
- item - TDecoratedType
- The item to return the implementation for.
Returns
- TInterface
- The new implementation.
Returns
- ↪IContextLookupChainLink
- An IContextLookupChainLink that has been added to the decorator as a result of this call, or
null
if decoration was unsuccessful.
Examples
This method can be used for implementations which depend on the item they are queried from
graph.decorator.nodeDecorator.selectionDecorator.setFactory(
(node) => new RedSelectionInstaller(node)
)
The following example shows how to decorate the lookup to create different instances for different types of nodes when queried. The example creates a red selection decorator for nodes with tag "type 1", a blue one for nodes with tag "type 2", and the default for all other nodes.
graph.decorator.nodeDecorator.selectionDecorator.setFactory((node) => {
switch (node.tag) {
case 'type 1':
return new RedSelectionInstaller(node)
case 'type 2':
return new BlueSelectionInstaller(node)
default:
return null
}
})
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's (e.g. NodeDecorator remove method:
/**
* @param {!IGraph} graph
*/
registerLookup(graph) {
this.chainLink =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setFactory(
(node) => new CustomSizeConstraintProvider(node)
)
}
/**
* @param {!IGraph} graph
*/
deregisterLookup(graph) {
graph.decorator.nodeDecorator.remove(this.chainLink)
}
registerLookup(graph: IGraph): void {
this.chainLink =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setFactory(
(node) => new CustomSizeConstraintProvider(node)
)!
}
deregisterLookup(graph: IGraph): void {
graph.decorator.nodeDecorator.remove(this.chainLink)
}
See Also
Sets the lookup of the given item
to return the given TInterface
implementation
if TInterface
is queried on the item
's lookup.
Remarks
This can be used to modify the lookup of a single item only.
To adjust the lookup of all items matching a predicate, use setImplementation instead. To adjust the lookup of all items, use setImplementation.
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's (e.g. NodeDecorator remove.
Parameters
A map of options to pass to the method.
- item - TDecoratedType
- The item for which the implementation shall be returned.
- implementation - TInterface
- The implementation to return if
item
is queried forTInterface
.
Returns
- ↪IContextLookupChainLink
- An IContextLookupChainLink that has been added to the decorator as a result of this call, or
null
if decoration was unsuccessful.
Examples
The following example shows how to decorate the lookup to return different values for different nodes. Note that the decorations can be chained.
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementation(
node1,
new NodeSizeConstraintProvider(new Size(10, 10), new Size(100, 100))
)
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementation(
node2,
new NodeSizeConstraintProvider(new Size(20, 20), new Size(200, 200))
)
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's (e.g. NodeDecorator remove method:
constructor() {}
/**
* @param {!IGraph} graph
*/
registerLookup(graph) {
this.chainLink =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementation(
new ConstantSizeConstraintProvider()
)
}
/**
* @param {!IGraph} graph
*/
deregisterLookup(graph) {
graph.decorator.nodeDecorator.remove(this.chainLink)
}
constructor() {}
registerLookup(graph: IGraph): void {
this.chainLink =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementation(
new ConstantSizeConstraintProvider()
)!
}
deregisterLookup(graph: IGraph): void {
graph.decorator.nodeDecorator.remove(this.chainLink)
}
See Also
setImplementation
(predicate: function(TDecoratedType):boolean, implementation: TInterface) : IContextLookupChainLinkSets the lookup of all items of type TDecoratedType
which match a predicate
to return the given TInterface
implementation
if TInterface
is queried on an item's lookup.
Remarks
This can be used to modify the lookup of all items matching a certain predicate in the same way.
To adjust the lookup of only a single item, use setImplementation instead. To adjust the lookup of all items, use setImplementation.
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's (e.g. NodeDecorator remove method.
Parameters
A map of options to pass to the method.
- predicate - function(TDecoratedType):boolean
- A predicate that determines which items are affected.
Signature Details
function(obj: TDecoratedType) : boolean
Represents the method that defines a set of criteria and determines whether the specified object meets those criteria.Parameters
- obj - TDecoratedType
- The object to compare against the criteria defined within the method represented by this delegate.
Returns
- boolean
true
if obj meets the criteria defined within the method represented by this delegate; otherwise,false
.
- implementation - TInterface
- The implementation to return if the
predicate
matches andTInterface
is queried.
Returns
- ↪IContextLookupChainLink
- An IContextLookupChainLink that has been added to the decorator as a result of this call, or
null
if decoration was unsuccessful.
Examples
The following example shows how to decorate the lookup to return different values for different types of node (nodes with different tags in this example). Note that the decorations can be chained.
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementation(
(node) => node.tag === 'type 1',
new NodeSizeConstraintProvider(new Size(10, 10), new Size(100, 100))
)
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementation(
(node) => node.tag === 'type 2',
new NodeSizeConstraintProvider(new Size(20, 20), new Size(200, 200))
)
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's (e.g. NodeDecorator remove method:
constructor() {}
/**
* @param {!IGraph} graph
*/
registerLookup(graph) {
this.chainLink =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementation(
new ConstantSizeConstraintProvider()
)
}
/**
* @param {!IGraph} graph
*/
deregisterLookup(graph) {
graph.decorator.nodeDecorator.remove(this.chainLink)
}
constructor() {}
registerLookup(graph: IGraph): void {
this.chainLink =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementation(
new ConstantSizeConstraintProvider()
)!
}
deregisterLookup(graph: IGraph): void {
graph.decorator.nodeDecorator.remove(this.chainLink)
}
See Also
Sets the lookup of all items of type TDecoratedType
to return the given TInterface
implementation
if TInterface
is queried on an item's lookup.
Remarks
This can be used to modify the lookup of all items in the same way.
To adjust the lookup of only a single item, use setImplementation instead. To adjust the lookup of all items matching a certain predicate, use setImplementation.
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's (e.g. NodeDecorator remove method.
Parameters
A map of options to pass to the method.
- implementation - TInterface
- The implementation to return unconditionally.
Returns
- ↪IContextLookupChainLink
- An IContextLookupChainLink that has been added to the decorator as a result of this call, or
null
if decoration was unsuccessful.
Examples
The following example shows how to decorate the lookup to return a constant value for all nodes:
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementation(
new ConstantSizeConstraintProvider()
)
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's (e.g. NodeDecorator remove method:
constructor() {}
/**
* @param {!IGraph} graph
*/
registerLookup(graph) {
this.chainLink =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementation(
new ConstantSizeConstraintProvider()
)
}
/**
* @param {!IGraph} graph
*/
deregisterLookup(graph) {
graph.decorator.nodeDecorator.remove(this.chainLink)
}
constructor() {}
registerLookup(graph: IGraph): void {
this.chainLink =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementation(
new ConstantSizeConstraintProvider()
)!
}
deregisterLookup(graph: IGraph): void {
graph.decorator.nodeDecorator.remove(this.chainLink)
}
See Also
setImplementationWrapper
(predicate: function(TDecoratedType):boolean, factory: function(TDecoratedType, TInterface):TInterface) : IContextLookupChainLinkSets the lookup of items matching a predicate
with a factory
callback that wraps the underlying implementation if TInterface
is queried during the lookup.
Remarks
This can be used to modify the lookup of all items matching a certain predicate where the factory implementation may delegate to the wrapped implementation in certain cases.
To adjust the lookup for all items in this manner, use setImplementationWrapper instead. To adjust the lookup of a single item, use setImplementation.
Note that depending on the value of the decorateNulls property, the factory will not be called to decorate null
results.
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's (e.g. NodeDecorator remove method.
Parameters
A map of options to pass to the method.
- predicate - function(TDecoratedType):boolean
- The predicate that determines for which items the wrapping shall be performed.
Signature Details
function(obj: TDecoratedType) : boolean
Represents the method that defines a set of criteria and determines whether the specified object meets those criteria.Parameters
- obj - TDecoratedType
- The object to compare against the criteria defined within the method represented by this delegate.
Returns
- boolean
true
if obj meets the criteria defined within the method represented by this delegate; otherwise,false
.
- factory - function(TDecoratedType, TInterface):TInterface
- The factory that will be passed the underlying implementation and that is queried to create the result.
Signature Details
function(arg1: TDecoratedType, arg2: TInterface) : TInterface
Encapsulates a method that has two parameters and returns a value of the type specified by theTResult
parameter.Parameters
- arg1 - TDecoratedType
- The first parameter of the method that this delegate encapsulates.
- arg2 - TInterface
- The second parameter of the method that this delegate encapsulates.
Returns
- TInterface
- The return value of the method that this delegate encapsulates.
Returns
- ↪IContextLookupChainLink
- An IContextLookupChainLink that has been added to the decorator as a result of this call, or
null
if decoration was unsuccessful.
Examples
This method can be used for implementations which wrap the default implementation
graph.decorator.nodeDecorator.positionHandlerDecorator.setImplementationWrapper(
(node) => node.tag !== null,
(node, original) => new ConstrainedPositionHandlerWrapper(original, node)
)
graph.decorator.nodeDecorator.positionHandlerDecorator.setImplementationWrapper(
(node) => node.tag !== null,
(node, original) => new ConstrainedPositionHandlerWrapper(original!, node!)
)
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's (e.g. NodeDecorator remove method:
constructor() {}
/**
* @param {!IGraph} graph
*/
registerLookup(graph) {
this.chainLink =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementationWrapper(
(node, provider) => new SizeConstraintProviderWrapper(node, provider)
)
}
/**
* @param {!IGraph} graph
*/
deregisterLookup(graph) {
graph.decorator.nodeDecorator.remove(this.chainLink)
}
constructor() {}
registerLookup(graph: IGraph): void {
this.chainLink =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementationWrapper(
(node, provider) => new SizeConstraintProviderWrapper(node, provider)
)!
}
deregisterLookup(graph: IGraph): void {
graph.decorator.nodeDecorator.remove(this.chainLink)
}
See Also
setImplementationWrapper
(factory: function(TDecoratedType, TInterface):TInterface) : IContextLookupChainLinkSets the lookup of all items with a factory
callback that wraps the underlying implementation if TInterface
is queried during the lookup.
Remarks
This can be used to modify the lookup of all items matching where the factory implementation may delegate to the wrapped implementation in certain cases.
To adjust the lookup in this manner only for items matching a predicate, use setImplementationWrapper instead. To adjust the lookup of a single item, use setImplementation.
Note that depending on the value of the decorateNulls property, the factory will not be called to decorate null
results.
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's (e.g. NodeDecorator remove method.
Parameters
A map of options to pass to the method.
- factory - function(TDecoratedType, TInterface):TInterface
- The factory that will be passed the underlying implementation and that is queried to create the result.
Signature Details
function(item: TDecoratedType, originalImplementation: TInterface) : TInterface
A function which wraps theoriginalImplementation
ofTInterface
into a custom implementation for the givenitem
.Parameters
- item - TDecoratedType
- The item to return the wrapped implementation for.
- originalImplementation - TInterface
- The original implementation to wrap.
Returns
- TInterface
- The new implementation.
Returns
- ↪IContextLookupChainLink
- An IContextLookupChainLink that has been added to the decorator as a result of this call, or
null
if decoration was unsuccessful.
Examples
This method can be used for implementations which wrap the default implementation
graph.decorator.nodeDecorator.positionHandlerDecorator.setImplementationWrapper(
(node, original) => new ConstrainedPositionHandlerWrapper(original, node)
)
graph.decorator.nodeDecorator.positionHandlerDecorator.setImplementationWrapper(
(node, original) => new ConstrainedPositionHandlerWrapper(original!, node!)
)
The effects of this method call can be undone by passing the return value to removeLookup or to the containing decorator's (e.g. NodeDecorator remove method:
constructor() {}
/**
* @param {!IGraph} graph
*/
registerLookup(graph) {
this.chainLink =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementationWrapper(
(node, provider) => new SizeConstraintProviderWrapper(node, provider)
)
}
/**
* @param {!IGraph} graph
*/
deregisterLookup(graph) {
graph.decorator.nodeDecorator.remove(this.chainLink)
}
constructor() {}
registerLookup(graph: IGraph): void {
this.chainLink =
graph.decorator.nodeDecorator.sizeConstraintProviderDecorator.setImplementationWrapper(
(node, provider) => new SizeConstraintProviderWrapper(node, provider)
)!
}
deregisterLookup(graph: IGraph): void {
graph.decorator.nodeDecorator.remove(this.chainLink)
}