Skip to content

Commit

Permalink
Add a simple trigger() and triggerAll() to the ListenerSet.
Browse files Browse the repository at this point in the history
  • Loading branch information
christofmuc committed Jan 15, 2023
1 parent 264a3c0 commit 620eedb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions LambdaValueListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class LambdaValueListener : private juce::Value::Listener {
value_.addListener(this);
}

void trigger() { listener_(value_); }

private:
virtual void valueChanged(juce::Value& value) override
{
Expand All @@ -51,6 +53,12 @@ class ListenerSet {
void addListener(juce::Value const& value, std::function<void(juce::Value& newValue)> listener) { listeners_.emplace_back(std::make_unique<LambdaValueListener>(value, listener)); }

void clear() { listeners_.clear(); }
void triggerAll()
{
for (auto& l : listeners_) {
l->trigger();
}
}

private:
std::vector<std::unique_ptr<LambdaValueListener>> listeners_;
Expand Down

0 comments on commit 620eedb

Please sign in to comment.