From 27c10c06aa4f43edbe17d91cf021044b8c66130b 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 2ab70214..149299f9 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 c242b4bc..c57a3a50 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 ~~~~~~~