ReduxDelphi
1.0.0
Reduxdelphi เป็นคอนเทนเนอร์สถานะที่คาดการณ์ได้สำหรับแอพ Delphi ที่ใช้การไหลของข้อมูลทิศทางเดียว แรงบันดาลใจจาก https://github.com/reactjs/redux
โครงการนี้ได้รับการพัฒนาด้วย Delphi 10.1
ตัวอย่าง TODOMVC ขึ้นอยู่กับโครงสร้างข้อมูลที่ไม่เปลี่ยนรูป (รายการทั่วไปที่ไม่เปลี่ยนรูป)
นี่คือตัวอย่างง่ายๆที่แสดงการใช้งานขั้นพื้นฐานของร้านค้าการกระทำการจัดส่ง ... :
unit DemoCounterForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
Redux;
type
TEnumAction= (INIT, INCREMENT, DECREMENT);
TFormDemoCounter = class (TForm)
ButtonInc: TButton;
ButtonDec: TButton;
LabelCounter: TLabel;
procedure ButtonIncClick (Sender: TObject);
procedure ButtonDecClick (Sender: TObject);
procedure FormShow (Sender: TObject);
private
FStore : IStore<Integer, TEnumAction>;
end ;
var
FormDemoCounter: TFormDemoCounter;
implementation
{ $R *.dfm }
procedure TFormDemoCounter.ButtonIncClick (Sender: TObject);
begin
FStore.dispatch(INCREMENT);
end ;
procedure TFormDemoCounter.ButtonDecClick (Sender: TObject);
begin
FStore.dispatch(DECREMENT);
end ;
procedure TFormDemoCounter.FormShow (Sender: TObject);
var
FReducer : TReducer<Integer,TEnumAction>;
begin
FReducer :=
function(State: Integer; Action: TEnumAction): Integer
begin
case Action of
INCREMENT:
Result := State + 1 ;
DECREMENT:
Result := State - 1 ;
else
Result := State;
end ;
end ;
FStore := TStore<Integer, TEnumAction>.Create(FReducer, 0 );
FStore.subscribe( procedure (State: Integer)
begin
LabelCounter.Caption := IntToStr(State);
end
);
FStore.dispatch(INIT);
end ;
end .