goatslacker / alt

Isomorphic flux implementation
http://alt.js.org/
3.45k stars 323 forks source link

Prevent action #638

Open maxs15 opened 8 years ago

maxs15 commented 8 years ago

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

aajtodd commented 8 years ago

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?

edision commented 8 years ago
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);
             });
        };
    }
}