public void Run(IStateAction action, bool?sendBack) { if (_middlewares.Any(m => !m.MayDispatchAction(action))) { return; } _middlewares.ForEach(m => m.BeforeDispatch(action)); var sender = ActorRefs.NoSender; var context = InternalCurrentActorCellKeeper.Current; if (context != null) { sender = context.Self; } var effects = new EffectInvoker(_effects.Where(e => e.ShouldReactToAction(action)), action, this); var resultInvoker = new ResultInvoker(effects, _engine, sender, sendBack ?? _sendBackSetting, action); _middlewares.ForEach(m => m.BeforeDispatch(action)); foreach (var dataMutation in _states.Select(sc => sc.TryDipatch(action, resultInvoker.AddResult, resultInvoker.WorkCompled))) { if (dataMutation == null) { continue; } resultInvoker.PushWork(); _engine.Mutate(dataMutation); } }
public ResultInvoker(EffectInvoker effectInvoker, MutatingEngine mutatingEngine, IActorRef sender, bool sendBack, IStateAction action) { _effectInvoker = effectInvoker; _mutatingEngine = mutatingEngine; _sender = sender; _sendBack = sendBack; _action = action; }