Format, add pubspec for community package

This commit is contained in:
Simon Binder 2019-02-20 17:20:26 +01:00
parent d93421840f
commit bcf1926033
6 changed files with 40 additions and 19 deletions

13
pubspec.yaml Normal file
View File

@ -0,0 +1,13 @@
# This pubspec file exists so that this repository can show up in the generated list of community
# repositories. It's not meant to serve as an actual pub file.
name: sally
description: Sally is a safe and reactive persistence library for Dart applications
homepage: https://github.com/simolus3/sally
authors:
- Flutter Community <community@flutter.zone>
- Simon Binder <simolus3@gmail.com>
maintainer: Simon Binder (@simolus3)
environment:
sdk: '>=2.0.0 <3.0.0'

View File

@ -6,21 +6,23 @@ library diff_util;
import 'package:sally/src/utils/android_diffutils_port.dart' as impl;
class EditAction {
/// The index of the first list on which this action should be applied. If
/// this action [isDelete], that index and the next [amount] indices should be
/// deleted. Otherwise, this index should be moved back by [amount] and
/// entries from the second list (starting at [indexFromOther]) should be
/// inserted into the gap.
final int index;
/// The amount of entries affected by this action
final int amount;
/// If this action [isInsert], this is the first index from the second list
/// from where the items should be taken from.
final int indexFromOther;
/// Whether this action should delete entries from the first list
bool get isDelete => indexFromOther == null;
/// Whether this action should insert entries into the first list
bool get isInsert => indexFromOther != null;
@ -30,14 +32,13 @@ class EditAction {
String toString() {
if (isDelete) {
return 'EditAction: Delete $amount entries from the first list, starting '
'at index $index';
'at index $index';
} else {
return 'EditAction: Insert $amount entries into the first list, taking '
'them from the second list starting at $indexFromOther. The entries '
'should be written starting at index $index';
'should be written starting at index $index';
}
}
}
/// Finds the shortest edit script that turns list [a] into list [b].

View File

@ -76,14 +76,16 @@ abstract class GeneratedDatabase {
/// Starts an [InsertStatement] for a given table. You can use that statement
/// to write data into the [table] by using [InsertStatement.insert].
@protected @visibleForTesting
@protected
@visibleForTesting
InsertStatement<T> into<T>(TableInfo<dynamic, T> table) =>
InsertStatement<T>(this, table);
/// Starts an [UpdateStatement] for the given table. You can use that
/// statement to update individual rows in that table by setting a where
/// clause on that table and then use [UpdateStatement.write].
@protected @visibleForTesting
@protected
@visibleForTesting
UpdateStatement<Tbl, ReturnType> update<Tbl, ReturnType>(
TableInfo<Tbl, ReturnType> table) =>
UpdateStatement(this, table);
@ -91,14 +93,16 @@ abstract class GeneratedDatabase {
/// Starts a query on the given table. Queries can be limited with an limit
/// or a where clause and can either return a current snapshot or a continuous
/// stream of data
@protected @visibleForTesting
@protected
@visibleForTesting
SelectStatement<Table, ReturnType> select<Table, ReturnType>(
TableInfo<Table, ReturnType> table) {
return SelectStatement<Table, ReturnType>(this, table);
}
/// Starts a [DeleteStatement] that can be used to delete rows from a table.
@protected @visibleForTesting
@protected
@visibleForTesting
DeleteStatement<Table> delete<Table>(TableInfo<Table, dynamic> table) =>
DeleteStatement<Table>(this, table);
}

View File

@ -122,12 +122,14 @@ List<Snake> calculateDiff(DiffInput input) {
final first = snakes.isEmpty ? null : snakes.first;
if (first == null || first.x != 0 || first.y != 0) {
snakes.insert(0, Snake()
..x = 0
..y = 0
..removal = false
..size = 0
..reverse = false);
snakes.insert(
0,
Snake()
..x = 0
..y = 0
..removal = false
..size = 0
..reverse = false);
}
return snakes;
@ -239,5 +241,5 @@ Snake _diffPartial(DiffInput input, int startOld, int endOld, int startNew,
}
throw StateError("Unexpected case: Please make sure the lists don't change "
'during a diff');
'during a diff');
}

View File

@ -9,7 +9,8 @@ List<T> applyEditScript<T>(List<T> a, List<T> b, List<EditAction> actions) {
final deleteStartIndex = action.index;
copy.removeRange(deleteStartIndex, deleteStartIndex + action.amount);
} else {
final toAdd = b.getRange(action.indexFromOther, action.indexFromOther + action.amount);
final toAdd = b.getRange(
action.indexFromOther, action.indexFromOther + action.amount);
copy.insertAll(action.index, toAdd);
}
}
@ -18,10 +19,10 @@ List<T> applyEditScript<T>(List<T> a, List<T> b, List<EditAction> actions) {
}
void main() {
final a = ['a', 'b', 'c', 'a', 'b', 'b', 'a'];
final a = ['a', 'b', 'c', 'a', 'b', 'b', 'a'];
final b = ['c', 'b', 'a', 'b', 'a', 'c'];
test('diff matcher should produce a correct edit script', () {
expect(applyEditScript(a, b, diff(a, b)), b);
});
}
}

View File

@ -260,4 +260,4 @@ Implementing this will very likely result in backwards-incompatible changes.
accessible for the generated code
- `GROUP BY` grouping functions
- Support for different database engines
- Support webapps via `AlaSQL` or a different engine
- Support webapps via `AlaSQL` or a different engine