Skip to content

Instantly share code, notes, and snippets.

@Aidanvii7
Created July 9, 2019 17:03
Show Gist options
  • Save Aidanvii7/7c699f637a8ba0ed83599164ffe25c60 to your computer and use it in GitHub Desktop.
Save Aidanvii7/7c699f637a8ba0ed83599164ffe25c60 to your computer and use it in GitHub Desktop.
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