Skip to content

Commit

Permalink
fixed dependency tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
sglienke committed Jun 25, 2015
1 parent e60900f commit 1382f90
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 47 deletions.
63 changes: 51 additions & 12 deletions ObservableTests.pas
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,64 @@ TObservableTests = class(TTestCase)
procedure ObservableSetValueChangesValue;

procedure DependentObservableReturnsValue;
// procedure DependentObservableEvaluatesOnlyOnceAfterChange; // not yet implemented
procedure DependentObservableEvaluatesOnlyOnceAfterChange;
procedure DependentObservableUpdatesValueWhenDependencyChanges;

procedure DependentObservableClearsOldDependencies;
end;

implementation

type
KO = Observable;

{ TObservableTests }

//procedure TObservableTests.DependentObservableEvaluatesOnlyOnceAfterChange;
//var
// o: IObservable<string>;
// count: Integer;
//begin
// count := 0;
// o := TDependentObservable<string>.Create(function: string begin Inc(count); Result := 'test' end);
// CheckEquals('test', o.Value);
// CheckEquals('test', o.Value);
// CheckEquals(1, count);
//end;
procedure TObservableTests.DependentObservableClearsOldDependencies;
var
a: IObservable<Boolean>;
b, c: IObservable<string>;
o: IObservable<string>;
count: Integer;
begin
a := KO.Create(False);
b := KO.Create('true');
c := KO.Create('false');
o := KO.Computed<string>(
function: string
begin
Inc(count);
if a.Value then
Result := b.Value
else
Result := c.Value
end);
count := 0;
CheckEquals('false', o.Value);
CheckEquals(0, count);
b.Value := 'TRUE';
CheckEquals(0, count);
c.Value := 'FALSE';
CheckEquals('FALSE', o.Value);
CheckEquals(1, count);
a.Value := True;
CheckEquals('TRUE', o.Value);
CheckEquals(2, count);
c.Value := 'false';
CheckEquals(2, count);
end;

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

procedure TObservableTests.DependentObservableReturnsValue;
var
Expand Down
Loading

0 comments on commit 1382f90

Please sign in to comment.