alt icon indicating copy to clipboard operation
alt copied to clipboard

Prevent action

Open maxs15 opened this issue 8 years ago • 2 comments

I'm looking for a way to prevent an action to update the store but I didn't find anything in the documentation. Is there a way to achieve this ? I tried just returning return; but I got an error [ReferenceError: An action was called but nothing was dispatched]

Is there maybe a way to unable the logs ?

Thanks

maxs15 avatar Apr 11 '16 15:04 maxs15

It looks to be just a warning but I'm seeing the same thing. This seems like a valid use case of an action.

Even the documentation on Actions indicates as much:

There are two exceptions to this, however:

Returning undefined (or omitting return altogether) will not dispatch the action
Returning a Promise will not dispatch the action

Async actions in particular come to mind where I want to dispatch an action which fires an ajax request and when I get the result defer to success/failed.

Is there any reason to keep the warning?

aajtodd avatar Jun 01 '16 18:06 aajtodd

class DemoActions{
    a() {
        return dispatch => {
              dispatch();
             $.get('/xxx', data => {
                 this.getSuccess(data);
             }).fail(() => {
                 this.getFail('error');
             });
        };
    }
}

// or

class DemoActions{
    a() {
        return dispatch => {

             $.get('/xxx', data => {
                   dispatch(data);
             });
        };
    }
}

edision avatar Jul 07 '16 08:07 edision