Let's get familiar with a few terms as they are used across this repo:
person.name
)['person', 'name']
)At a high level flow for a typical render looks like this:
1. render()
|__ 2. compile()
|__ 3. tokenize()
|__ 4. resolve()
|__ 5. get() or resolveFn()
|__ 6. stringify()
The callback for resolving a value (synchronous)
Same as ResolveFn
but for asynchronous functions
Compiles a template and returns an object with functions that render it. Compilation makes repeated render calls more optimized by parsing the template only once and reusing the results. As a result, rendering gets 3-5x faster. Caching is stored in the resulting object, so if you free up all the references to that object, the caches will be garbage collected.
same as the template parameter to .render()
some options for customizing the compilation
a Renderer object which has render methods
A useful utility function that is used internally to lookup a path in an object. It can also be used in your custom resolver functions if needed. Under the hood it uses getRef
This is similar to Lodash's _.get()
an object to resolve value from
the path string as it appeared in the template
the value or undefined
an object to resolve value from
the parsed path (see parsePath)
the value or undefined
the path as it occurs in the template.
For example a["b"].c
['a', 'b', 'c']
Replaces every {{path}} inside the template with values from the scope parameter.
The template containing one or more {{path}} as
placeholders for values from the scope
parameter.
An object containing values for paths from the the
template. If it's omitted, we default to an empty object.
Since functions are objects in javascript, the scope
can technically be a
function too but it won't be called. It'll be treated as an object and its
properties will be used for the lookup.
same options as the compile function
Template where its paths replaced with corresponding values.
Same as render but accepts a resolver function which will be responsible for returning a value for every path.
a function that takes a path and resolves it to a value. The value can be a number, string or boolean. If it is not, it'll be "stringified".
Template where its paths are replaced with the values returned from the resolver function
Same as renderFn but supports asynchronous resolver functions (a function that returns a promise instead of the value).
a promise that when resolved contains the template where its paths replaced with what is returned from the resolver function for each path.
Parses a template and returns the tokens in an object.
the template
the resulting tokens as an object that has strings and paths
An array that is derived from a path string For example, if your template has a path that looks like
'person.name'
, its corresponding Ref looks like['person', 'name']