Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple wrapper class for consuming one time events from a MobX store
class Transient<T> {
T _value;
Transient(T value) {
this._value = value;
}
void use(Function(T value) block) {
assert(block != null);
if (_value != null) {
block(_value);
_value = null;
}
}
}
class Event {
Object _flag = Object();
void consume(Function block) {
assert(block != null);
if (_flag != null) {
block();
_flag = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment