Skip to content

[BUG] ReactiveCommand Execute() runs before subscribe #2689

@jalbertSyncroTech

Description

@jalbertSyncroTech

Describe the bug

According to this documentation comment, ReactiveCommand Execute() should not run the associated command logic until the returned observable is subscribed.

"Invoking this method will return a cold (lazy) observable that, when subscribed, will execute the logic encapsulated by the command. It is worth restating that the returned observable is lazy. Nothing will happen if you call Execute and neglect to subscribe (directly or indirectly) to the returned observable."

/// Invoking this method will return a cold (lazy) observable that, when subscribed, will execute the logic

However, this change replaced the call to
Observable.StartAsync(execute)
with
() => execute().ToObservable(),
which incorrectly executes the command logic immediately.

93823ff

Steps To Reproduce

  • Call ReactiveCommand.Execute()

Expected behavior

  • The logic in the command should not be executed (until .Subscribe() or await is used)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions