onSuccess method
Implementation
Future<bool> onSuccess(Data data, {int? code, String? message, Observable? onSuccessOverride}) async
{
// set busy
busy = true;
// max records
int maxrecords = this.maxrecords ?? 10000;
if (maxrecords < 0) maxrecords = 0;
// apply data transforms
if (children != null)
for (WidgetModel model in this.children!)
if (model is ITransform) await (model as ITransform).apply(data);
// type - default is replace
ListTypes? type = S.toEnum(this.queuetype, ListTypes.values);
// Fifo - Oldest -> Newest
if (type == ListTypes.fifo) {
Data temp = Data();
if (this.data != null) this.data!.forEach((element) => temp.add(element));
data.forEach((element) => temp.add(element));
if (temp.length > maxrecords)
temp.removeRange(0, temp.length - maxrecords);
data = temp;
}
// Lifo - Newest > Oldest
if (type == ListTypes.lifo) {
Data temp = Data();
data.forEach((element) => temp.add(element));
if (this.data != null) this.data!.forEach((element) => temp.add(element));
if (temp.length > maxrecords)
temp.removeRange(temp.length - maxrecords - 1, temp.length);
data = temp;
}
// Append
if (type == ListTypes.append) {
Data temp = Data();
if (this.data != null) this.data!.forEach((element) => temp.add(element));
data.forEach((element) => temp.add(element));
data = temp;
}
// Prepend
if (type == ListTypes.prepend) {
Data temp = Data();
data.forEach((element) => temp.add(element));
if (this.data != null) this.data!.forEach((element) => temp.add(element));
data = temp;
}
// Truncate List
if (data.length > maxrecords) data.removeRange(maxrecords, data.length);
// Return Success
return await onData(data, code: code, message: message, onSuccessOverride: onSuccessOverride);
}