Skip to content

Commit

Permalink
fix(analyze): Fix the analizer issues
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmannZ committed Apr 21, 2019
1 parent 52bcd2c commit a3df378
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 47 deletions.
4 changes: 1 addition & 3 deletions example/lib/graphql_bloc/bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import 'package:graphql_flutter/graphql_flutter.dart';
import '../graphql_operation/mutations/mutations.dart' as mutations;
import '../graphql_operation/queries/readRepositories.dart' as queries;

/// Create a ../local.dart file with YOUR_PERSONAL_ACCESS_TOKEN = '<YOUR_PERSONAL_ACCESS_TOKEN>'
/// to make the example work
import '../local.dart' show YOUR_PERSONAL_ACCESS_TOKEN;
const String YOUR_PERSONAL_ACCESS_TOKEN = '<YOUR_PERSONAL_ACCESS_TOKEN>';

class Repo {
const Repo({this.id, this.name, this.viewerHasStarred});
Expand Down
8 changes: 3 additions & 5 deletions example/lib/graphql_widget/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import 'package:graphql_flutter/graphql_flutter.dart';
import '../graphql_operation/mutations/mutations.dart' as mutations;
import '../graphql_operation/queries/readRepositories.dart' as queries;

/// Create a ../local.dart file with YOUR_PERSONAL_ACCESS_TOKEN = '<YOUR_PERSONAL_ACCESS_TOKEN>'
/// to make the example work
import '../local.dart' show YOUR_PERSONAL_ACCESS_TOKEN;
const String YOUR_PERSONAL_ACCESS_TOKEN = '<YOUR_PERSONAL_ACCESS_TOKEN>';

final bool ENABLE_WEBSOCKETS = false;
const bool ENABLE_WEBSOCKETS = false;

class GraphQLWidgetScreen extends StatelessWidget {
const GraphQLWidgetScreen() : super();
Expand Down Expand Up @@ -186,7 +184,7 @@ class StarrableRepository extends StatelessWidget {
document: starred ? mutations.removeStar : mutations.addStar,
),
builder: (RunMutation toggleStar, QueryResult result) {
print([result.loading, optimistic]);
print(<bool>[result.loading, optimistic]);
return ListTile(
leading: starred
? const Icon(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/cache/in_memory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class InMemoryCache implements Cache {
}
try {
final File file = await _localStorageFile;
final storedHashMap = HashMap<String, dynamic>();
final HashMap<String, dynamic> storedHashMap = HashMap<String, dynamic>();

if (file.existsSync()) {
final Stream<List<int>> inputStream = file.openRead();
Expand Down
3 changes: 1 addition & 2 deletions lib/src/cache/lazy_cache_map.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:core';
import 'dart:collection';

import 'package:meta/meta.dart';

Expand All @@ -13,7 +12,7 @@ class LazyCacheMap extends LazyDereferencingMap {
Map<String, Object> data, {
@required Dereference dereference,
CacheState cacheState,
}) : this.cacheState =
}) : cacheState =
cacheState ?? (data is LazyCacheMap ? data.cacheState : null),
super(data, dereference: dereference);

Expand Down
4 changes: 2 additions & 2 deletions lib/src/cache/optimistic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ class OptimisticCache extends NormalizedInMemoryCache {
patch.id == removeId || _parentPatchId(patch.id) == removeId,
);

print([
print(<dynamic>[
optimisticPatches.length,
optimisticPatches.map((p) => p.id),
optimisticPatches.map<String>((OptimisticPatch p) => p.id),
removeId
]);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/core/raw_operation_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RawOperationData {
Map<String, dynamic> variables,
String operationName,
}) : _operationName = operationName,
this.variables = SplayTreeMap<String, dynamic>.of(
variables = SplayTreeMap<String, dynamic>.of(
variables ?? const <String, dynamic>{},
);

Expand Down
91 changes: 58 additions & 33 deletions lib/src/socket_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ class SocketClient {
///
/// If this instance is disposed, this method does nothing.
Future<void> _connect() async {
if (_connectionStateController.isClosed) return;
if (_connectionStateController.isClosed) {
return;
}

_connectionStateController.value = SocketConnectionState.CONNECTING;
print('Connecting to websocket: $url...');
Expand All @@ -105,15 +107,17 @@ class SocketClient {
.map<GraphQLSocketMessage>(_parseSocketMessage);

if (config.inactivityTimeout != null) {
_keepAliveSubscription = _connectionKeepAlive
.timeout(config.inactivityTimeout, onTimeout: (event) {
print(
"Haven't received keep alive message for ${config.inactivityTimeout.inSeconds} seconds. Disconnecting..");
event.close();
_socket.close(WebSocketStatus.goingAway);
_connectionStateController.value =
SocketConnectionState.NOT_CONNECTED;
}).listen(null);
_keepAliveSubscription = _connectionKeepAlive.timeout(
config.inactivityTimeout,
onTimeout: (EventSink<ConnectionKeepAlive> event) {
print(
"Haven't received keep alive message for ${config.inactivityTimeout.inSeconds} seconds. Disconnecting..");
event.close();
_socket.close(WebSocketStatus.goingAway);
_connectionStateController.value =
SocketConnectionState.NOT_CONNECTED;
},
).listen(null);
}

_messageSubscription = _messageStream.listen(
Expand All @@ -139,7 +143,9 @@ class SocketClient {
_keepAliveSubscription?.cancel();
_messageSubscription?.cancel();

if (_connectionStateController.isClosed) return;
if (_connectionStateController.isClosed) {
return;
}

if (_connectionStateController.value != SocketConnectionState.NOT_CONNECTED)
_connectionStateController.value = SocketConnectionState.NOT_CONNECTED;
Expand All @@ -149,9 +155,12 @@ class SocketClient {
print(
'Scheduling to connect in ${config.delayBetweenReconnectionAttempts.inSeconds} seconds...');

_reconnectTimer = Timer(config.delayBetweenReconnectionAttempts, () {
_connect();
});
_reconnectTimer = Timer(
config.delayBetweenReconnectionAttempts,
() {
_connect();
},
);
} else {
Timer.run(() => _connect());
}
Expand Down Expand Up @@ -238,35 +247,51 @@ class SocketClient {
.take(1);

final Observable<SocketConnectionState> waitForConnectedState = addTimeout
? waitForConnectedStateWithoutTimeout
.timeout(config.queryAndMutationTimeout, onTimeout: (e) {
print('Connection timed out.');
response.addError(TimeoutException('Connection timed out.'));
e.close();
response.close();
})
? waitForConnectedStateWithoutTimeout.timeout(
config.queryAndMutationTimeout,
onTimeout: (EventSink<SocketConnectionState> event) {
print('Connection timed out.');
response.addError(TimeoutException('Connection timed out.'));
event.close();
response.close();
},
)
: waitForConnectedStateWithoutTimeout;

sub = waitForConnectedState.listen((_) {
final Stream<GraphQLSocketMessage> dataErrorComplete =
_messageStream.where((GraphQLSocketMessage message) {
if (message is SubscriptionData) return message.id == id;
if (message is SubscriptionError) return message.id == id;
if (message is SubscriptionComplete) return message.id == id;
return false;
}).takeWhile((_) => !response.isClosed);
_messageStream.where(
(GraphQLSocketMessage message) {
if (message is SubscriptionData) {
return message.id == id;
}

if (message is SubscriptionError) {
return message.id == id;
}

if (message is SubscriptionComplete) {
return message.id == id;
}

return false;
},
).takeWhile((_) => !response.isClosed);

final Stream<GraphQLSocketMessage> subscriptionComplete = addTimeout
? dataErrorComplete
.where((GraphQLSocketMessage message) =>
message is SubscriptionComplete)
.take(1)
.timeout(config.queryAndMutationTimeout, onTimeout: (e) {
print('Request timed out.');
response.addError(TimeoutException('Request timed out.'));
e.close();
response.close();
})
.timeout(
config.queryAndMutationTimeout,
onTimeout: (EventSink<GraphQLSocketMessage> event) {
print('Request timed out.');
response.addError(TimeoutException('Request timed out.'));
event.close();
response.close();
},
)
: dataErrorComplete
.where((GraphQLSocketMessage message) =>
message is SubscriptionComplete)
Expand Down

0 comments on commit a3df378

Please # to comment.