我正在使用颤振从少数设备交换 Firestore 数据。
如果我使用 StreamBuilder 一切正常,但我不喜欢将业务逻辑与 UI 混合。我更喜欢使用 BLOC 作为使用 flutter_bloc 插件的模式。
但是 flutter_bloc 是这样工作的:
脚步:
事件 ------------------------> 新数据但没有新的 UI 事件
异步请求
异步响应
状态(mapEventToState)-------> ¿我如何获得新状态?
至于我没有“UI 事件”,因为正在从另一台设备更新 Firestore 数据,我无法更新状态。
我可以在 bloc 构造函数上使用这样的东西:
Stream<QuerySnapshot> query;
QuedadaBloc(){
query = Firestore.instance.collection('my_collection').snapshots();
query.listen((datos){
dispatch(Fetch()); // send fictitious UI event
});
}
Run Code Online (Sandbox Code Playgroud)
但我认为这不是正确的方法。
¿任何建议?
非常感谢。
J. 巴勃罗。
我正在尝试使用Alloy更新Titanium中的集合中的模型.
此代码无效:
var contactos = Alloy.Collections.instance('Contact');
var contacto = contactos.get({id: 3});
// Output: {id:3, name:'Juan 3', marcado: 1}
Ti.API.debug('get: ' + JSON.stringify(contacto));
contacto.set({marcado: 0});
// Output: {id:3, name:'Juan 3', marcado: 0}
Ti.API.debug('set: ' + JSON.stringify(contacto));
contacto.save();
contactos.fetch();
// Output: [{id:3, name:'Juan 3', marcado: 1},{...},{...}]
Ti.API.debug('despues de save: ' + JSON.stringify( JSON.stringify( contactos ) ));
Run Code Online (Sandbox Code Playgroud)
虽然这是有效的:
var contactos = Alloy.Collections.instance('Contact');
var contacto1 = Alloy.createModel('Contact');
// Output: {id:null, name:'', marcado: 0}
Ti.API.debug('createModel: ' + JSON.stringify(contacto1));
var contacto2 = contactos.get({id: 3});
// Output: …Run Code Online (Sandbox Code Playgroud) 我的数据是这样的(每两个'-'一个字节):
+----+--+----+----+
|0840|0C|00AD|0840|
+----+--+----+----+
Run Code Online (Sandbox Code Playgroud)
如果我使用此代码:错误
Type TAlarmasRATP = record
Funcion : word;
Instancia : byte;
Err_0 : word;
Err_1 : word;
end;
Run Code Online (Sandbox Code Playgroud)
函数 = 4008,实例 = 0C,Err_0 = 08AD,Err_1 = 0040
如果我使用此代码:正确
Type TAlarmasRATP = record
Funcion : word;
Instancia : byte;
Err_0 : array [0..1] of byte;
Err_1 : array [0..1] of byte;
end;
Run Code Online (Sandbox Code Playgroud)
函数 = 4008,实例 = 0C,Err_0 = AD00,Err_1 = 4008
为什么第一个不起作用?