namespace GFramework.Core.Abstractions.StateManagement; /// /// 定义 Store 构建器接口,用于在创建 Store 之前完成 reducer、中间件和比较器配置。 /// 该抽象适用于模块化注册、依赖注入装配和测试工厂,避免调用方必须依赖具体 Store 类型进行配置。 /// /// 状态树的根状态类型。 public interface IStoreBuilder { /// /// 配置用于判断状态是否真正变化的比较器。 /// /// 状态比较器。 /// 当前构建器实例。 IStoreBuilder WithComparer(IEqualityComparer comparer); /// /// 配置历史缓冲区容量。 /// 传入 0 表示禁用历史记录;大于 0 时会保留最近若干个状态快照,用于撤销、重做和时间旅行调试。 /// /// 历史缓冲区容量。 /// 当前构建器实例。 IStoreBuilder WithHistoryCapacity(int historyCapacity); /// /// 配置 reducer 的 action 匹配策略。 /// 默认使用 ,仅在需要复用基类或接口 action 层次时再启用多态匹配。 /// /// 要使用的匹配策略。 /// 当前构建器实例。 IStoreBuilder WithActionMatching(StoreActionMatchingMode actionMatchingMode); /// /// 添加一个强类型 reducer。 /// /// 当前 reducer 处理的 action 类型。 /// 要添加的 reducer。 /// 当前构建器实例。 IStoreBuilder AddReducer(IReducer reducer); /// /// 使用委托快速添加一个 reducer。 /// /// 当前 reducer 处理的 action 类型。 /// 执行归约的委托。 /// 当前构建器实例。 IStoreBuilder AddReducer(Func reducer); /// /// 添加一个 Store 中间件。 /// /// 要添加的中间件。 /// 当前构建器实例。 IStoreBuilder UseMiddleware(IStoreMiddleware middleware); /// /// 基于给定初始状态创建一个新的 Store。 /// /// Store 的初始状态。 /// 已应用当前构建器配置的 Store 实例。 IStore Build(TState initialState); }