Skip to content

Commit

Permalink
Merge pull request #82 from kevinresol/fix-mapasync
Browse files Browse the repository at this point in the history
Fix mapAsync
  • Loading branch information
back2dos authored Sep 14, 2023
2 parents 8902bbd + 1d44cc4 commit 1814a90
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tink/state/Observable.hx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ abstract Observable<T>(ObservableObject<T>) from ObservableObject<T> to Observab
return Observable.auto(() -> f(value, that.value));

public function mapAsync<R>(f:Transform<T, Promise<R>>):Observable<Promised<R>>
return Observable.auto(() -> f.apply(this.getValue()));
return Observable.auto(() -> f.apply(value));

@:deprecated('use auto instead')
public function switchSync<R>(cases:Array<{ when: T->Bool, then: Lazy<Observable<R>> } > , dfault:Lazy<Observable<R>>):Observable<R>
Expand Down
20 changes: 20 additions & 0 deletions tests/TestBasic.hx
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,24 @@ class TestBasic {

return asserts.done();
}

public function mapAsync() {
final s = new State(0);
final o:Observable<Int> = s;
final m = o.mapAsync(v -> Future.delay(0, v));
final fired = [];
m.bind(v -> fired.push(v));
haxe.Timer.delay(() -> {
s.set(1);
haxe.Timer.delay(() -> {
asserts.assert(Std.string(fired[0]) == 'Loading');
asserts.assert(Std.string(fired[1]) == 'Done(0)');
asserts.assert(Std.string(fired[2]) == 'Loading');
asserts.assert(Std.string(fired[3]) == 'Done(1)');
asserts.assert(fired.length == 4);
asserts.done();
}, 10);
}, 0);
return asserts;
}
}

0 comments on commit 1814a90

Please sign in to comment.