Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/pierrejean-coudert/ReduxDelphi

ReduxDelphi is a predictable state container for Delphi apps utilizing a unidirectional data flow. Inspired by https://github.com/reactjs/redux .
https://github.com/pierrejean-coudert/ReduxDelphi

delphi library object-pascal redux

Last synced: about 2 months ago
JSON representation

ReduxDelphi is a predictable state container for Delphi apps utilizing a unidirectional data flow. Inspired by https://github.com/reactjs/redux .

Lists

README

        

# ReduxDelphi

ReduxDelphi is a predictable state container for Delphi apps utilizing a unidirectional data flow. Inspired by https://github.com/reactjs/redux .

This project is currently developed with Delphi 10.1

The TodoMVC sample is based on immutable data structures (Generic immutable lists).

## Counter sample code

Here is a simple example showing the basic usage of Store, Actions, Dispatch,...:

```Pascal
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;
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;
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.Create(FReducer, 0);
FStore.subscribe( procedure (State: Integer)
begin
LabelCounter.Caption := IntToStr(State);
end
);
FStore.dispatch(INIT);
end;

end.
```