From b92a6d0b5b7529ced0e9d4e9882c89e759cc812d Mon Sep 17 00:00:00 2001 From: Gene Pavlovsky Date: Mon, 26 Feb 2024 09:16:12 +0100 Subject: [PATCH] Make nextTime's condition optional --- package-lock.json | 26 ++++++++++++++++++++++++++ src/tink/state/Observable.hx | 9 ++++++--- tests.hxml | 3 ++- tests/TestBasic.hx | 9 +++++++-- 4 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..3c607f9 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,26 @@ +{ + "name": "@haxelib/tink_state", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@haxelib/tink_state", + "hasInstallScript": true, + "dependencies": { + "lix": "^15.10.1" + } + }, + "node_modules/lix": { + "version": "15.12.1", + "resolved": "https://registry.npmjs.org/lix/-/lix-15.12.1.tgz", + "integrity": "sha512-8cYNMYttFY6Pl18jGspIQBvhUP7ScjBOaoV025K1oWrRMhNNBep2NsEimBQq0u/Bcq2q3K58LWH1nr50aej6DA==", + "hasInstallScript": true, + "bin": { + "haxe": "bin/haxeshim.js", + "haxelib": "bin/haxelibshim.js", + "lix": "bin/lix.js", + "neko": "bin/nekoshim.js" + } + } + } +} diff --git a/src/tink/state/Observable.hx b/src/tink/state/Observable.hx index 732632d..090aa9d 100644 --- a/src/tink/state/Observable.hx +++ b/src/tink/state/Observable.hx @@ -77,8 +77,11 @@ abstract Observable(ObservableObject) from ObservableObject to Observab public function combine(that:Observable, f:T->A->R):Observable return Observable.auto(() -> f(value, that.value)); - public function nextTime(?options:{ ?butNotNow: Bool, ?hires:Bool }, check:T->Bool):Future - return getNext(options, v -> if (check(v)) Some(v) else None); + public function nextTime(?options:{ ?butNotNow: Bool, ?hires:Bool }, ?condition:T->Bool):Future + return getNext(options, + if (condition == null) Some + else v -> if (condition(v)) Some(v) else None + ); public function getNext(?options:{ ?butNotNow: Bool, ?hires:Bool }, select:T->Option):Future { var ret = Future.trigger(), @@ -360,4 +363,4 @@ class ObservableTools { static public function flatten(o:Observable>) return Observable.auto(() -> Observable.lift(o).value.value); -} \ No newline at end of file +} diff --git a/tests.hxml b/tests.hxml index 705f647..26f6852 100644 --- a/tests.hxml +++ b/tests.hxml @@ -1,6 +1,7 @@ +-cp src -cp tests -D no-deprecation-warnings -lib tink_unittest -main RunTests --lib deep_equal \ No newline at end of file +-lib deep_equal diff --git a/tests/TestBasic.hx b/tests/TestBasic.hx index 2b4ee10..8f23719 100644 --- a/tests/TestBasic.hx +++ b/tests/TestBasic.hx @@ -1,7 +1,7 @@ package; -import tink.state.Scheduler.direct; import tink.state.*; +import tink.state.Scheduler.direct; using tink.CoreApi; @@ -126,6 +126,11 @@ class TestBasic { asserts.assert(fired == 4); + await(o.nextTime({ hires: true, })); + set(0); + + asserts.assert(fired == 5); + return asserts.done(); } @@ -152,7 +157,7 @@ class TestBasic { return asserts.done(); } - + public function mapAsync() { final s = new State(0); final o:Observable = s;