Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. # parse subscribe <code dart> itemSubscribe() async { /// 1. 등록, 2. 수정, 3. 삭제 itemDao.subscribe(pantry?.objectId, (LiveQueryEvent type, Item item) { switch (type) { case LiveQueryEvent.create: case LiveQueryEvent.enter: itemList.add(item); break; case LiveQueryEvent.update: var idx = itemList.indexWhere((e) => e.objectId == item.objectId); itemList[idx] = item; break; case LiveQueryEvent.leave: case LiveQueryEvent.delete: itemList = itemList.where((e) => e.objectId != item.objectId).toList(); break; default: } itemClassify(); }); } </code> <code> subscribe( String? pantryId, Function(LiveQueryEvent, Item) callback, ) async { if (_liveQuery == null) _liveQuery = LiveQuery(); unsubscribe(); var query = QueryBuilder<Item>(Item()) ..whereEqualTo(Item.keyPantryId, pantryId); _subscription = await _liveQuery?.client.subscribe(query); subscribeOn(_subscription, callback); } </code> <code> subscribeOn(Subscription? subscription, Function callback) { if (subscription == null) return; subscription.on(LiveQueryEvent.create, (value) { print('*** CREATE ***: ${DateTime.now().toString()}\n $value '); callback(LiveQueryEvent.create, value); }); subscription.on(LiveQueryEvent.enter, (value) { print('*** ENTER ***: ${DateTime.now().toString()}\n $value '); callback(LiveQueryEvent.enter, value); }); subscription.on(LiveQueryEvent.update, (value) { print('*** UPDATE ***: ${DateTime.now().toString()}\n $value '); callback(LiveQueryEvent.update, value); }); subscription.on(LiveQueryEvent.leave, (value) { print('*** LEAVE ***: ${DateTime.now().toString()}\n $value '); callback(LiveQueryEvent.leave, value); }); subscription.on(LiveQueryEvent.delete, (value) { print('*** DELETE ***: ${DateTime.now().toString()}\n $value '); callback(LiveQueryEvent.delete, value); }); } </code> open/parse-subscribe.txt Last modified: 2024/10/05 06:15by 127.0.0.1