不确定 refluxjs 中的 .listen() 究竟做了什么

Not sure what .listen() in refluxjs does exactly

refluxjs 中,我不确定 .listen() 是做什么的。据我了解,它与 nodejs eventemitter 具有相同的概念,但回流以自己的方式包装。我似乎无法在任何地方找到这方面的文档。也许我错过了。我想在源代码或文档中找到 .listen(),以便我确切地知道 refluxjs 如何使用它。

你试过 README 了吗?上面有一整节:Listening to changes in data store.

Listening to changes in data store

In your component, register to listen to changes in your data store like this:

// Fairly simple view component that outputs to console
function ConsoleComponent() {

    // Registers a console logging callback to the statusStore updates
    statusStore.listen(function(status) {
        console.log('status: ', status);
    });
};

var consoleComponent = new ConsoleComponent();

Invoke actions as if they were functions:

statusUpdate(true);
statusUpdate(false);

With the setup above this will output the following in the console:

status:  ONLINE
status:  OFFLINE

是的,它的语义非常像 EventEmitter;它使用 eventemitter3 under the hood. listen itself is defined in PublisherMethods.js.