React.js - flux vs global event bus

前端 未结 4 1713
情书的邮戳
情书的邮戳 2021-02-15 01:45

What is the advantage of using Flux over a global event bus? I think the dispatcher is all that is needed:

  1. component publishes \'user event\' with data to the dis
4条回答
  •  遇见更好的自我
    2021-02-15 02:01

    You basically described flux, the only difference is:

    1. stores emit a change event

    And the component updating its state isn't part of flux, that's a common practice for integrating flux and react.

    Flux just names each of these pieces and gives guidelines on what each piece's responsibility is.

    It's essentially a main event emitter (dispatcher), the event types (actions), functions that emit an event on the dispatcher (action creators; the event body is a payload), and other event emitters that: keep state, listen to the dispatcher and emit change events (stores).

    At least that's how it works in JS. The core principle is the unidirectional data flow. There are plenty of event emitters that are used for bidirectional communication.

提交回复
热议问题