BlazorwithFluxor:我可以拥有多个同一存储的实例吗?
创始人
2024-12-22 02:00:11
0

在Fluxor中,每个存储都是一个单例,这意味着您不能直接创建多个存储实例。但是,您可以使用不同的功能模块为不同组件提供不同的状态管理。

例如,假设您有两个组件需要管理站点信息。要做到这一点,您可以创建另一个站点信息特定的特征模块(这里我们称其为SiteFeature),它将包含一个SiteState和一个Site存储。

SiteFeature类如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Fluxor;

namespace BlazorFluxorSample.Features.Sites
{
    public class SiteFeature : Feature
    {
        public override string GetName() => "Sites";
        protected override SiteState GetInitialState() =>
            new SiteState(isLoading: true);
    }
}

SiteState看起来像这样:

using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BlazorFluxorSample.Features.Sites
{
    public class SiteState
    {
        public SiteState(bool isLoading,
            ICollection sites = null,
            Site currentSite = null,
            bool? isCreating = null,
            bool? isEditing = null,
            bool? isDeleting = null,
            bool? isWarning = null,
            bool? isSuccess = null,
            string message = null,
            Exception exception = null)
        {
            IsLoading = isLoading;
            Sites = sites ?? new List();
            CurrentSite = currentSite;
            IsCreating = isCreating;
            IsEditing = isEditing;
            IsDeleting = isDeleting;
            IsWarning = isWarning;
            IsSuccess = isSuccess;
            Message = message;
            Exception = exception;
        }

        public bool IsLoading { get; }
        public ICollection Sites { get; }
        public Site CurrentSite { get; }
        public bool? IsCreating { get; }
        public bool? Is

相关内容

热门资讯

黑科技辅助!wpk辅助神器,(... 黑科技辅助!wpk辅助神器,(WPK辅助器)原来真的有挂,攻略教程(辅助)-哔哩哔哩;WPK辅助器是...
黑科技辅助!微扑克辅助挂,(微... 黑科技辅助!微扑克辅助挂,(微扑克辅助)原来真的有挂,2025新版教程(真是)-哔哩哔哩;AI辅助机...
黑科技辅助!微扑克辅助透视技能... 黑科技辅助!微扑克辅助透视技能教程,(微扑克安卓版本)原来真的有挂,第三方教程(教程)-哔哩哔哩是一...
黑科技辅助!aapoker有外... 黑科技辅助!aapoker有外挂,(AAPoKer ai)原来真的有挂,技巧教程(方式)-哔哩哔哩;...
黑科技辅助!wepokeai代... 黑科技辅助!wepokeai代打的胜率,(Wepoke插件挂)原来真的有挂,存在挂教程(有挂工具)-...
黑科技辅助!aapoker辅助... 黑科技辅助!aapoker辅助,(AAPoKer工具)原来真的有挂,2025新版技巧(解惑)-哔哩哔...
黑科技辅助!悟空黑桃a金花是真... 黑科技辅助!悟空黑桃a金花是真人,(悟空黑桃a真人)原来真的有挂,普及教程(新版)-哔哩哔哩;1.悟...
黑科技辅助!wepoke辅助,... 黑科技辅助!wepoke辅助,(WePoKe能玩)原来真的有挂,必赢方法(真的有挂)-哔哩哔哩;We...
黑科技辅助!微扑克有辅助透视,... 黑科技辅助!微扑克有辅助透视,(微扑克辅助挂)原来真的有挂,微扑克教程(证实)-哔哩哔哩;2. 七法...
黑科技辅助!wepoke插件,... 黑科技辅助!wepoke插件,(Wepoke代码)原来真的有挂,详细教程(有挂秘笈)-哔哩哔哩;人气...