Get the delta for the state. Returns: The delta for the state.
(self)
| 1855 | } |
| 1856 | |
| 1857 | def get_delta(self) -> Delta: |
| 1858 | """Get the delta for the state. |
| 1859 | |
| 1860 | Returns: |
| 1861 | The delta for the state. |
| 1862 | """ |
| 1863 | delta = {} |
| 1864 | |
| 1865 | self._mark_dirty_computed_vars() |
| 1866 | frontend_computed_vars: set[str] = { |
| 1867 | name for name, cv in self.computed_vars.items() if not cv._backend |
| 1868 | } |
| 1869 | |
| 1870 | # Return the dirty vars for this instance, any cached/dependent computed vars, |
| 1871 | # and always dirty computed vars (cache=False) |
| 1872 | delta_vars = self.dirty_vars.intersection(self.base_vars).union( |
| 1873 | self.dirty_vars.intersection(frontend_computed_vars) |
| 1874 | ) |
| 1875 | |
| 1876 | subdelta: dict[str, Any] = { |
| 1877 | prop + FIELD_MARKER: self.get_value(prop) |
| 1878 | for prop in delta_vars |
| 1879 | if not types.is_backend_base_variable(prop, type(self)) |
| 1880 | } |
| 1881 | |
| 1882 | if len(subdelta) > 0: |
| 1883 | delta[self.get_full_name()] = subdelta |
| 1884 | |
| 1885 | # Recursively find the substate deltas. |
| 1886 | substates = self.substates |
| 1887 | for substate in self.dirty_substates.union(self._always_dirty_substates): |
| 1888 | delta.update(substates[substate].get_delta()) |
| 1889 | |
| 1890 | # Return the delta. |
| 1891 | return delta |
| 1892 | |
| 1893 | async def _get_resolved_delta(self) -> Delta: |
| 1894 | """Get the delta for the state after resolving all coroutines. |