Created
July 9, 2019 17:03
-
-
Save Aidanvii7/7c699f637a8ba0ed83599164ffe25c60 to your computer and use it in GitHub Desktop.
Simple wrapper class for consuming one time events from a MobX store
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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