Skip to content

Commit

Permalink
Change behavior to allow chaining
Browse files Browse the repository at this point in the history
This now allows `mobj.always.method1().method2()`, which would
add two updaters for `methd1()` and `method2()`
  • Loading branch information
JasonGrace2282 committed Jul 13, 2024
1 parent 92c4b0d commit 482f622
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion manim/mobject/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ def add_updater(*method_args, **method_kwargs):
lambda m: getattr(m, name)(*method_args, **method_kwargs),
call_updater=True,
)
return mob
return self

return add_updater
18 changes: 9 additions & 9 deletions manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,15 @@ def construct(self):
def always(self) -> Self:
"""Call a method on a mobject every frame.
This is syntactic sugar for ``mob.add_updater(lambda m: m.method())``
This is syntactic sugar for ``mob.add_updater(lambda m: m.method(*args, **kwargs), call_updater=True)``.
Note that this will call the method immediately. If this behavior is not
desired, you should use :meth:`add_updater` directly.
.. warning::
Attempting to add multiple updaters to the same mobject (such as
by calling this method more than once, and not removing the previous updater)
can have unintended side effects, such as one updater taking priority over the
other.
Chaining of methods is allowed, but each method will be added
as its own updater. If you are chaining methods, make sure they
do not interfere with each other or you may get unexpected results.
Example
-------
Expand All @@ -413,12 +413,12 @@ def always(self) -> Self:
class AlwaysExample(Scene):
def construct(self):
sq = Square().to_edge(LEFT)
t = Text("Hello World!").always.next_to(sq, UP)
t = Text("Hello World!")
t.always.next_to(sq, UP)
self.add(sq, t)
self.play(sq.animate.to_edge(RIGHT))
"""
# can't use typing.cast because Self is under typing_extensions
# can't use typing.cast because Self is under TYPE_CHECKING
return _UpdaterBuilder(self) # type: ignore

def __deepcopy__(self, clone_from_id) -> Self:
Expand Down

0 comments on commit 482f622

Please sign in to comment.