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 .
- Host: GitHub
- URL: https://github.com/pierrejean-coudert/ReduxDelphi
- Owner: pierrejean-coudert
- License: mit
- Created: 2017-03-03T07:30:51.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-02-08T08:33:19.000Z (over 4 years ago)
- Last Synced: 2024-01-27T09:08:26.781Z (5 months ago)
- Topics: delphi, library, object-pascal, redux
- Language: Pascal
- Homepage:
- Size: 81.1 KB
- Stars: 44
- Watchers: 12
- Forks: 22
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-pascal - Redux Delphi
- awesome-delphi - Redux Delphi
- awesome-delphi - Redux Delphi
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.
```