From 6b509bd43fbf6012665ed5a30f38cafa4c665d51 Mon Sep 17 00:00:00 2001 From: Peter Kovacs Date: Wed, 21 Jun 2023 11:59:44 -0400 Subject: [PATCH] Define `Node.lazy` to lazily evaluate node contents --- Sources/Plot/API/Node.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/Plot/API/Node.swift b/Sources/Plot/API/Node.swift index 245883e..e957eb4 100644 --- a/Sources/Plot/API/Node.swift +++ b/Sources/Plot/API/Node.swift @@ -159,6 +159,14 @@ public extension Node { static func components(@ComponentBuilder _ content: () -> Component) -> Node { .component(content()) } + + /// Create a node that lazily evaluates its contents at rendering time. + /// - parameter closure: A closure which evaluates to the contents of this node + static func `lazy`(_ closure: @escaping () -> Node ) -> Node { + Node { renderer in + closure().rendering(&renderer) + } + } } internal extension Node where Context: DocumentFormat {