Skip to content

StateComponentMapping

ctreffs edited this page Oct 8, 2020 · 1 revision

StateComponentMapping

Used by the EntityState class to create the mappings of components to providers via a fluent interface.

public class StateComponentMapping

Methods

withInstance(_:)

Creates a mapping for the component type to a specific component instance. A ComponentInstanceProvider is used for the mapping.

@discardableResult public func withInstance(_ component: Component) -> StateComponentMapping

Parameters

  • component: The component instance to use for the mapping

Returns

This ComponentMapping, so more modifications can be applied

withType(_:)

Creates a mapping for the component type to new instances of the provided type. The type should be the same as or extend the type for this mapping. A ComponentTypeProvider is used for the mapping.

@discardableResult public func withType(_ type: ComponentInitializable.Type) -> Self

Parameters

  • type: The type of components to be created by this mapping

Returns

This ComponentMapping, so more modifications can be applied

withSingleton(_:)

Creates a mapping for the component type to a single instance of the provided type. The instance is not created until it is first requested. The type should be the same as or extend the type for this mapping. A ComponentSingletonProvider is used for the mapping.

@discardableResult public func withSingleton(_ type: ComponentInitializable.Type?) -> Self

Parameters

  • type: The type of the single instance to be created. If omitted, the type of the mapping is used.

Returns

This ComponentMapping, so more modifications can be applied

withMethod(_:)

Creates a mapping for the component type to a method call. A DynamicComponentProvider is used for the mapping.

@discardableResult public func withMethod<C: Component>(_ closure: DynamicComponentProvider<C>.Closure) -> Self

Parameters

  • closure: The Closure instance to return the component instance

Returns

This ComponentMapping, so more modifications can be applied

withProvider(_:)

Creates a mapping for the component type to any ComponentProvider.

@discardableResult public func withProvider(_ provider: ComponentProvider) -> Self

Parameters

  • provider: The component provider to use.

Returns

This ComponentMapping, so more modifications can be applied.

add(_:)

Maps through to the addMapping method of the EntityState that this mapping belongs to so that a fluent interface can be used when configuring entity states.

@discardableResult public func add(_ type: ComponentInitializable.Type) -> StateComponentMapping

Parameters

  • type: The type of component to add a mapping to the state for

Returns

The new ComponentMapping for that type

Clone this wiki locally