Skip to content

Observble<bool> doesn't work in ToReactiveCommand as canExecuteSource #372

@BR7RKR

Description

@BR7RKR

I have the following code:

var canRemove = Observable
            .Merge(SelectedCoordsItem.Select(x => x is not null))
            .ObserveOnUIThreadDispatcher()
            .Where(_ =>
            {
                if (SelectedCoordsItem.Value is null)
                {
                    return false;
                }

                return _savedCoordinates.Contains(SelectedCoordsItem.Value);
            });

        AddNewItemCommand = new ReactiveCommand(AddNewItem).DisposeItWith(Disposable);
        RemoveItemCommand = canRemove.ToReactiveCommand<Unit>(RemoveItem).DisposeItWith(Disposable);

In this case when canRemove translates false value it doesn't turn off my command.

When I turn canRemove into ReactiveProperty everything works fine.

I guess that it is a bug.
If Observable is not a valid source for canExecute in this context, it would be helpful to either:

  • restrict the API so that such usage produces a compile-time error, or
  • add a remark in the XML documentation clarifying the limitation and the correct usage pattern.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions