diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2021-05-08 18:37:07 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2021-05-08 18:37:07 +0200 |
commit | 00e52ec8ee38a85737c093d90ebfba5069829608 (patch) | |
tree | 967bffe7133fb3266ab99fc44827aeeba8ce5f7d /include/erebos/frp.h | |
parent | b02dfe41b255ac663c3ac3a4475a4933186de1e7 (diff) |
FRP: run callback when starting to watch behavior
Diffstat (limited to 'include/erebos/frp.h')
-rw-r--r-- | include/erebos/frp.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/include/erebos/frp.h b/include/erebos/frp.h index 8014536..681aee8 100644 --- a/include/erebos/frp.h +++ b/include/erebos/frp.h @@ -160,11 +160,18 @@ using Bhv = BhvFun<monostate, A>; template<typename A> Watched<A> Bhv<A>::watch(function<void(const A &)> f) { + BhvCurTime ctime; + auto & impl = BhvFun<monostate, A>::impl; + if (impl->needsUpdate(ctime)) + impl->doUpdate(ctime); + auto cb = make_shared<function<void(const BhvCurTime &)>>( [impl = BhvFun<monostate, A>::impl, f] (const BhvCurTime & ctime) { f(impl->get(ctime, monostate())); }); - BhvFun<monostate, A>::impl->watchers.push_back(cb); + + impl->watchers.push_back(cb); + f(impl->get(ctime, monostate())); return Watched<A>(move(cb)); } |