Skip to content

Instantly share code, notes, and snippets.

@JAStanton
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JAStanton/a89844d150ef5b0f66b9 to your computer and use it in GitHub Desktop.
Save JAStanton/a89844d150ef5b0f66b9 to your computer and use it in GitHub Desktop.
// (This is psuedo code)
class fooAction extends store {
addFoo(foo, bar, baz) {
return new Promise(function(reject, resolve) {
ajax(function(response, error) {
if (error) {
// I want to pass two arguments here but it will noly pass the first one.
reject({foo, error});
} else {
resolve(response);
}
})
});
};
}
class fooStore extends action {
constructor() {
super();
let myActionIds = this.getActionId('foos');
this.registerAsync(myActionIds.addFoo, this.handleFetching, this.handleSuccess, this.handleFail);
}
// "receives same arguments that were passed to the action."
handleFetching(args) {
// I expected my args to be foo, bar, baz but it's actually:
// [actionArgs, actionId, async, dispatchId]
let foo = args.actionArgs.foo;
let bar = args.actionArgs.bar;
let baz = args.actionArgs.baz;
}
// "receives the rejected value of the promise returned by the action (by
// convention, an error object)."
handleFail(args) {
// It only passed the first argument, it would be nice to have all of them
// and not have to unpack them
let foo = args.foo;
let error = args.error;
}
// "receives the resolved value of the promise returned by the action."
handleSuccess(response) {
// that was simple. first arg is the response
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment