Understand micromustache terminology and lifecycle
masterTo use micromustache effectively, it is helpful to understand its core terminology and the high-level rendering lifecycle:
Core Concepts
- Path: A string in a template used to refer to a value (e.g.,
person.name). - Ref: An array derived from a Path used for internal lookups (e.g.,
['person', 'name']). - Scope: The object used to resolve values (referred to as a view in Mustache.JS).
- Value: The actual data used to interpolate a path.
- Tags: The delimiters used to mark paths in a template. The default tags are
{{and}}.
Internal Processes
- Parsing: Converting a Path into a Ref.
- Resolving: Looking up a Value for a Path using either the Scope or a custom resolver function.
- Tokenization: Breaking a template into constant strings and Paths.
- Compiling: The process of tokenizing a template to create a Renderer object.
- Rendering: The process of interpolating Paths in a template with their resolved values.
- Stringification: The final step (also called generator) of combining resolved values into the final string result.
- Renderer: An object containing a tokenized template with methods for rendering.
High-Level Rendering Flow
render()└── 2.compile()└── 3.tokenize()└── 4.resolve()└── 5.get()orresolveFn()└── 6.stringify()
1. render()
|__ 2. compile()
|__ 3. tokenize()
|__ 4. resolve()
|__ 5. get() or resolveFn()
|__ 6. stringify()