Binding and templating internals

Deep dive into Aurelia's binding system, template compilation pipeline, and rendering architecture for framework contributors and advanced plugin authors.

Understand how Aurelia's binding and templating system works under the hood. This guide covers the compilation pipeline, binding lifecycle, observation strategies, and rendering architecture—essential knowledge for framework contributors, plugin authors, and developers debugging complex binding scenarios.

Audience

This guide is for:

  • Framework contributors - Understanding the codebase

  • Plugin authors - Extending the compiler or runtime

  • Advanced developers - Debugging complex binding issues

  • Performance optimizers - Understanding cost of bindings

Architecture Overview

┌─────────────────┐
│  Template HTML  │
└────────┬────────┘


┌─────────────────┐
│ Template Parser │  (HTMLParser)
└────────┬────────┘


┌─────────────────┐
│   Compilation   │  (TemplateCompiler)
│   - Parse       │
│   - Analyze     │
│   - Generate    │
└────────┬────────┘


┌─────────────────┐
│  Instructions   │  (Binding, Listener, etc.)
└────────┬────────┘


┌─────────────────┐
│   Rendering     │  (Renderer)
└────────┬────────┘


┌─────────────────┐
│  Live Bindings  │  (Binding, Listener, etc.)
│  + Observers    │
└─────────────────┘

Part 1: Template Compilation

Phase 1: HTML Parsing

Aurelia uses the browser's native HTML parser wrapped in HTMLParser:

Key Points:

  • Uses native <template> element

  • Parses into DocumentFragment

  • Preserves DOM structure exactly

  • No virtual DOM involved

Phase 2: Template Compilation

The TemplateCompiler walks the DOM and generates instructions:

Phase 3: Instruction Generation

Instructions are data structures describing what to create at runtime:

Instruction Types:

  • PropertyBindingInstruction - .bind, .one-way, .two-way

  • ListenerBindingInstruction - .trigger, .delegate, .capture

  • RefBindingInstruction - ref attribute

  • IteratorBindingInstruction - repeat.for

  • HydrateElementInstruction - Custom elements

  • HydrateAttributeInstruction - Custom attributes

  • Interpolation Instruction - ${expression}

Part 2: Expression Parsing

Expression Parser

Converts strings to Abstract Syntax Trees (AST):

Expression Types

Binding Modes

Part 3: Rendering & Hydration

Renderer

Converts instructions into live bindings:

Binding Lifecycle

Part 4: Observation System

Observer Types

PropertyObserver (Plain Objects)

SetterObserver (Dirty Checking)

ArrayObserver

ObserverLocator

Central registry for creating observers:

Part 5: Change Detection & Scheduling

Observation Strategies

Proxy-Based (Default)

Getter/Setter-Based

Part 6: Performance Characteristics

Binding Costs

Binding Type
Compile Time
Runtime Setup
Per-Update Cost

One-Time

Low

None

Zero

To-View

Low

Low

Low

Two-Way

Low

Medium

Medium

Interpolation

Medium

Low

Low

Repeat

High

High

High

Observation Costs

Strategy
Memory
CPU (Setup)
CPU (Update)

Proxy

Low

Low

Very Low

Getter/Setter

Medium

Medium

Low

Dirty Checking

Low

Low

High

Part 7: Debugging Techniques

Enable Debug Mode

Inspect Bindings

Trace Observations

Profile Bindings

Part 8: Plugin Development

Custom Binding Command

Custom Observer

Resources

Contributing

If you're interested in contributing to Aurelia's core:

  1. Join the Discord

Last updated

Was this helpful?