-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deduplicate events emision in nested properties (#279)
* feat: deduplicate events emmision in nested properties * remove obsolete lines * try putting in same file * fix type to Type * select code path in __new__ * fix test coverage * simplify test * fix andy requests * update function name and add docstring * style(pre-commit.ci): auto fixes [...] * Update tests/test_evented_model.py Co-authored-by: Andy Sweet <[email protected]> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Talley Lambert <[email protected]> Co-authored-by: Andy Sweet <[email protected]>
- Loading branch information
1 parent
9cdce45
commit 9f75e18
Showing
4 changed files
with
239 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from types import TracebackType | ||
|
||
import pydantic.version | ||
|
||
if pydantic.version.VERSION.startswith("2"): | ||
from ._evented_model_v2 import EventedModel as EventedModelV1 | ||
else: | ||
from ._evented_model_v1 import EventedModel as EventedModelV2 | ||
|
||
|
||
class ComparisonDelayer: | ||
def __init__(self, target: EventedModelV1 | EventedModelV2) -> None: | ||
self._target = target | ||
|
||
def __enter__(self) -> None: | ||
self._target._delay_check_semaphore += 1 | ||
|
||
def __exit__( | ||
self, | ||
exc_type: type[BaseException] | None, | ||
exc_val: BaseException | None, | ||
exc_tb: TracebackType | None, | ||
) -> None: | ||
self._target._delay_check_semaphore -= 1 | ||
self._target._check_if_values_changed_and_emit_if_needed() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.