From 5f0c01809d679854b976a187061258a70d9d10f2 Mon Sep 17 00:00:00 2001 From: David Jennes Date: Thu, 28 Jul 2022 02:30:25 +0200 Subject: [PATCH] Docs & changelog entry --- CHANGELOG.md | 3 +++ docs/templates.rst | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ab7021..149299f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,9 @@ [David Jennes](https://github.com/djbe) [#164](https://github.com/stencilproject/Stencil/pull/164) [#325](https://github.com/stencilproject/Stencil/pull/325) +- Allow providing lazily evaluated context data, using the `LazyValueWrapper` structure. + [David Jennes](https://github.com/djbe) + [#324](https://github.com/stencilproject/Stencil/pull/324) ### Deprecations diff --git a/docs/templates.rst b/docs/templates.rst index c242b4b..c57a3a5 100644 --- a/docs/templates.rst +++ b/docs/templates.rst @@ -50,6 +50,14 @@ For example, if you have the following context: The result of {{ item[key] }} will be the same as {{ item.name }}. It will first evaluate the result of {{ key }}, and only then evaluate the lookup expression. +You can use the `LazyValueWrapper` type to have values in your context that will be lazily evaluated. The provided value will only be evaluated when it's first accessed in your template, and will be cached afterwards. For example: + +.. code-block:: swift + + [ + "magic": LazyValueWrapper(myHeavyCalculations()) + ] + Boolean expressions ------------------- @@ -60,7 +68,6 @@ For example, this will output string `true` if variable is equal to 1 and `false {{ variable == 1 }} - Filters ~~~~~~~