Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/createAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function createAction(definition) {
}

definition.children = definition.children || [];
if (definition.asyncResult){
if (definition.asyncResult || definition.asyncCall){
definition.children = definition.children.concat(["completed", "failed"]);
}

Expand All @@ -52,6 +52,14 @@ export default function createAction(definition) {
_isAction: true
}, PublisherMethods, ActionMethods, definition);


if(definition.asyncCall){
context.listen( (argument) => {
definition.asyncCall(argument)
.then(definition.children.completed)
.catch(definition.children.failed);
});
}
var functor = function() {
var triggerType = functor.sync ? "trigger" : "triggerAsync";
return functor[triggerType].apply(functor, arguments);
Expand Down
7 changes: 7 additions & 0 deletions test/creatingActions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ describe('Creating action', function() {
});
});

it.only("should create action with the parameter asyncCall",function(done){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minus the .only()

let doLogin = () => {
done();
};
let actions = Reflux.createActions({login: {asyncCall: doLogin }});
actions.login();
});
describe('Reflux.ActionMethods', function() {

afterEach(function(){
Expand Down