Skip to content

Need a way to tell if a command has not yet started execution #22

Open
@minkyn

Description

@minkyn

According to the comment for CommandResult class:

/// Combined execution state of a `Command` represented using four of its fields.
/// A [CommandResult] will be issued for any state change of any of its fields
/// During normal command execution you will get this items by listening at the command's [.results] ValueListenable.
/// 1. If the command was just newly created you will get `param data, null, null, false` (paramData, data, error, isExecuting)
/// 2. When calling execute: `param data, null, null, true`
/// 3. When execution finishes: `param data, the result, null, false`
/// `param data` is the data that you pass as parameter when calling the command

In short, the way to tell whether a command has yet to execute or has completed execution is to see if result.data is null.

However, the actual implementation is inconsistent. The result.data always returns the initial value set on command creation before executing. If the command returns the same value after execution, there is no way to tell them apart. Ideally, CommandResult should have both a getter that returns the initial value before the actual data, as well as a getter that follows the comment to indicate a newly created command before execution.

Moreover, even when CommandResult were fixed to follow its comments, for commands that have no return value, there is still no way to tell if execution has yet started, as the result.data will always be null before and after the execution.

I know I can use another field to track that info, but it's not an elegant solution. The Command class should embed that state internally, just like in FutureBuilder you can use snapshot.connectionState to differentiate ConnectionState.none against ConnectionState.done.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions