สเตเตอร์เป็นการ ทดลอง แบบง่าย ๆ แบบ di-oriented, redux ที่ได้รับแรงบันดาลใจหรือการทดลองแบบจำลองการอัปเดต (MVU) โดยใช้ C# 9.0 มันทำงานได้ดีกับ Blazor และ Mobileblazorbindings รวมถึงการแบ่งปันสถานะระหว่างส่วน Xamarin และส่วน Blazor ของแอพมือถือไฮบริด มันควรจะทำงานร่วมกับโมเดลไคลเอนต์. NET Stateful อื่น ๆ
ณ ปี 2021-04-08 โครงการไม่รองรับ. NET Standard 2.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 ค่าของคุณสมบัติ Count ของ Counter.State นั้น ตัวอย่างยังรวมถึง 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 } ;
}
}
} จากส่วนประกอบของ Blazor ที่สืบทอดมาจาก StatorComponent เราสามารถส่งการกระทำเหล่านั้นได้
@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 และแอพไฮบริดใหม่ฉันพบว่าบันทึก C# 9 นั้นเหมาะสมมากสำหรับสิ่งนี้ ฉันเริ่มทดลองกับการแปลงประเภทที่ไม่เปลี่ยนรูป (บันทึก) และจบลงด้วยการสร้างโครงการนี้
ชื่อ StateR , Stator เด่นชัดได้รับแรงบันดาลใจจาก MediatR ที่ใช้ครั้งแรกภายใต้ฮูดเพื่อไกล่เกลี่ยคำสั่ง
สเตเตอร์เป็นส่วนที่อยู่นิ่งของระบบโรตารี [... ] พลังงานไหลผ่านสเตเตอร์ไปยังหรือจากส่วนประกอบหมุนของระบบ
ที่มา: Wikipedia
หลังจากได้ยินเกี่ยวกับเรื่องนี้มาหลายปีแล้วฉันอ่านเกี่ยวกับเรื่องนี้และพบแนวคิดที่ยอดเยี่ยมทดลองใช้และนำแนวคิดมาใช้
ห้องสมุดนี้ใช้แนวคิดที่แนะนำโดย Redux แต่. NET ไม่ใช่ JavaScript และ. NET Core ถูกสร้างขึ้นรอบ ๆ การฉีดพึ่งพา (DI) ดังนั้นฉันจึงตัดสินใจใช้ประโยชน์จากสิ่งนั้น
ไม่มีประเภทและไม่มี DI จริงใน JavaScript ดังนั้นจึงสมเหตุสมผลที่คนที่นั่นไม่ได้คำนึงถึงสิ่งนั้นเมื่อพวกเขาสร้าง 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