Skip to content

Commit bcddecc

Browse files
authored
Merge pull request #145 from objectbox/async-and-isolates
Async callbacks & multi-isolate store access
2 parents 7babaca + 035441a commit bcddecc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1745
-419
lines changed

.github/workflows/dart.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ jobs:
2626
- macos-10.15
2727
- ubuntu-20.04
2828
dart:
29-
- 2.10.5
30-
# - 2.9.3 - generator stuck. I remember there was an issue in some dependency but don't remember which one.
31-
- 2.8.4
32-
- 2.7.2
29+
- latest
30+
- 2.10.0 # currently the lowest fully supported version (i.e. generator + lib)
3331
runs-on: ${{ matrix.os }}
3432
steps:
3533
# Note: dart-sdk from flutter doesn't work on linux, see https://github.com/flutter/flutter/issues/74599

benchmark/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: objectbox_benchmark
22
description: Simple ObjectBox-Dart performance benchmark
33

44
environment:
5-
sdk: ">=2.6.0 <3.0.0"
5+
sdk: ">=2.10.0 <3.0.0"
66

77
dependencies:
88
objectbox: any

flutter_libs/android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ android {
1212

1313
dependencies {
1414
// https://bintray.com/objectbox/objectbox/io.objectbox%3Aobjectbox-android
15-
implementation "io.objectbox:objectbox-android:2.8.0"
15+
implementation "io.objectbox:objectbox-android:2.9.0"
1616
}

flutter_libs/ios/download-framework.sh

+7-5
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ set -euo pipefail
44
# NOTE: run this script before publishing
55

66
# https://github.com/objectbox/objectbox-swift/releases/
7-
obxSwiftVersion="1.4.1"
7+
obxSwiftVersion="1.5.0-beta1"
88

99
dir=$(dirname "$0")
1010

11-
url="https://github.com/objectbox/objectbox-swift/releases/download/v${obxSwiftVersion}/ObjectBox-framework-${obxSwiftVersion}.zip"
11+
url="https://github.com/objectbox/objectbox-swift-spec-staging/releases/download/v1.x/ObjectBox-xcframework-${obxSwiftVersion}.zip"
1212
zip="${dir}/fw.zip"
1313

1414
curl --location --fail --output "${zip}" "${url}"
1515

16+
frameworkPath=Carthage/Build/ObjectBox.xcframework/ios-arm64/ObjectBox.framework
17+
1618
rm -rf "${dir}/Carthage"
1719
unzip "${zip}" -d "${dir}" \
18-
"Carthage/Build/iOS/ObjectBox.framework/Headers/*" \
19-
"Carthage/Build/iOS/ObjectBox.framework/ObjectBox" \
20-
"Carthage/Build/iOS/ObjectBox.framework/Info.plist"
20+
"${frameworkPath}/Headers/*" \
21+
"${frameworkPath}/ObjectBox" \
22+
"${frameworkPath}/Info.plist"
2123

2224
rm "${zip}"

flutter_libs/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ homepage: https://objectbox.io
55
description: ObjectBox is a super-fast NoSQL ACID compliant object database. This package contains flutter runtime libraries for ObjectBox.
66

77
environment:
8-
sdk: ">=2.6.0 <3.0.0"
9-
flutter: ">=1.12.0 <2.0.0"
8+
sdk: ">=2.9.0 <3.0.0"
9+
flutter: ">=1.20.0 <2.0.0"
1010

1111
dependencies:
1212
# This is here just to ensure compatibility between objectbox-dart code and the libraries used

generator/integration-tests/shared-pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: objectbox_generator_test
22

33
environment:
4-
sdk: ">=2.5.0 <3.0.0"
4+
sdk: ">=2.10.0 <3.0.0"
55

66
dependencies:
77
objectbox: any

generator/pubspec.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ homepage: https://objectbox.io
55
description: ObjectBox binding code generator - finds annotated entities and adds them to the ObjectBox DB model.
66

77
environment:
8-
sdk: ">=2.5.0 <3.0.0"
8+
# min SDK v2.10.0 (or Flutter v1.22) - there were breaking changes in the analyzer/resolver
9+
sdk: ">=2.10.0 <3.0.0"
910

1011
dependencies:
1112
objectbox: 0.11.0

install.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -eu
88
# * update lib/src/bindings/objectbox.h
99
# * execute pub run ffigen
1010
# * have a look at the changed files to see if some call sites need to be updated
11-
cLibVersion=0.11.0
11+
cLibVersion=0.12.0
1212
os=$(uname)
1313

1414
# if there's no tty this is probably part of a docker build - therefore we install the c-api explicitly

objectbox/CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## latest
2+
3+
* Add `Store.reference` getter and `Store.fromReference()` factory - enabling access to store from multiple isolates.
4+
* Add `Store.subscribe<EntityType>()` and `Store.subscribe<EntityType>()` data change event streams.
5+
* Add multiple `SyncClient` event streams.
6+
* Update to objectbox-c v0.12.0
7+
* Update to objectbox-android v2.9.0
8+
* Update to objectbox-swift v1.5.0
9+
* Increase minimum SDK versions: Flutter v1.20 & Dart v2.9. Code generator already required Flutter v1.22 & Dart v2.10.
10+
111
## 0.11.0 (2021-02-01)
212

313
* Add `ToOne<>` class to wrap related entities. See examples for details.

objectbox/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test: ## Test all targets
2020

2121
valgrind-test: ## Test all targets with valgrind
2222
pub run build_runner build
23-
../tool/valgrind.sh
23+
tool/valgrind.sh
2424

2525
integration-test: ## Execute integration tests
2626
cd example/flutter/objectbox_demo/ ; \

objectbox/example/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ omits the argument to `Store(directory: )`, thus using the default - 'objectbox'
9696
import 'objectbox.g.dart'; // created by `dart pub run build_runner build`
9797
9898
void main() {
99-
var store = Store(getObjectBoxModel()); // Note: getObjectBoxModel() is generated for you in objectbox.g.dart
99+
final store = Store(getObjectBoxModel()); // Note: getObjectBoxModel() is generated for you in objectbox.g.dart
100100
101101
// your app code ...
102102

objectbox/example/flutter/objectbox_demo/pubspec.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ description: An example project for the objectbox-dart binding.
33
version: 0.3.0+1
44

55
environment:
6-
sdk: ">=2.1.0 <3.0.0"
6+
sdk: ">=2.10.0 <3.0.0"
7+
flutter: ">=1.22.0 <2.0.0"
78

89
dependencies:
910
flutter:

objectbox/example/flutter/objectbox_demo_sync/lib/main.dart

+18-9
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class MyApp extends StatelessWidget {
3434
@override
3535
Widget build(BuildContext context) {
3636
return MaterialApp(
37-
title: 'OB Example',
37+
title: 'OB Example (sync)',
3838
theme: ThemeData(primarySwatch: Colors.blue),
39-
home: MyHomePage(title: 'OB Example'),
39+
home: MyHomePage(title: 'OB Example (sync)'),
4040
);
4141
}
4242
}
@@ -64,23 +64,20 @@ class ViewModel {
6464
_query = _box.query().order(dateProp, flags: Order.descending).build();
6565

6666
// TODO configure actual sync server address and authentication
67+
// For configuration and docs, see objectbox/lib/src/sync.dart
6768
// 10.0.2.2 is your host PC if an app is run in an Android emulator.
6869
// 127.0.0.1 is your host PC if an app is run in an iOS simulator.
69-
// For other options, see objectbox/lib/src/sync.dart
70+
final syncServerIp = Platform.isAndroid ? '10.0.2.2' : '127.0.0.1';
7071
final syncClient =
71-
Sync.client(_store, 'ws://10.0.2.2:9999', SyncCredentials.none());
72+
Sync.client(_store, 'ws://$syncServerIp:9999', SyncCredentials.none());
7273
syncClient.start();
7374
}
7475

7576
void addNote(Note note) => _box.put(note);
7677

7778
void removeNote(Note note) => _box.remove(note.id);
7879

79-
// Note: using query.findStream() and sync.client() in the same app is
80-
// currently not supported so this app is currently not working and only
81-
// servers as an example on how and when to start a sync client.
82-
// Stream<List<Note>> get queryStream => _query.findStream();
83-
Stream<List<Note>> get queryStream => Stream<List<Note>>.empty();
80+
Stream<List<Note>> get queryStream => _query.findStream();
8481

8582
List<Note> get allNotes => _query.find();
8683

@@ -144,6 +141,8 @@ class _MyHomePageState extends State<MyHomePage> {
144141
style: TextStyle(
145142
fontSize: 15.0,
146143
),
144+
// Provide a Key for the integration test
145+
key: Key('list_item_${index}'),
147146
),
148147
Padding(
149148
padding: EdgeInsets.only(top: 5.0),
@@ -188,6 +187,8 @@ class _MyHomePageState extends State<MyHomePage> {
188187
InputDecoration(hintText: 'Enter a new note'),
189188
controller: _noteInputController,
190189
onSubmitted: (value) => _addNote(),
190+
// Provide a Key for the integration test
191+
key: Key('input'),
191192
),
192193
),
193194
Padding(
@@ -220,6 +221,14 @@ class _MyHomePageState extends State<MyHomePage> {
220221
itemBuilder: _itemBuilder(snapshot.data));
221222
}))
222223
]),
224+
// We need a separate submit button because flutter_driver integration
225+
// test doesn't support submitting a TextField using "enter" key.
226+
// See https://github.com/flutter/flutter/issues/9383
227+
floatingActionButton: FloatingActionButton(
228+
key: Key('submit'),
229+
onPressed: _addNote,
230+
child: Icon(Icons.add),
231+
),
223232
);
224233
}
225234
}

