Skip to content

Commit 482f622

Browse files
Change behavior to allow chaining
This now allows `mobj.always.method1().method2()`, which would add two updaters for `methd1()` and `method2()`
1 parent 92c4b0d commit 482f622

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

manim/mobject/builders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@ def add_updater(*method_args, **method_kwargs):
9999
lambda m: getattr(m, name)(*method_args, **method_kwargs),
100100
call_updater=True,
101101
)
102-
return mob
102+
return self
103103

104104
return add_updater

manim/mobject/mobject.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,15 @@ def construct(self):
395395
def always(self) -> Self:
396396
"""Call a method on a mobject every frame.
397397
398-
This is syntactic sugar for ``mob.add_updater(lambda m: m.method())``
398+
This is syntactic sugar for ``mob.add_updater(lambda m: m.method(*args, **kwargs), call_updater=True)``.
399+
Note that this will call the method immediately. If this behavior is not
400+
desired, you should use :meth:`add_updater` directly.
399401
400402
.. warning::
401403
402-
Attempting to add multiple updaters to the same mobject (such as
403-
by calling this method more than once, and not removing the previous updater)
404-
can have unintended side effects, such as one updater taking priority over the
405-
other.
406-
404+
Chaining of methods is allowed, but each method will be added
405+
as its own updater. If you are chaining methods, make sure they
406+
do not interfere with each other or you may get unexpected results.
407407
408408
Example
409409
-------
@@ -413,12 +413,12 @@ def always(self) -> Self:
413413
class AlwaysExample(Scene):
414414
def construct(self):
415415
sq = Square().to_edge(LEFT)
416-
t = Text("Hello World!").always.next_to(sq, UP)
416+
t = Text("Hello World!")
417+
t.always.next_to(sq, UP)
417418
self.add(sq, t)
418419
self.play(sq.animate.to_edge(RIGHT))
419-
420420
"""
421-
# can't use typing.cast because Self is under typing_extensions
421+
# can't use typing.cast because Self is under TYPE_CHECKING
422422
return _UpdaterBuilder(self) # type: ignore
423423

424424
def __deepcopy__(self, clone_from_id) -> Self:

0 commit comments

Comments
 (0)