Walk through the component tree and memoize all stateful components. Args: component: The component to memoize. Returns: The memoized component tree.
(cls, component: BaseComponent)
| 1679 | |
| 1680 | @classmethod |
| 1681 | def compile_from(cls, component: BaseComponent) -> BaseComponent: |
| 1682 | """Walk through the component tree and memoize all stateful components. |
| 1683 | |
| 1684 | Args: |
| 1685 | component: The component to memoize. |
| 1686 | |
| 1687 | Returns: |
| 1688 | The memoized component tree. |
| 1689 | """ |
| 1690 | if isinstance(component, Component): |
| 1691 | if component._memoization_mode.recursive: |
| 1692 | # Recursively memoize stateful children (default). |
| 1693 | component.children = [ |
| 1694 | cls.compile_from(child) for child in component.children |
| 1695 | ] |
| 1696 | # Memoize this component if it depends on state. |
| 1697 | stateful_component = cls.create(component) |
| 1698 | if stateful_component is not None: |
| 1699 | return stateful_component |
| 1700 | return component |
| 1701 | |
| 1702 | |
| 1703 | class MemoizationLeaf(Component): |