获取有史以来经过的所有价值
假设我们要创建一个流的流,该流将包含映射< String,String>。现在,这里的收获是我想创建一个函数,该函数将在此MAP< String,String>中添加新的键值对。
例如,
final _configMap = BehaviorSubject<Map<String, dynamic>>();
Stream<Map<String, dynamic>> get configMap => _configMap.stream;
Function(Map<String, dynamic>) get addConfigMap => _configMap.sink.add;
现在调用接收器AddConfigmap只能接受新的地图。 但我的要求是创建一个行为主体,该行为会接受键值对,并且其流将散发出包含我们传递给它的所有键值对的地图。是否有可能?如果是,那怎么办?
Let's say that we want to create a stream which would contain a Map<String, String>. Now the catch here is that I want to create a function that would add new key-value pairs into this stream of Map<String, String>.
e.g.,
final _configMap = BehaviorSubject<Map<String, dynamic>>();
Stream<Map<String, dynamic>> get configMap => _configMap.stream;
Function(Map<String, dynamic>) get addConfigMap => _configMap.sink.add;
Now calling the sink addConfigMap will only accept a new map. But my requirement here is to create a BehaviorSubject that would accept Key-Value pairs and whose stream will emit a Map containing all those key-value pairs that we have ever passed into it. Is it possible ? If yes, then how ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将“累加器”映射存储在类上,然后在流的输入元素上映射,将新元素插入存储的
map
,然后最终发射存储的map
:使用:
You can store the "accumulator" map on the class, then map over the input elements of your stream, inserting the new elements into the stored
Map
, and finally emitting the storedMap
:To use: