Skip to content

Commit

Permalink
renamed IObservable<T> to Observable<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
sglienke committed Jun 26, 2015
1 parent 8619c87 commit 028eaa7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 56 deletions.
28 changes: 14 additions & 14 deletions MainViewModel.pas
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ TTicket = class

TViewModel = class(TComponent)
private
fLastName: IObservable<string>;
fFirstName: IObservable<string>;
fFullName: IObservable<string>;
fNumberOfClicks: IObservable<Integer>;
fHasClickedTooManyTimes: IObservable<Boolean>;
fChosenTicket: IObservable<TTicket>;
fLastName: Observable<string>;
fFirstName: Observable<string>;
fFullName: Observable<string>;
fNumberOfClicks: Observable<Integer>;
fHasClickedTooManyTimes: Observable<Boolean>;
fChosenTicket: Observable<TTicket>;
fTickets: TList<TTicket>;
fAvailableCountries: TArray<string>;
fCountry: IObservable<string>;
fActive: IObservable<Boolean>;
fCountry: Observable<string>;
fActive: Observable<Boolean>;

function GetLastName: string;
procedure SetLastName(const value: string);
Expand All @@ -45,17 +45,17 @@ TViewModel = class(TComponent)
procedure ResetTicket;

property LastName: string read GetLastName write SetLastName;
property FirstName: IObservable<string> read fFirstName;
property FullName: IObservable<string> read fFullName;
property FirstName: Observable<string> read fFirstName;
property FullName: Observable<string> read fFullName;

property NumberOfClicks: IObservable<Integer> read fNumberOfClicks;
property HasClickedTooManyTimes: IObservable<Boolean> read fHasClickedTooManyTimes;
property NumberOfClicks: Observable<Integer> read fNumberOfClicks;
property HasClickedTooManyTimes: Observable<Boolean> read fHasClickedTooManyTimes;

property ChosenTicket: IObservable<TTicket> read fChosenTicket;
property ChosenTicket: Observable<TTicket> read fChosenTicket;
property Tickets: TList<TTicket> read fTickets;

property AvailableCountries: TArray<string> read fAvailableCountries;
property Country: IObservable<string> read fCountry;
property Country: Observable<string> read fCountry;

property Active: Boolean read GetActive write SetActive;
end;
Expand Down
31 changes: 14 additions & 17 deletions ObservableTests.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ TObservableTests = class(TTestCase)

implementation

type
KO = Observable;

{ TObservableTests }

procedure TObservableTests.DependentObservableClearsOldDependencies;
var
a: IObservable<Boolean>;
b, c: IObservable<string>;
o: IObservable<string>;
a: Observable<Boolean>;
b, c: Observable<string>;
o: Observable<string>;
count: Integer;
begin
a := KO.Create(False);
Expand Down Expand Up @@ -62,31 +59,31 @@ procedure TObservableTests.DependentObservableClearsOldDependencies;

procedure TObservableTests.DependentObservableEvaluatesOnlyOnceAfterChange;
var
o: IObservable<string>;
o: Observable<string>;
count: Integer;
begin
count := 0;
o := TDependentObservable<string>.Create(function: string begin Inc(count); Result := 'test' end);
o := KO.Computed<string>(function: string begin Inc(count); Result := 'test' end);
CheckEquals('test', o);
CheckEquals('test', o);
CheckEquals(1, count);
end;

procedure TObservableTests.DependentObservableReturnsValue;
var
o: IObservable<string>;
o: Observable<string>;
begin
o := TDependentObservable<string>.Create(function: string begin Result := 'test' end);
o := KO.Computed<string>(function: string begin Result := 'test' end);
CheckEquals('test', o);
end;

procedure TObservableTests.DependentObservableUpdatesValueWhenDependencyChanges;
var
o1, o2: IObservable<string>;
o1, o2: Observable<string>;
called: Boolean;
begin
o1 := TObservable<string>.Create();
o2 := TDependentObservable<string>.Create(function: string begin Result := o1; called := True; end);
o1 := KO.Create<string>();
o2 := KO.Computed<string>(function: string begin Result := o1; called := True; end);
CheckEquals('', o2);
called := False;
o1('test');
Expand All @@ -96,17 +93,17 @@ procedure TObservableTests.DependentObservableUpdatesValueWhenDependencyChanges;

procedure TObservableTests.ObservableReturnsValue;
var
o: IObservable<string>;
o: Observable<string>;
begin
o := TObservable<string>.Create('test');
o := KO.Create('test');
CheckEquals('test', o);
end;

procedure TObservableTests.ObservableSetValueChangesValue;
var
o: IObservable<string>;
o: Observable<string>;
begin
o := TObservable<string>.Create();
o := KO.Create<string>();
CheckEquals('', o);
o('test');
CheckEquals('test', o);
Expand Down
24 changes: 12 additions & 12 deletions SimpleMVVM.Observable.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ interface
end;

