Component Instance
This node creates an instance of a custom component with its own isolated scope and state.
The Component Instance node enables component-based architecture by instantiating reusable components.
The Component Instance node creates a runtime instance of a custom component, providing encapsulation, reusability, and modularity. Each instance maintains its own isolated state and scope while exposing the component's defined input and output interfaces.
Usage
The Component Instance node is fundamental to component-based development:
Component Instantiation
- Isolated Scope: Each instance has its own NodeScope for complete encapsulation
- State Management: Independent state for each component instance
- Unique Identity: Automatic generation of unique instance IDs
- Model Binding: Dynamic binding to component models and definitions
Dynamic Interface Creation
When a component is instantiated:
- Input Port Registration: Automatically creates inputs based on component's input definition
- Output Port Registration: Automatically creates outputs based on component's output definition
- Interface Synchronization: Keeps instance interface in sync with component definition
- Port Management: Handles dynamic addition/removal of component ports
Inputs
Component Configuration
| Data | Description |
|---|---|
| Component Model | Reference to the component definition to instantiate |
Dynamic Inputs
Input ports are automatically created based on the component's input definition
Outputs
Dynamic Outputs
Output ports are automatically created based on the component's output definition
Instance Information
| Data | Description |
|---|---|
| Instance ID | Unique identifier for this component instance |
Advanced Features
Scope Management
- Parent Scope Inheritance: Inherits model scope from parent context
- Isolated Execution: Component logic executes in its own scope
- Resource Management: Proper cleanup when instance is destroyed
- Event Handling: Manages component lifecycle events
Component Lifecycle
- Creation: Instance is created with unique ID and scope
- Model Binding: Component model is set and internal structure is built
- Port Creation: Input and output ports are dynamically registered
- Root Detection: Component root nodes are identified and managed
- Execution: Component logic executes within isolated scope
- Cleanup: Proper resource cleanup when instance is removed
Example Use Cases
-
Reusable UI Components: Create multiple instances of custom UI elements
Component: Custom Card
Instances: ProductCard, UserCard, NewsCard
Each with different data but same behavior -
Data Processing Units: Replicate data processing logic
Component: Data Transformer
Instances: Process different data streams
Each maintaining separate state -
Game Objects: Create multiple game entities
Component: Enemy Character
Instances: Multiple enemies with individual states
Each with own health, position, behavior -
Form Sections: Reuse form components
Component: Address Form
Instances: Billing Address, Shipping Address
Each managing separate address data
State Isolation
Each Component Instance maintains complete state isolation:
- Independent Variables: Each instance has its own variable values
- Separate Event Handling: Events are isolated to instance scope
- Unique Timers: Timers and animations run independently
- Individual Connections: Network requests and data connections are separate
Performance Considerations
- Memory Management: Each instance allocates its own memory space
- Execution Overhead: Instances have individual execution contexts
- Resource Optimization: Shared component definitions reduce memory usage
- Cleanup Importance: Proper instance cleanup prevents memory leaks
Development Patterns
Factory Pattern: Use Component Instances to create object factories Template Method: Define common behavior in components, customize through inputs Observer Pattern: Use component outputs to notify external systems Composite Pattern: Build complex structures from simple component instances
Best Practices
- Component Design: Design components for reusability and clear interfaces
- State Management: Keep component state minimal and well-defined
- Resource Cleanup: Ensure proper cleanup of timers, connections, and events
- Interface Stability: Maintain stable component interfaces to avoid breaking instances
- Testing: Test components both in isolation and as instances
Debugging and Monitoring
- Instance Identification: Use unique instance IDs for debugging
- Scope Inspection: Inspect instance-specific state and variables
- Performance Monitoring: Monitor individual instance performance
- Error Isolation: Errors in one instance don't affect others
The Component Instance node is essential for building scalable, maintainable applications using component-based architecture principles.