-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat(firestore): add support for VectorValue #16476
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3b6e835
feat(firestore): add support for VectorValue
Lyokone c629919
android
Lyokone d657ef9
fix iOS
Lyokone a23714b
android
Lyokone 2317c28
fix format
Lyokone 9713550
add to example app
Lyokone 43b61c2
android
Lyokone f0eb9e6
JS
Lyokone 18e4669
with correct JS version
Lyokone 55f3959
format
Lyokone ab406e1
more tests
Lyokone 296f3e0
fix tests
Lyokone cb4252d
change to test
Lyokone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
feat(firestore): add support for VectorValue
- Loading branch information
commit 3b6e835232bac62c8a2be51621dbbd2dae414225
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/cloud_firestore/cloud_firestore/example/integration_test/vector_value_e2e.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Copyright 2020, the Chromium project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'package:cloud_firestore/cloud_firestore.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| void runVectorValueTests() { | ||
| group('$VectorValue', () { | ||
| late FirebaseFirestore /*?*/ firestore; | ||
|
|
||
| setUpAll(() async { | ||
| firestore = FirebaseFirestore.instance; | ||
| }); | ||
|
|
||
| Future<DocumentReference<Map<String, dynamic>>> initializeTest( | ||
| String path, | ||
| ) async { | ||
| String prefixedPath = 'flutter-tests/$path'; | ||
| await firestore.doc(prefixedPath).delete(); | ||
| return firestore.doc(prefixedPath); | ||
| } | ||
|
|
||
| testWidgets('sets a $VectorValue & returns one', (_) async { | ||
|
russellwheatley marked this conversation as resolved.
Outdated
|
||
| DocumentReference<Map<String, dynamic>> doc = | ||
| await initializeTest('vector-value'); | ||
|
|
||
| await doc.set({ | ||
| 'foo': const VectorValue([10.0, -10.0]) | ||
| }); | ||
|
|
||
| DocumentSnapshot<Map<String, dynamic>> snapshot = await doc.get(); | ||
|
|
||
| VectorValue vectorValue = snapshot.data()!['foo']; | ||
| expect(vectorValue, isA<VectorValue>()); | ||
| expect(vectorValue.toArray(), equals([10.0, -10.0])); | ||
| }); | ||
|
|
||
| testWidgets('updates a $VectorValue & returns', (_) async { | ||
| DocumentReference<Map<String, dynamic>> doc = | ||
| await initializeTest('vector-value-update'); | ||
|
|
||
| await doc.set({ | ||
| 'foo': const VectorValue([10.0, -10.0]) | ||
| }); | ||
|
|
||
| await doc.update({ | ||
| 'foo': const VectorValue([-10.0, 10.0]) | ||
| }); | ||
|
|
||
| DocumentSnapshot<Map<String, dynamic>> snapshot = await doc.get(); | ||
|
|
||
| VectorValue vectorValue = snapshot.data()!['foo']; | ||
| expect(vectorValue, isA<VectorValue>()); | ||
| expect(vectorValue.toArray(), equals([-10.0, 10.0])); | ||
| }); | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/vector_value.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // ignore_for_file: require_trailing_commas | ||
| // Copyright 2017, the Chromium project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/foundation.dart'; | ||
|
|
||
| /// Represents a vector value by an array of doubles. | ||
| @immutable | ||
| class VectorValue { | ||
| /// Create [VectorValue] instance. | ||
| const VectorValue(this._value); | ||
|
|
||
| final List<double> _value; // ignore: public_member_api_docs | ||
|
|
||
| @override | ||
| bool operator ==(Object other) => | ||
| other is VectorValue && listEquals(other._value, _value); | ||
|
|
||
| @override | ||
| int get hashCode => _value.hashCode; | ||
|
|
||
| @override | ||
| String toString() => 'VectorValue(value: $_value)'; | ||
|
|
||
| /// Converts a [VectorValue] to a [List] of [double]. | ||
| List<double> toArray() => _value; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.