Added teardown styled use effect

This commit is contained in:
2023-03-01 06:41:14 -08:00
parent 008cf282dd
commit dfcc14f2a7
3 changed files with 51 additions and 3 deletions

View File

@ -10,6 +10,8 @@ namespace Dawn {
class IStateProperty {
public:
std::vector<std::function<void()>> _effectListners;
std::vector<std::function<std::function<void()>()>> _effectListnersWithTeardown;
std::vector<std::function<void()>> _effectTeardowns;
};
template<class V>
@ -26,12 +28,28 @@ namespace Dawn {
this->previous = this->_realValue;
this->_realValue = val;
// Run the teardowns
auto itTeardown = this->_effectTeardowns.begin();
while(itTeardown != this->_effectTeardowns.end()) {
(*itTeardown)();
++itTeardown;
}
this->_effectTeardowns.clear();
// Notify the effect listeners
auto itEffect = this->_effectListners.begin();
while(itEffect != this->_effectListners.end()) {
(*itEffect)();
++itEffect;
}
// Notify the teardown effect listeners
auto itWithTeardown = this->_effectListnersWithTeardown.begin();
while(itWithTeardown != this->_effectListnersWithTeardown.end()) {
auto teardown = (*itWithTeardown)();
this->_effectTeardowns.push_back(teardown);
++itWithTeardown;
}
}
public: