本文整理汇总了C#中ReactiveList.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# ReactiveList.Reset方法的具体用法?C# ReactiveList.Reset怎么用?C# ReactiveList.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReactiveList
的用法示例。
在下文中一共展示了ReactiveList.Reset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BaseEventsViewModel
protected BaseEventsViewModel(IApplicationService applicationService)
{
ApplicationService = applicationService;
var events = new ReactiveList<EventModel>();
Events = events.CreateDerivedCollection(CreateEventTextBlocks);
ReportRepository = true;
GoToRepositoryCommand = ReactiveCommand.Create();
GoToRepositoryCommand.OfType<EventModel.RepoModel>().Subscribe(x =>
{
var repoId = new RepositoryIdentifier(x.Name);
var vm = CreateViewModel<RepositoryViewModel>();
vm.RepositoryOwner = repoId.Owner;
vm.RepositoryName = repoId.Name;
ShowViewModel(vm);
});
GoToGistCommand = ReactiveCommand.Create();
GoToGistCommand.OfType<EventModel.GistEvent>().Subscribe(x =>
{
var vm = CreateViewModel<GistViewModel>();
vm.Id = x.Gist.Id;
vm.Gist = x.Gist;
ShowViewModel(vm);
});
LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
this.RequestModel(CreateRequest(0, 100), t as bool?, response =>
{
//this.CreateMore(response, m => { }, events.AddRange);
events.Reset(response.Data);
}));
}
示例2: ExploreViewModel
public ExploreViewModel(ISessionService applicationService)
{
ShowRepositoryDescription = applicationService.Account.ShowRepositoryDescriptionInList;
Title = "Explore";
var gotoRepository = new Action<RepositoryItemViewModel>(x => {
var vm = this.CreateViewModel<RepositoryViewModel>();
vm.RepositoryOwner = x.Owner;
vm.RepositoryName = x.Name;
NavigateTo(vm);
});
var repositories = new ReactiveList<Octokit.Repository>();
Repositories = repositories.CreateDerivedCollection(x =>
new RepositoryItemViewModel(x, true, gotoRepository));
var users = new ReactiveList<Octokit.User>();
Users = users.CreateDerivedCollection(x =>
new UserItemViewModel(x.Login, x.AvatarUrl, false, () => {
var vm = this.CreateViewModel<UserViewModel>();
vm.Init(x.Login);
NavigateTo(vm);
}));
this.WhenAnyValue(x => x.SearchFilter)
.DistinctUntilChanged()
.Subscribe(_ => {
SearchText = string.Empty;
users.Clear();
repositories.Clear();
});
var canSearch = this.WhenAnyValue(x => x.SearchText).Select(x => !string.IsNullOrEmpty(x));
SearchCommand = ReactiveCommand.CreateAsyncTask(canSearch, async t => {
try
{
users.Clear();
repositories.Clear();
if (SearchFilter == SearchType.Repositories)
{
var request = new Octokit.SearchRepositoriesRequest(SearchText);
var response = await applicationService.GitHubClient.Search.SearchRepo(request);
repositories.Reset(response.Items);
}
else if (SearchFilter == SearchType.Users)
{
var request = new Octokit.SearchUsersRequest(SearchText);
var response = await applicationService.GitHubClient.Search.SearchUsers(request);
users.Reset(response.Items);
}
}
catch (Exception e)
{
var msg = string.Format("Unable to search for {0}. Please try again.", SearchFilter.Humanize());
throw new Exception(msg, e);
}
});
}
示例3: LanguagesViewModel
public LanguagesViewModel()
{
Title = "Languages";
var languages = new ReactiveList<Language>();
Languages = languages.CreateDerivedCollection(
x => new LanguageItemViewModel(x.Name, x.Slug),
filter: 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;
});
this.WhenAnyValue(x => x.SelectedLanguage)
.IsNotNull()
.Subscribe(_ => Dismiss());
LoadCommand = ReactiveCommand.CreateAsyncTask(async t =>
{
var languageRepository = new LanguageRepository();
var langs = await languageRepository.GetLanguages();
langs.Insert(0, LanguageRepository.DefaultLanguage);
languages.Reset(langs);
});
}
示例4: 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());
});
}
示例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: 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));
});
}
示例7: IssueLabelsViewModel
public IssueLabelsViewModel(
Func<Task<IReadOnlyList<Label>>> loadAllLabelsFunc,
Func<Task<IReadOnlyList<Label>>> loadSelectedFunc,
Func<IEnumerable<Label>, Task> saveLabelsFunc)
{
var labels = new ReactiveList<Label>();
var selected = new ReactiveList<Label>();
Labels = labels.CreateDerivedCollection(x =>
{
var vm = new IssueLabelItemViewModel(x);
vm.IsSelected = selected.Any(y => y.Url == x.Url);
return vm;
});
SaveCommand = ReactiveCommand.CreateAsyncTask(_ =>
{
var currentlySelected = Labels.Where(x => x.IsSelected).ToList();
var selectedLabelsUrl = currentlySelected.Select(x => x.Label.Url).ToArray();
var prevSelectedLabelsUrl = selected.Select(x => x.Url).ToArray();
var intersect = selectedLabelsUrl.Intersect(prevSelectedLabelsUrl).ToArray();
var different = selectedLabelsUrl.Length != prevSelectedLabelsUrl.Length || intersect.Length != selectedLabelsUrl.Length;
return different ? saveLabelsFunc(currentlySelected.Select(x => x.Label)) : Task.FromResult(0);
});
LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
selected.Clear();
selected.AddRange((await loadSelectedFunc()) ?? Enumerable.Empty<Label>());
labels.Reset(await loadAllLabelsFunc());
});
}
示例8: 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());
});
}
示例9: 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();
}
示例10: PullRequestsViewModel
public PullRequestsViewModel(IApplicationService applicationService)
{
PullRequests = new ReactiveList<PullRequestModel>();
GoToPullRequestCommand = ReactiveCommand.Create();
GoToPullRequestCommand.OfType<PullRequestModel>().Subscribe(pullRequest =>
{
var vm = CreateViewModel<PullRequestViewModel>();
vm.RepositoryOwner = RepositoryOwner;
vm.RepositoryName = RepositoryName;
vm.PullRequestId = pullRequest.Number;
vm.PullRequest = pullRequest;
vm.WhenAnyValue(x => x.PullRequest).Skip(1).Subscribe(x =>
{
var index = PullRequests.IndexOf(pullRequest);
if (index < 0) return;
PullRequests[index] = x;
PullRequests.Reset();
});
ShowViewModel(vm);
});
this.WhenAnyValue(x => x.SelectedFilter).Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan());
LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
{
var state = SelectedFilter == 0 ? "open" : "closed";
var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].PullRequests.GetAll(state: state);
return PullRequests.SimpleCollectionLoad(request, t as bool?);
});
}
示例11: ReleasesViewModel
public ReleasesViewModel(ISessionService applicationService)
{
Title = "Releases";
var releases = new ReactiveList<Octokit.Release>();
Releases = releases.CreateDerivedCollection(CreateItemViewModel, x => !x.Draft);
LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
releases.Reset(await applicationService.GitHubClient.Release.GetAll(RepositoryOwner, RepositoryName)));
}
示例12: CommitBranchesViewModel
public CommitBranchesViewModel(ISessionService applicationService)
{
Title = "Commit Branch";
var branches = new ReactiveList<Octokit.Branch>();
Branches = branches.CreateDerivedCollection(
x => new BranchItemViewModel(x.Name, () => {
var vm = this.CreateViewModel<CommitsViewModel>();
NavigateTo(vm.Init(RepositoryOwner, RepositoryName, x.Name));
}),
filter: x => x.Name.ContainsKeyword(SearchKeyword),
signalReset: this.WhenAnyValue(x => x.SearchKeyword));
LoadCommand = ReactiveCommand.CreateAsyncTask(async t =>
branches.Reset(await applicationService.GitHubClient.Repository.GetAllBranches(RepositoryOwner, RepositoryName)));
}
示例13: FeedbackViewModel
public FeedbackViewModel(ISessionService applicationService)
{
Title = "Feedback";
var items = new ReactiveList<Octokit.Issue>();
Items = items.CreateDerivedCollection(x => new FeedbackItemViewModel(x, () => {
var vm = this.CreateViewModel<IssueViewModel>();
vm.Init(CodeHubOwner, CodeHubName, x.Number);
NavigateTo(vm);
}),
filter: x => x.Title.ContainsKeyword(SearchKeyword),
signalReset: this.WhenAnyValue(x => x.SearchKeyword));
LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
items.Reset(await applicationService.GitHubClient.Issue.GetAllForRepository(CodeHubOwner, CodeHubName)));
}
示例14: OrganizationsViewModel
public OrganizationsViewModel(ISessionService applicationService)
{
Title = "Organizations";
var organizations = new ReactiveList<Octokit.Organization>();
Organizations = organizations.CreateDerivedCollection(
x => new UserItemViewModel(x.Login, x.AvatarUrl, true, () => {
var vm = this.CreateViewModel<OrganizationViewModel>();
vm.Init(x.Login, x);
NavigateTo(vm);
}),
filter: x => x.Name.ContainsKeyword(SearchKeyword),
signalReset: this.WhenAnyValue(x => x.SearchKeyword));
LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
organizations.Reset(await applicationService.GitHubClient.Organization.GetAll(Username)));
}
示例15: TrendingViewModel
public TrendingViewModel(INetworkActivityService networkActivity, TrendingRepository trendingRepository)
{
SelectedLanguage = _defaultLanguage;
var repositories = new ReactiveList<TrendingRepositoryViewModel>();
Repositories = repositories.CreateDerivedCollection(x => x);
GoToRepositoryCommand = ReactiveCommand.Create();
GoToRepositoryCommand.OfType<Octokit.Repository>().Subscribe(x =>
{
var vm = CreateViewModel<RepositoryViewModel>();
vm.RepositoryIdentifier = new BaseRepositoryViewModel.RepositoryIdentifierModel(x.Owner.Login, x.Name);
ShowViewModel(vm);
});
GoToLanguages = ReactiveCommand.Create();
GoToLanguages.Subscribe(_ =>
{
var vm = CreateViewModel<LanguagesViewModel>();
vm.ExtraLanguages.Add(_defaultLanguage);
vm.SelectedLanguage = SelectedLanguage;
vm.WhenAnyValue(x => x.SelectedLanguage).Skip(1).Subscribe(x =>
{
SelectedLanguage = x;
vm.DismissCommand.ExecuteIfCan();
});
ShowViewModel(vm);
});
this.WhenAnyValue(x => x.SelectedLanguage).Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan());
LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
{
var tempRepos = new List<TrendingRepositoryViewModel>();
foreach (var t in _times)
{
var language = SelectedLanguage == null ? null : SelectedLanguage.Slug;
var repos = await trendingRepository.GetTrendingRepositories(t.Slug, language);
tempRepos.AddRange(repos.Select(x => new TrendingRepositoryViewModel { Repository = x, Time = t.Name } ));
}
repositories.Reset(tempRepos);
});
LoadCommand.TriggerNetworkActivity(networkActivity);
}