objectbox/example/flutter/objectbox_demo_sync/lib/objectbox-model.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"name": "date",
3131
"type": 6
3232
}
33-
]
33+
],
34+
"relations": []
3435
}
3536
],
3637
"lastEntityId": "1:2802681814019499133",

objectbox/example/flutter/objectbox_demo_sync/pubspec.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ description: An example project for the objectbox-dart binding.
33
version: 0.3.0+1
44

55
environment:
6-
sdk: ">=2.1.0 <3.0.0"
6+
sdk: ">=2.10.0 <3.0.0"
7+
flutter: ">=1.22.0 <2.0.0"
78

89
dependencies:
910
flutter:

objectbox/lib/objectbox.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,13 @@ export 'src/relations/to_many.dart' show ToMany;
2323
export 'src/relations/to_one.dart' show ToOne;
2424
export 'src/store.dart' show Store;
2525
export 'src/sync.dart'
26-
show Sync, SyncClient, SyncCredentials, SyncRequestUpdatesMode, SyncState;
26+
show
27+
Sync,
28+
SyncChange,
29+
SyncClient,
30+
SyncConnectionEvent,
31+
SyncCredentials,
32+
SyncRequestUpdatesMode,
33+
SyncState,
34+
SyncLoginEvent;
2735
export 'src/transaction.dart' show TxMode;

