本文整理汇总了C#中ReactiveList类的典型用法代码示例。如果您正苦于以下问题:C# ReactiveList类的具体用法?C# ReactiveList怎么用?C# ReactiveList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReactiveList类属于命名空间,在下文中一共展示了ReactiveList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IssueMilestonesViewModel
public IssueMilestonesViewModel(
Func<Task<IReadOnlyList<Milestone>>> loadMilestones,
Func<Task<Milestone>> loadSelectedFunc,
Func<Milestone, Task> saveFunc)
{
var milestones = new ReactiveList<Milestone>();
Milestones = milestones.CreateDerivedCollection(x => CreateItemViewModel(x));
this.WhenAnyValue(x => x.Selected)
.Subscribe(x => {
foreach (var a in Milestones)
a.IsSelected = a.Number == x?.Number;
});
DismissCommand = ReactiveCommand.Create();
SaveCommand = ReactiveCommand.CreateAsyncTask(_ => {
DismissCommand.ExecuteIfCan();
return _selected != _previouslySelected ? saveFunc(_selected) : Task.FromResult(0);
});
LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
_previouslySelected = Selected = await loadSelectedFunc();
milestones.Reset(await loadMilestones());
});
}
示例2: LanguagesViewModel
public LanguagesViewModel(IJsonSerializationService jsonSerializationService, INetworkActivityService networkActivity)
{
var languages = new ReactiveList<LanguageModel>();
Languages = languages.CreateDerivedCollection(
x => new LanguageItemViewModel(x.Name, x.Slug),
x => x.Name.StartsWith(SearchKeyword ?? string.Empty, StringComparison.OrdinalIgnoreCase),
signalReset: this.WhenAnyValue(x => x.SearchKeyword));
Languages
.Changed.Select(_ => Unit.Default)
.Merge(this.WhenAnyValue(x => x.SelectedLanguage).Select(_ => Unit.Default))
.Select(_ => SelectedLanguage)
.Where(x => x != null)
.Subscribe(x =>
{
foreach (var l in Languages)
l.Selected = l.Slug == x.Slug;
});
LoadCommand = ReactiveCommand.CreateAsyncTask(async t =>
{
var trendingData = await BlobCache.LocalMachine.DownloadUrl(LanguagesUrl, absoluteExpiration: DateTimeOffset.Now.AddDays(1));
var langs = jsonSerializationService.Deserialize<List<LanguageModel>>(System.Text.Encoding.UTF8.GetString(trendingData));
langs.Insert(0, DefaultLanguage);
languages.Reset(langs);
});
LoadCommand.TriggerNetworkActivity(networkActivity);
LoadCommand.ExecuteIfCan();
}
示例3: BaseCommitsViewModel
protected BaseCommitsViewModel()
{
Title = "Commits";
var gotoCommitCommand = ReactiveCommand.Create();
gotoCommitCommand.OfType<CommitItemViewModel>().Subscribe(x =>
{
var vm = this.CreateViewModel<CommitViewModel>();
vm.RepositoryOwner = RepositoryOwner;
vm.RepositoryName = RepositoryName;
vm.Node = x.Commit.Sha;
NavigateTo(vm);
});
var commits = new ReactiveList<CommitItemViewModel>();
Commits = commits.CreateDerivedCollection(
x => x,
x => x.Description.ContainsKeyword(SearchKeyword) || x.Name.ContainsKeyword(SearchKeyword),
signalReset: this.WhenAnyValue(x => x.SearchKeyword));
LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
commits.SimpleCollectionLoad(CreateRequest(),
x => new CommitItemViewModel(x, gotoCommitCommand.ExecuteIfCan),
x => LoadMoreCommand = x == null ? null : ReactiveCommand.CreateAsyncTask(_ => x())));
}
示例4: LibraryGroupViewModel
protected LibraryGroupViewModel(string header, string addHeader = null, string icon = null) {
Header = header;
AddHeader = addHeader;
Icon = icon;
if (!Execute.InDesignMode)
this.SetCommand(x => x.AddCommand);
Children = new ReactiveList<IHierarchicalLibraryItem>();
IsExpanded = true;
this.WhenAnyValue(x => x.SelectedItemsInternal)
.Select(x => x == null ? null : x.CreateDerivedCollection(i => (IHierarchicalLibraryItem) i))
.BindTo(this, x => x.SelectedItems);
UiHelper.TryOnUiThread(() => {
Children.EnableCollectionSynchronization(_childrenLock);
_childrenView =
Children.CreateCollectionView(
new[] {
new SortDescription("SortOrder", ListSortDirection.Ascending),
new SortDescription("Model.IsFavorite", ListSortDirection.Descending),
new SortDescription("Model.Name", ListSortDirection.Ascending)
}, null,
null, null, true);
_itemsView = _childrenView;
});
}
示例5: AccountsViewModel
public AccountsViewModel(IAccountsService accountsService)
{
_accountsService = accountsService;
Accounts = new ReactiveList<IAccount>(accountsService);
LoginCommand = ReactiveCommand.Create();
GoToAddAccountCommand = ReactiveCommand.Create();
DeleteAccountCommand = ReactiveCommand.Create();
DeleteAccountCommand.OfType<IAccount>().Subscribe(x =>
{
if (Equals(accountsService.ActiveAccount, x))
ActiveAccount = null;
accountsService.Remove(x);
Accounts.Remove(x);
});
LoginCommand.OfType<IAccount>().Subscribe(x =>
{
if (Equals(accountsService.ActiveAccount, x))
DismissCommand.ExecuteIfCan();
else
{
ActiveAccount = x;
MessageBus.Current.SendMessage(new LogoutMessage());
DismissCommand.ExecuteIfCan();
}
});
GoToAddAccountCommand.Subscribe(_ => ShowViewModel(CreateViewModel<IAddAccountViewModel>()));
this.WhenActivated(d => Accounts.Reset(accountsService));
}
示例6: BlogViewModel
public BlogViewModel(string title, Uri feedAddress, IFeedService feedService = null, IBlobCache cache = null)
{
Title = title;
FeedAddress = feedAddress;
FeedService = feedService ?? Locator.Current.GetService<IFeedService>();
Cache = cache ?? Locator.Current.GetService<IBlobCache>();
Articles = new ReactiveList<ArticleViewModel>();
Refresh = ReactiveCommand.CreateAsyncObservable(x => GetAndFetchLatestArticles());
Refresh.Subscribe(articles =>
{
// this could be done cleaner, send a PR.
// Refresh.ToPropertyEx(this, x => x.Articles);
Articles.Clear();
Articles.AddRange(articles);
});
Refresh.ThrownExceptions.Subscribe(thrownException => { this.Log().Error(thrownException); });
_isLoading = Refresh.IsExecuting.ToProperty(this, x => x.IsLoading);
// post-condition checks
Condition.Ensures(FeedAddress).IsNotNull();
Condition.Ensures(FeedService).IsNotNull();
Condition.Ensures(Cache).IsNotNull();
}
示例7: MainVM
public MainVM()
{
var bobbyJoe = new Person("Bobby Joe", new[] { new Pet("Fluffy") });
var bob = new Person("Bob", new[] { bobbyJoe });
var littleJoe = new Person("Little Joe");
var joe = new Person("Joe", new[] { littleJoe });
Family = new ReactiveList<TreeItem> { bob, joe };
_addPerson = ReactiveCommand.Create();
_addPerson.Subscribe(_ =>
{
if (SelectedItem == null) return;
var p = new Person(NewName);
SelectedItem.AddChild(p);
p.IsSelected = true;
p.ExpandPath();
});
_addPet = ReactiveCommand.Create();
_addPet.Subscribe(_ =>
{
if (SelectedItem == null) return;
var p = new Pet(PetName);
SelectedItem.AddChild(p);
p.IsSelected = true;
p.ExpandPath();
});
_collapse = ReactiveCommand.Create();
_collapse.Subscribe(_ =>
{
SelectedItem?.CollapsePath();
});
}
示例8: CacheViewModel
public CacheViewModel(IScreen hostScreen, IAppState appState)
{
HostScreen = hostScreen;
appState.WhenAny(x => x.CachePath, x => x.Value)
.Where(x => !String.IsNullOrWhiteSpace(x))
.Select(x => (new DirectoryInfo(x)).Name)
.ToProperty(this, x => x.UrlPathSegment, out _UrlPathSegment);
Keys = new ReactiveList<string>();
appState.WhenAny(x => x.CurrentCache, x => x.Value)
.SelectMany(x => Observable.Start(() => x.GetAllKeys(), RxApp.TaskpoolScheduler))
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(newKeys => {
Keys.Clear();
newKeys.ForEach(x => Keys.Add(x));
});
FilteredKeys = Keys.CreateDerivedCollection(
key => key,
key => FilterText == null || key.IndexOf(FilterText, StringComparison.OrdinalIgnoreCase) > -1,
signalReset: this.WhenAny(x => x.FilterText, x => x.Value));
SelectedViewer = "Text";
this.WhenAny(x => x.SelectedKey, x => x.SelectedViewer, (k, v) => k.Value)
.Where(x => x != null && SelectedViewer != null)
.SelectMany(x => appState.CurrentCache.GetAsync(x).Catch(Observable.Return(default(byte[]))))
.Select(x => createValueViewModel(x, SelectedViewer))
.LoggedCatch(this, Observable.Return<ICacheValueViewModel>(null))
.ToProperty(this, x => x.SelectedValue, out _SelectedValue);
}
示例9: IssueAssigneeViewModel
public IssueAssigneeViewModel(
Func<Task<IReadOnlyList<User>>> loadAssignees,
Func<Task<User>> loadSelectedFunc,
Func<User, Task> saveFunc)
{
var assignees = new ReactiveList<IssueAssigneeItemViewModel>();
Assignees = assignees.CreateDerivedCollection(
x => x,
filter: x => x.Name.ContainsKeyword(SearchKeyword),
signalReset: this.WhenAnyValue(x => x.SearchKeyword));
this.WhenAnyValue(x => x.Selected)
.Subscribe(x => {
foreach (var a in Assignees)
a.IsSelected = string.Equals(a.User.Login, x?.Login);
});
DismissCommand = ReactiveCommand.Create();
SaveCommand = ReactiveCommand.CreateAsyncTask(_ => {
DismissCommand.ExecuteIfCan();
return Selected != _previouslySelected ? saveFunc(_selected) : Task.FromResult(0);
});
LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
_previouslySelected = Selected = await loadSelectedFunc();
assignees.Reset((await loadAssignees()).Select(CreateItemViewModel));
});
}
示例10: IssueMilestonesViewModel
public IssueMilestonesViewModel(IApplicationService applicationService)
{
Milestones = new ReactiveList<MilestoneModel>();
SelectMilestoneCommand = ReactiveCommand.CreateAsyncTask(async t =>
{
var milestone = t as MilestoneModel;
if (milestone != null)
SelectedMilestone = milestone;
if (SaveOnSelect)
{
try
{
int? milestoneNumber = null;
if (SelectedMilestone != null) milestoneNumber = SelectedMilestone.Number;
var updateReq = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[IssueId].UpdateMilestone(milestoneNumber);
await applicationService.Client.ExecuteAsync(updateReq);
}
catch (Exception e)
{
throw new Exception("Unable to to save milestone! Please try again.", e);
}
}
DismissCommand.ExecuteIfCan();
});
LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
Milestones.SimpleCollectionLoad(
applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Milestones.GetAll(),
t as bool?));
}
示例11: CreateCollectionView
private MultiSelectCollectionView<ShortcutViewModel> CreateCollectionView(ReactiveList<ShortcutViewModel> shortcuts)
{
var view = new MultiSelectCollectionView<ShortcutViewModel>(shortcuts);
view.Filter = ApplyFilter;
view.SortDescriptions.Add(new SortDescription(nameof(ShortcutViewModel.Name), ListSortDirection.Ascending));
return view;
}
示例12: IssueLabelsViewModel
public IssueLabelsViewModel(Func<Task<IReadOnlyList<Label>>> loadLabels)
{
var labels = new ReactiveList<Label>();
Selected = new ReactiveList<Label>();
Labels = labels.CreateDerivedCollection(x =>
{
var vm = new IssueLabelItemViewModel(x);
vm.IsSelected = Selected.Any(y => string.Equals(y.Name, x.Name));
// vm.GoToCommand
// .Select(_ => x)
// .Where(y => vm.IsSelected)
// .Where(y => Selected.All(l => l.Url != y.Url))
// .Subscribe(Selected.Add);
// vm.GoToCommand
// .Select(_ => x)
// .Where(y => !vm.IsSelected)
// .Select(y => Selected.Where(l => l.Url == y.Url).ToArray())
// .Subscribe(Selected.RemoveAll);
return vm;
});
SelectLabelsCommand = ReactiveCommand.CreateAsyncTask(t => {
var selectedLabelsUrl = Selected.Select(x => x.Url).ToArray();
var prevSelectedLabelsUrl = _previouslySelectedLabels.Select(x => x.Url).ToArray();
var intersect = selectedLabelsUrl.Intersect(prevSelectedLabelsUrl).ToArray();
var different = selectedLabelsUrl.Length != prevSelectedLabelsUrl.Length || intersect.Length != selectedLabelsUrl.Length;
return Task.FromResult(0); //different ? updateIssue(new ReadOnlyCollection<Label>(Selected)) : Task.FromResult(0);
});
LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
labels.Reset(await loadLabels());
});
}
示例13: ChangesetViewModel
public ChangesetViewModel(IApplicationService applicationService)
{
_applicationService = applicationService;
Comments = new ReactiveList<CommentModel>();
GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Commit).Select(x => x != null));
GoToHtmlUrlCommand.Select(x => Commit).Subscribe(GoToUrlCommand.ExecuteIfCan);
GoToRepositoryCommand = ReactiveCommand.Create();
GoToRepositoryCommand.Subscribe(_ =>
{
var vm = CreateViewModel<RepositoryViewModel>();
vm.RepositoryOwner = RepositoryOwner;
vm.RepositoryName = RepositoryName;
ShowViewModel(vm);
});
GoToFileCommand = ReactiveCommand.Create();
GoToFileCommand.OfType<CommitModel.CommitFileModel>().Subscribe(x =>
{
if (x.Patch == null)
{
var vm = CreateViewModel<SourceViewModel>();
vm.Branch = Commit.Sha;
vm.Username = RepositoryOwner;
vm.Repository = RepositoryName;
vm.Items = new []
{
new SourceViewModel.SourceItemModel
{
ForceBinary = true,
GitUrl = x.BlobUrl,
Name = x.Filename,
Path = x.Filename,
HtmlUrl = x.BlobUrl
}
};
vm.CurrentItemIndex = 0;
ShowViewModel(vm);
}
else
{
var vm = CreateViewModel<ChangesetDiffViewModel>();
vm.Username = RepositoryOwner;
vm.Repository = RepositoryName;
vm.Branch = Commit.Sha;
vm.Filename = x.Filename;
ShowViewModel(vm);
}
});
LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
{
var forceCacheInvalidation = t as bool?;
var t1 = this.RequestModel(_applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Commits[Node].Get(), forceCacheInvalidation, response => Commit = response.Data);
Comments.SimpleCollectionLoad(_applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Commits[Node].Comments.GetAll(), forceCacheInvalidation).FireAndForget();
return t1;
});
}
示例14: AppState
public AppState()
{
Articles = new ReactiveList<Article> ();
ElectionArticles = new ReactiveList<ElectionArticle> ();
Events = new ReactiveList<Event> ();
OrganizationMenuItems = new ReactiveList<OrganizationMenuItem> ();
}
示例15: ViewModel2
public ViewModel2()
{
SearchResults = new ReactiveList<FlickrPhoto>();
var canSearch = this.WhenAny(x => x.SearchTerm, x => !String.IsNullOrWhiteSpace(x.Value));
Search = ReactiveCommand.CreateAsyncTask(canSearch, async _ => { return await GetSearchResultFromBing(this.SearchTerm); });
LoadMoreItems = ReactiveCommand.CreateAsyncTask(canSearch, async x => { return await LoadMore((int)x); });
Search.Subscribe(results =>
{
SearchResults.Clear();
foreach (var item in results)
{
SearchResults.Add(item);
}
});
LoadMoreItems.Subscribe(results =>
{
foreach (var item in results)
{
SearchResults.Add(item);
}
});
Search.ThrownExceptions.Subscribe(ex => { UserError.Throw("Potential network connectivity Error", ex); });
LoadMoreItems.ThrownExceptions.Subscribe(ex => { UserError.Throw("Problem when downloading additional items", ex); });
this.WhenAnyValue(x => x.SearchTerm)
.Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
.InvokeCommand(this, x => x.Search);
//SearchTerm = "british cat";
}