{$M+}
IReadOnlyObservable<T> = reference to function: T;
IObservable<T> = interface(IReadOnlyObservable<T>)
ReadOnlyObservable<T> = reference to function: T;
Observable<T> = interface(ReadOnlyObservable<T>)
{$REGION 'Property Accessors'}
procedure Invoke(const value: T); overload;
{$ENDREGION}
Expand Down Expand Up @@ -109,7 +109,7 @@ TDependentObservable = class(TObservableBase)
constructor Create(const getter: TFunc<TValue>; const setter: TAction<TValue>); overload;
end;

TObservable<T> = class(TObservableBase, IObservable<T>)
TObservable<T> = class(TObservableBase, Observable<T>)
private
fValue: T;
class var Comparer: IEqualityComparer<T>;
Expand All @@ -126,7 +126,7 @@ TObservable<T> = class(TObservableBase, IObservable<T>)
constructor Create(const value: T); overload;
end;

TDependentObservable<T> = class(TObservableBase, IObservable<T>)
TDependentObservable<T> = class(TObservableBase, Observable<T>)
private
fGetter: TFunc<T>;
fSetter: TAction<T>;
Expand All @@ -152,11 +152,11 @@ TValueHelper = record helper for TValue
end;

Observable = record
class function Create<T>: IObservable<T>; overload; static; inline;
class function Create<T>(const value: T): IObservable<T>; overload; static; inline;
class function Create<T>: Observable<T>; overload; static; inline;
class function Create<T>(const value: T): Observable<T>; overload; static; inline;

class function Computed<T>(const getter: TFunc<T>): IObservable<T>; overload; static; inline;
class function Computed<T>(const getter: TFunc<T>; const setter: TAction<T>): IObservable<T>; overload; static; inline;
class function Computed<T>(const getter: TFunc<T>): Observable<T>; overload; static; inline;
class function Computed<T>(const getter: TFunc<T>; const setter: TAction<T>): Observable<T>; overload; static; inline;
end;

implementation
Expand Down Expand Up @@ -517,23 +517,23 @@ procedure TDependentObservable<T>.Subscribe(const action: TAction<T>;

{$REGION 'Observable'}

class function Observable.Create<T>: IObservable<T>;
class function Observable.Create<T>: Observable<T>;
begin
Result := TObservable<T>.Create();
end;

class function Observable.Create<T>(const value: T): IObservable<T>;
class function Observable.Create<T>(const value: T): Observable<T>;
begin
Result := TObservable<T>.Create(value);
end;

class function Observable.Computed<T>(const getter: TFunc<T>): IObservable<T>;
class function Observable.Computed<T>(const getter: TFunc<T>): Observable<T>;
begin
Result := TDependentObservable<T>.Create(getter);
end;

class function Observable.Computed<T>(const getter: TFunc<T>;
const setter: TAction<T>): IObservable<T>;
const setter: TAction<T>): Observable<T>;
begin
Result := TDependentObservable<T>.Create(getter, setter);
end;
Expand Down
26 changes: 13 additions & 13 deletions TournamentViewModel.pas
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ interface
type
TMatch = class
private
fHomeTeam: IObservable<string>;
fAwayTeam: IObservable<string>;
fHomeScore: IObservable<Integer>;
fAwayScore: IObservable<Integer>;
fWinner: IObservable<string>;
fHomeTeam: Observable<string>;
fAwayTeam: Observable<string>;
fHomeScore: Observable<Integer>;
fAwayScore: Observable<Integer>;
fWinner: Observable<string>;
public
constructor Create(const matchName: string;
const homeTeam: IObservable<string>;
const awayTeam: IObservable<string>);
const homeTeam: Observable<string>;
const awayTeam: Observable<string>);

procedure SaveScore;

property HomeTeam: IObservable<string> read fHomeTeam;
property AwayTeam: IObservable<string> read fAwayTeam;
property HomeScore: IObservable<Integer> read fHomeScore;
property AwayScore: IObservable<Integer> read fAwayScore;
property HomeTeam: Observable<string> read fHomeTeam;
property AwayTeam: Observable<string> read fAwayTeam;
property HomeScore: Observable<Integer> read fHomeScore;
property AwayScore: Observable<Integer> read fAwayScore;

property Winner: IObservable<string> read fWinner;
property Winner: Observable<string> read fWinner;
end;

TTournamentViewModel = class(TComponent)
Expand Down Expand Up @@ -96,7 +96,7 @@ procedure TTournamentViewModel.SemiFinalTwo_SaveScore;
{ TMatch }

constructor TMatch.Create(const matchName: string;
const homeTeam: IObservable<string>; const awayTeam: IObservable<string>);
const homeTeam: Observable<string>; const awayTeam: Observable<string>);
begin
fHomeTeam := homeTeam;
fAwayTeam := awayTeam;
Expand Down

0 comments on commit 028eaa7

Please sign in to comment.