objectbox/lib/src/bindings/bindings.dart

+33
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'dart:ffi';
22
import 'dart:io' show Platform;
33

4+
import '../common.dart';
5+
import 'helpers.dart';
46
import 'objectbox-c.dart';
57

68
// let files importing bindings.dart also get all the OBX_* types
@@ -46,3 +48,34 @@ ObjectBoxC loadObjectBoxLib() {
4648
ObjectBoxC /*?*/ _cachedBindings;
4749

4850
ObjectBoxC get C => _cachedBindings ??= loadObjectBoxLib();
51+
52+
/// Init DartAPI in C for async callbacks.
53+
///
54+
/// Call each time you're assign a native listener - will throw if the Dart
55+
/// native API isn't available.
56+
/// See https://github.com/objectbox/objectbox-dart/issues/143
57+
void initializeDartAPI() {
58+
if (_dartAPIinitialized == null) {
59+
final errCode = C.dartc_init_api(NativeApi.initializeApiDLData);
60+
_dartAPIinitialized = (OBX_SUCCESS == errCode);
61+
if (!_dartAPIinitialized) {
62+
_dartAPIinitException = latestNativeError(
63+
codeIfMissing: errCode,
64+
dartMsg: "Dart/Flutter SDK you're using is not compatible with "
65+
'ObjectBox observers, query streams and Sync event streams. '
66+
'Please consider using Flutter v1.20.x or v1.22.x (or Dart v2.10.x). '
67+
'See https://github.com/objectbox/objectbox-dart/issues/197 for more details. '
68+
'Native exception');
69+
}
70+
}
71+
72+
if (_dartAPIinitException != null) {
73+
throw _dartAPIinitException;
74+
}
75+
}
76+
77+
// null => not initialized
78+
// true => initialized successfully
79+
// false => failed to initialize - incompatible Dart version
80+
bool /*?*/ _dartAPIinitialized;
81+
ObjectBoxException /*?*/ _dartAPIinitException;

0 commit comments

Comments
 (0)