Skip to content

Commit 3fdbe97

Browse files
authored
ParseLiveList Performance improvement (#327)
* Created ParseLiveList * LiveList & LivListBuilder works * Cleanup * changed to animated list * Fix in dataloading * updated AnimatedList * Finished Animations & cleanup * handle reconnect * Added dispose methodes & renamed classes & cleanup * cleanup * Fix animation duration * added README ParseLiveList section * Initialized example_livelist * Update application_constants.dart * Update .gitignore * Revert "Update .gitignore" This reverts commit 4d8982d. * Update .gitignore * HotFix: object Update from client If the client changes the object. (ParseObject does not get copied) * Implemented simple example * Update README.md * Update main.dart * Update README.md * Update README.md * LiveList - Performance Improvement This is the change mentioned in #324 (comment) Requires #326 * LiveList - Performance Improvement This is the change mentioned in #324 (comment) Requires #326 * example_livelist: use clientKey * Changed example_livelist query In the README I wrote, you can use a field called "show" to hide elements.
1 parent 16f9e96 commit 3fdbe97

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const String keyApplicationName = '';
22
const String keyParseApplicationId = '';
3-
const String keyParseMasterKey = '';
3+
const String keyParseClientKey = '';
44
const String keyParseServerUrl = '';
55
const String keyParseLiveServerUrl = '';
66
const bool keyDebug = true;

example_livelist/lib/main.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class _MyAppState extends State<MyApp> {
2323
initFailed = !success;
2424
if (success)
2525
_queryBuilder = QueryBuilder<ParseObject>(ParseObject('Test'))
26-
..orderByAscending('order');
27-
;
26+
..orderByAscending('order')
27+
..whereNotEqualTo('show', false);
2828
});
2929
}).catchError((dynamic _) {
3030
setState(() {
@@ -179,6 +179,7 @@ class _ObjectFormState extends State<ObjectForm> {
179179
setState(() {
180180
_formKey.currentState.save();
181181
final ParseObject object = _currentObject;
182+
//Delay to highlight the animation.
182183
Future<void>.delayed(const Duration(seconds: 1))
183184
.then((_) {
184185
object.save();

lib/src/utils/parse_live_list.dart

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,27 +160,28 @@ class ParseLiveList<T extends ParseObject> {
160160
for (int i = 0; i < _list.length; i++) {
161161
if (after(object, _list[i].object) != true) {
162162
_list.insert(i, ParseLiveListElement<T>(object, loaded: loaded));
163-
_eventStreamController.sink.add(ParseLiveListAddEvent<T>(i, object));
163+
_eventStreamController.sink.add(ParseLiveListAddEvent<T>(
164+
i, object?.clone(object?.toJson(full: true))));
164165
return;
165166
}
166167
}
167168
_list.add(ParseLiveListElement<T>(object, loaded: loaded));
168-
_eventStreamController.sink
169-
.add(ParseLiveListAddEvent<T>(_list.length - 1, object));
169+
_eventStreamController.sink.add(ParseLiveListAddEvent<T>(
170+
_list.length - 1, object?.clone(object?.toJson(full: true))));
170171
}
171172

172173
void _objectUpdated(T object) {
173174
for (int i = 0; i < _list.length; i++) {
174175
if (_list[i].object.get<String>(keyVarObjectId) ==
175176
object.get<String>(keyVarObjectId)) {
176-
//TODO: better soulution
177-
// if (after(_list[i].object, object) == null) {
178-
// _list[i].object = object;
179-
// } else {
180-
_list.removeAt(i).dispose();
181-
_eventStreamController.sink.add(ParseLiveListDeleteEvent<T>(i, object));
182-
_objectAdded(object);
183-
// }
177+
if (after(_list[i].object, object) == null) {
178+
_list[i].object = object;
179+
} else {
180+
_list.removeAt(i).dispose();
181+
_eventStreamController.sink.add(ParseLiveListDeleteEvent<T>(
182+
i, object?.clone(object?.toJson(full: true))));
183+
_objectAdded(object);
184+
}
184185
break;
185186
}
186187
}
@@ -191,7 +192,8 @@ class ParseLiveList<T extends ParseObject> {
191192
if (_list[i].object.get<String>(keyVarObjectId) ==
192193
object.get<String>(keyVarObjectId)) {
193194
_list.removeAt(i).dispose();
194-
_eventStreamController.sink.add(ParseLiveListDeleteEvent<T>(i, object));
195+
_eventStreamController.sink.add(ParseLiveListDeleteEvent<T>(
196+
i, object?.clone(object?.toJson(full: true))));
195197
break;
196198
}
197199
}
@@ -256,12 +258,12 @@ class ParseLiveListElement<T extends ParseObject> {
256258

257259
Stream<T> get stream => _streamController?.stream;
258260

259-
T get object => _object;
261+
T get object => _object?.clone(_object?.toJson(full: true));
260262

261263
set object(T value) {
262264
_loaded = true;
263265
_object = value;
264-
_streamController?.add(object);
266+
_streamController?.add(_object?.clone(_object?.toJson(full: true)));
265267
}
266268

267269
bool get loaded => _loaded;

0 commit comments

Comments
 (0)