public Maybe <Unit> RemoveEntry(string projectName, string name) => _engine.Mutate(nameof(RemoveEntry), c => from context in c from project in context.Data.Projects.FirstMaybe(p => p.ProjectName == projectName) from entry in MayNotNull(project.Entries.Find(le => le.Key == name)) select context.WithChange(new RemoveEntryChange(entry)));
public void WorkCompled() { if (Interlocked.Decrement(ref _pending) == 0) { _mutatingEngine.Mutate(_effectInvoker); _mutatingEngine.Mutate(this); } }
public void RemoveEntry(string project, string name) { _engine.Mutate(nameof(RemoveEntry), obs => obs.Select(context => { var entry = context.Data.Projects.FirstOrDefault(p => p.ProjectName == project)?.Entries .Find(le => le.Key == name); return(entry == null ? context : context.Update(new RemoveEntryChange(entry), context.Data.ReplaceEntry(entry, null))); })); }
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 ProjectMutator(MutatingEngine <MutatingContext <ProjectFile> > engine, ProjectFileWorkspace workspace) { _engine = engine; _workspace = workspace; NewProject = engine.EventSource(mc => new AddProject(mc.GetChange <NewProjectChange>().Project), context => context.Change is NewProjectChange); RemovedProject = engine.EventSource(mc => new RemoveProject(mc.GetChange <RemoveProjectChange>().Project), context => context.Change is RemoveProjectChange); NewLanguage = engine.EventSource(mc => mc.GetChange <LanguageChange>().ToEventData(), context => context.Change is LanguageChange); NewImport = engine.EventSource(mc => mc.GetChange <AddImportChange>().ToEventData(), context => context.Change is AddImportChange); RemoveImport = engine.EventSource(mc => mc.GetChange <RemoveImportChange>().ToData(), context => context.Change is RemoveImportChange); NewLanguage.RespondOn(null, newLang => { if (workspace.ProjectFile.GlobalLanguages.Contains(newLang.ActiveLanguage)) { return; } if (!Projects.All(p => p.ActiveLanguages.Contains(newLang.ActiveLanguage))) { return; } _engine.Mutate(nameof(AddLanguage) + "Global-Single", obs => obs.Select(context => context.Update(new GlobalLanguageChange(newLang.ActiveLanguage), context.Data with { GlobalLanguages = context.Data.GlobalLanguages.Add(newLang.ActiveLanguage) }))); });
public void SetIntigrate(bool intigrate) { _engine.Mutate(nameof(SetIntigrate), obs => obs.Select(mc => mc.Data.BuildInfo.IntigrateProjects == intigrate ? mc : mc.Update(new IntigrateImportChange(intigrate), mc.Data with { BuildInfo = mc.Data.BuildInfo with { IntigrateProjects = intigrate } })));
public ProjectMutator(MutatingEngine <MutatingContext <ProjectFile> > engine, ProjectFileWorkspace workspace) { _engine = engine; _workspace = workspace; NewProject = engine.EventSource( c => c.Select(mc => new AddProject(mc.GetChange <NewProjectChange>().Project)), c => from context in c from change in context.Change select change is NewProjectChange); RemovedProject = engine.EventSource(c => c.Select(mc => new RemoveProject(mc.GetChange <RemoveProjectChange>().Project)), c => from context in c from change in context.Change select change is RemoveProjectChange); NewLanguage = engine.EventSource(c => c.Select(mc => mc.GetChange <LanguageChange>().ToEventData()), c => from context in c from change in context.Change select change is LanguageChange); NewImport = engine.EventSource(c => c.Select(mc => mc.GetChange <AddImportChange>().ToEventData()), c => from context in c from change in context.Change select change is AddImportChange); RemoveImport = engine.EventSource(c => c.Select(mc => mc.GetChange <RemoveImportChange>().ToData()), c => from context in c from change in context.Change select change is RemoveImportChange); NewLanguage.RespondOn(null, mayNewLang => Do(from newlang in mayNewLang where !workspace.ProjectFile.GlobalLanguages.Contains(newlang.ActiveLanguage) where Projects.All(p => p.ActiveLanguages.Contains(newlang.ActiveLanguage)) select Action(() => _engine.Mutate(nameof(AddLanguage) + "Global-Single", c => from context in c select context.WithChange(new GlobalLanguageChange(newlang.ActiveLanguage)))))); }
public Maybe <Unit> SetIntigrate(bool intigrate) => _engine.Mutate(nameof(SetIntigrate), mc => from context in mc where context.Data.BuildInfo.IntigrateProjects != intigrate select context.WithChange(May(new IntigrateImportChange(intigrate))));
// => _engine.Mutate(nameof(Reset), context => context.Update(new ResetChange(), file)); public void UpdateSource(string file) => _engine.Mutate(nameof(UpdateSource), context => context.Update(new SourceChange(), context.Data.WithSource(file)));
// => _engine.Mutate(nameof(Reset), context => context.Update(new ResetChange(), file)); public void UpdateSource(string file) { _engine.Mutate(nameof(UpdateSource), context => context.Select(c => c.Update(new SourceChange(), c.Data with { Source = file })));
public Maybe <Unit> AddProject(string mayName) => _engine.Mutate(nameof(AddProject), c => from context in c from name in MayNotEmpty(mayName) let newProject = new Project(name, ImmutableList.CreateRange(context.Data.GlobalLanguages)) select context.WithChange(new NewProjectChange(newProject)));