You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From discussion in #57 it seems we may need to create actions together with a callback that works like the preEmit.
Add function as argument in createAction so you can do this:
varmyAction=Reflux.createAction(function(arg){console.log(arg);returnarg+1;});myAction.listen(function(arg){console.log(arg);})myAction("test");// will output:// test// test1
Internally we could just pass the callback to the preEmit hook. Also the action needs to pass the return value preEmit does. By default, if preEmit does not return anything (i.e. returns undefined), the arguments are kept as is.
Creating multiple actions is done through an options object:
varActions=Reflux.createActions({action1: true,// or any truthy valueaction2: function(arg){console.log(arg);returnarg+1;}});Actions.action1();// no preEmit hook, just a default actionActions.action2("test");// outputs test, passes on "test1"
The text was updated successfully, but these errors were encountered:
my 2 cents here: I think actions is the place where additional validations might be useful, so what do you think if when creating actions developer can specify arg type validation, similar to propTypes in React.
@andreypopp I wonder if it is just easier to do the function approach anyway... and add a validator composer. E.g. like this:
// composing validatorvarvalidatorFunc=Reflux.createValidator(Reflux.validators.isNumberIntervalOf(0,100),Reflux.validators.isNot(1));// attach validator to actionvaraction=Reflux.createAction(validatorFunc);
Alternatively put that into the shouldEmit hook instead.
// attach validator to actionvaraction=Reflux.createAction();action.shouldEmit=validatorFunc;
Also validators may need to "throw an error" by invoking relevant action(s) for an error handling flow. Probably add that to the validator as parameter:
// ErrorAction(s) defined earliervarvalidatorFunc=Reflux.createValidator(Reflux.validators.isNot(-1,ErrorAction.wrongNumberOnTextField));
Krawaller has implemented the passthrough on preEmit in #78 which is included in 0.1.8.
Closing this issue now, since I'm pretty sure you can use 3rd party argument matchers in javascript. So I'm dropping the idea for now until someone comes with a really good idea for validator implementation.
From discussion in #57 it seems we may need to create actions together with a callback that works like the preEmit.
Add function as argument in
createAction
so you can do this:Internally we could just pass the callback to the preEmit hook. Also the action needs to pass the return value preEmit does. By default, if preEmit does not return anything (i.e. returns
undefined
), the arguments are kept as is.Creating multiple actions is done through an options object:
The text was updated successfully, but these errors were encountered: