Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
* A redux middleware for processing Meteor methods
* When an action is dispatched, it will pass through our middleware.
* if denoted a method, we will dispatch the action with readyState of loading
* The method passed in is then called, and dispatches further ready states for success/error
* The reducer shape should include { data, readyState } for use in the UI
* @returns {Function}
export default function methodMiddleware() {
return (next) => {
return (action) => {
const { method, } = action;
if (!method) {
return next(action);
next({, readyState: 'loading' });
return method((error, result) => {
if (error) {
return next({ error: error.reason, readyState: 'error', });
return next({ data: result, readyState: 'success',});
// implementation
type: "SOMETIHNG",
method: function (cb) {
return'something', cb);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment