Skip to main content

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:

  1. Input Port Registration: Automatically creates inputs based on component's input definition
  2. Output Port Registration: Automatically creates outputs based on component's output definition
  3. Interface Synchronization: Keeps instance interface in sync with component definition
  4. Port Management: Handles dynamic addition/removal of component ports

Inputs

Component Configuration

DataDescription
Component ModelReference 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

DataDescription
Instance IDUnique 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

  1. Creation: Instance is created with unique ID and scope
  2. Model Binding: Component model is set and internal structure is built
  3. Port Creation: Input and output ports are dynamically registered
  4. Root Detection: Component root nodes are identified and managed
  5. Execution: Component logic executes within isolated scope
  6. Cleanup: Proper resource cleanup when instance is removed

Example Use Cases

  1. Reusable UI Components: Create multiple instances of custom UI elements

    Component: Custom Card
    Instances: ProductCard, UserCard, NewsCard
    Each with different data but same behavior
  2. Data Processing Units: Replicate data processing logic

    Component: Data Transformer
    Instances: Process different data streams
    Each maintaining separate state
  3. Game Objects: Create multiple game entities

    Component: Enemy Character
    Instances: Multiple enemies with individual states
    Each with own health, position, behavior
  4. 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

  1. Component Design: Design components for reusability and clear interfaces
  2. State Management: Keep component state minimal and well-defined
  3. Resource Cleanup: Ensure proper cleanup of timers, connections, and events
  4. Interface Stability: Maintain stable component interfaces to avoid breaking instances
  5. 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.