Skip to content

LifeCycleEventHub#onDispatch receive StoreChangedPayload #328

@azu

Description

@azu

This is a bug.

        const context = new Context({
            dispatcher: new Dispatcher(),
            store: storeGroup
        });
        context.events.onDispatch((payload, meta) => {
            // payload is instanceof StoreChangedPayload in some times
        });

The problem case is happen when user call Store#setState.

Example: When execute ExampleUseCase, context.events.onDispatch recevive StoreChangedPayload at once.

// UseCase
class ExampleUseCase extends UseCase {
    execute() {
        this.dispatch({ type: "update" });
    }
}

// Store
class ExampleStore extends Store {
    constructor() {
        super();
        this.state = {};
    }

    receivePayload(payload) {
        if (payload.type === "update") {
            this.setState({ value: "new value" });
        }
    }

    getState() {
        return this.state;
    }
}

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