定子是一種使用C#9.0的簡單,面向DI的,面向REDUX啟發或模型視圖上升(MVU)實驗。它可以與大麻和移動布拉索互動合作,包括在Xamarin部分和混合移動應用程序的大麻片之間共享狀態。它還應該與任何其他.NET狀態客戶端模型一起使用。
截至2021-04-08,該項目不支持.NET標準2.0,僅0.NET 5+
該項目使用:
| 姓名 | nuget.org | feedz.io |
|---|---|---|
dotnet add package StateR | ||
dotnet add package StateR.Blazor | ||
dotnet add package StateR.Blazor.Experiments | ||
dotnet add package StateR.Experiments |
以下片段代表了一個圍繞計數器的功能,您可以在其中Increment , Decrement並Set該Counter.State的Count屬性的值。該片段還包括該計數器的InitialState 。
services
. AddStateR ( appAssembly )
. AddAsyncOperations ( ) // Add support for Redux thunk-like helpers
. AddReduxDevTools ( ) // Add support for Redux DevTools
. Apply ( )
; using StateR ;
namespace BlazorMobileHybridExperiments . Features
{
public class Counter
{
public record State ( int Count ) : StateBase ;
public class InitialState : IInitialState < State >
{
public State Value => new State ( 0 ) ;
}
public record Increment : IAction ;
public record Decrement : IAction ;
public class Reducers : IReducer < State , Increment > , IReducer < State , Decrement >
{
public State Reduce ( State state , Increment action ) => state with { Count = state . Count + 1 } ;
public State Reduce ( State state , Decrement action ) => state with { Count = state . Count - 1 } ;
}
}
}然後,從從StatorComponent component繼承的大黃色組件中,我們可以派遣這些動作。
@page "/counter"
@inherits StateR . Blazor . StatorComponent
@inject IState < Features . Counter . State > CounterState
< h1 > Counter < / h1 >
< p > Current count : @CounterState . Current . Count < / p >
< button class = "btn btn-primary" @onclick = "@(async () => await DispatchAsync(new Features.Counter.Increment()))" > + < / button >
< button class = "btn btn-primary" @onclick = "@(async () => await DispatchAsync(new Features.Counter.Decrement()))" > - < / button >它不需要從
StatorComponent繼承,組件(或任何類)可以手動訂閱任何IState<T>。
我和其他一些圖書館一起玩了,我對他們的工作方式並不100%。因此,在使用MobileblazorBindings和新的Hybrid應用程序玩耍時,我發現C#9唱片非常適合這一點。我開始嘗試轉換不變的類型(記錄),並最終創建此項目。
StateR名稱(發音為Stator的靈感來自MediatR ,最初是在引擎蓋下用於調解命令的。
定子是旋轉系統的固定部分[...]。能量流過定子往返系統的旋轉組件。
資料來源:維基百科
在聽到了多年的了解之後,我讀到了有關它的知識,並發現了這個概念出色,對此進行了實驗,並採用了這個想法。
該庫基於Redux引入的概念,但是.NET不是JavaScript,並且.NET Core圍繞依賴注入(DI)構建,因此我決定利用這一點。
JavaScript中沒有類型,也沒有真正的DI,因此當那裡的人們在建造Redux時沒有考慮到這一點是有道理的。
我將Redux DevTools實現基於Fluxor,這是一個類似的項目,我曾經使用過一次。這幫助我縮短了將定子與Redux Devtools連接的實現時間;謝謝。
...
請打開一個問題,並儘可能清楚;看看如何做出貢獻?有關更多信息。
如果您想為該項目做出貢獻,請首先感謝您的興趣,並請閱讀為Forevolve開源項目做出貢獻以獲取更多信息。
另外,請閱讀適用於所有前伏存儲庫的貢獻者盟約行為準則。
dotnet test /p:CollectCoverage=true => coverage.json
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura => coverage.cobertura.xml
dotnet test --collect:"XPlat Code Coverage" => testResults/{guid}/coverage.cobertura.xml
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:coverage.cobertura.xml -targetdir:coveragereport -reporttypes:Html
dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
reportgenerator " -reports:test**coverage.cobertura.xml " -targetdir:coveragereport -reporttypes:Html