Skip to content

Why does the return value of fn get dispatched? #3

@shaula

Description

@shaula

I'm using redux-subscribe with plain redux (no react, no vdux or whatever).

Since I'm a redux beginner, I don't understand this line of your code:

Index: node_modules/redux-subscribe/lib/index.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- node_modules/redux-subscribe/lib/index.js	(revision )
+++ node_modules/redux-subscribe/lib/index.js	(revision )
@@ -85,6 +85,7 @@
 
                 if (prev !== next) {
                   (0, _foreach2.default)(function (fn) {
+                    // Why is the return value of fn dispatched again?
                     return dispatch(fn({ path: path, prev: prev, next: next }));
                   }, subscriptions[path]);
                 }

My call to subscribe looks like this:

store.dispatch(subscribe('feature', 'feature', () => {
	renderFeature();
	return {type: null};
}));

But initially I tried doing:

store.dispatch(subscribe('feature', 'feature', renderFeature));

...which failed as the dispatch function is passed a null and cannot find a property type on it. As a result I return {type: null} from my wrapped render function. Am I doing something wrong?

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