-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat offline support refactor #135
base: feat-offline-support
Are you sure you want to change the base?
Conversation
Split out offline DB related operations into separate classes.
@lohanidamodar, I tried to move a lot of logic out of ClientOfflineMixin. What do you think? |
if (params.containsKey('queries')) { | ||
final queries = params['queries'] as List<dynamic>; | ||
queries.forEach((query) { | ||
final q = Query.parse(query as String); | ||
|
||
switch (q.method) { | ||
case 'equal': | ||
final value = q.params[1]; | ||
if (value is List) { | ||
value.forEach((v) { | ||
final List<Filter> equalFilters = []; | ||
value.forEach((v) { | ||
equalFilters.add(Filter.equals(q.params[0], v)); | ||
}); | ||
filters.add(Filter.or(equalFilters)); | ||
}); | ||
} else { | ||
filters.add(Filter.equals(q.params[0], q.params[1])); | ||
} | ||
break; | ||
|
||
case 'notEqual': | ||
filters.add(Filter.notEquals(q.params[0], q.params[1])); | ||
break; | ||
|
||
case 'lessThan': | ||
filters.add(Filter.lessThan(q.params[0], q.params[1])); | ||
break; | ||
|
||
case 'lessThanEqual': | ||
filters.add(Filter.lessThanOrEquals(q.params[0], q.params[1])); | ||
break; | ||
|
||
case 'greaterThan': | ||
filters.add(Filter.greaterThan(q.params[0], q.params[1])); | ||
break; | ||
|
||
case 'greaterThanEqual': | ||
filters.add(Filter.greaterThanOrEquals(q.params[0], q.params[1])); | ||
break; | ||
|
||
case 'search': | ||
filters.add(Filter.matches(q.params[0], r'${q.params[1]} ')); | ||
break; | ||
|
||
case 'orderAsc': | ||
sortOrders.add(SortOrder(q.params[0] as String)); | ||
break; | ||
|
||
case 'orderDesc': | ||
sortOrders.add(SortOrder(q.params[0] as String, false)); | ||
break; | ||
|
||
case 'cursorBefore': | ||
// TODO: Handle this case. | ||
break; | ||
|
||
case 'cursorAfter': | ||
// TODO: Handle this case. | ||
break; | ||
|
||
case 'limit': | ||
finder.limit = q.params[0] as int; | ||
break; | ||
case 'offset': | ||
finder.offset = q.params[0] as int; | ||
break; | ||
} | ||
}); | ||
|
||
if (filters.isNotEmpty) { | ||
filter = Filter.and(filters); | ||
finder.filter = filter; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abnegate, here's an attempt at client-side filters of offline data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. However I still suggest refactoring it in a middleware approach for final release. LMK WYT.
String method; | ||
List<dynamic> params; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String method; | |
List<dynamic> params; | |
final String method; | |
final List<dynamic> params; |
I think these can be final
What does this PR do?
Refactor ClientOfflineMixin and add offline filters
Test Plan
Manual
Related PRs and Issues
(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)
Have you read the Contributing Guidelines on issues?
Yes