Skip to content

Commit

Permalink
Wrap socketcluster in class
Browse files Browse the repository at this point in the history
Allow mocking.
  • Loading branch information
MichaelMarner committed Oct 9, 2018
1 parent 1f33280 commit 824d9a9
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.0.3

- Specify minimum version of socketcluster_client

# 0.0.2

Use socketcluster_client from pub.
Expand Down
3 changes: 2 additions & 1 deletion lib/redux_remote_devtools.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library remote_devtools;
library redux_remote_devtools;

import 'package:redux/redux.dart';
import 'package:socketcluster_client/socketcluster_client.dart';
Expand All @@ -7,5 +7,6 @@ import 'dart:convert';
import 'dart:async';

part './src/action_encoder.dart';
part './src/socketcluster_wrapper.dart';
part './src/state_encoder.dart';
part './src/remote_devtools_middleware.dart';
2 changes: 1 addition & 1 deletion lib/src/action_encoder.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of remote_devtools;
part of redux_remote_devtools;

/// Interface for custom action encoding logic
abstract class ActionEncoder {
Expand Down
7 changes: 4 additions & 3 deletions lib/src/remote_devtools_middleware.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of remote_devtools;
part of redux_remote_devtools;

class RemoteDevToolsMiddleware extends MiddlewareClass {
/**
Expand All @@ -9,7 +9,7 @@ class RemoteDevToolsMiddleware extends MiddlewareClass {
*
*/
String _host;
Socket socket;
SocketClusterWrapper socket;
Store store;
String _channel;
bool _started = false;
Expand All @@ -22,7 +22,8 @@ class RemoteDevToolsMiddleware extends MiddlewareClass {
this.stateEncoder = const JsonStateEncoder(),
this.socket}) {
if (socket == null) {
this.socket = new Socket('ws://${this._host}/socketcluster/');
this.socket =
new SocketClusterWrapper('ws://${this._host}/socketcluster/');
}
}

Expand Down
21 changes: 21 additions & 0 deletions lib/src/socketcluster_wrapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
part of redux_remote_devtools;

class SocketClusterWrapper {
Socket _socket;
String url;
SocketClusterWrapper(this.url);

Future<void> connect() async {
this._socket = await Socket.connect(this.url);
}

Emitter on(String event, Function func) {
return this._socket.on(event, func);
}

void emit(String event, Object data, [AckCall ack]) {
this._socket.emit(event, data, ack);
}

get id => this._socket.id;
}
2 changes: 1 addition & 1 deletion lib/src/state_encoder.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
part of remote_devtools;
part of redux_remote_devtools;

/// Interface for custom State encoding logic
abstract class StateEncoder {
Expand Down
4 changes: 2 additions & 2 deletions test/remote_devtools_middleware_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:socketcluster_client/socketcluster_client.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';

class MockSocket extends Mock implements Socket {}
class MockSocket extends Mock implements SocketClusterWrapper {}

void main() {
group('RemoteDevtoolsMiddleware', () {
Expand All @@ -15,7 +15,7 @@ void main() {
});
});
group('connect', () {
Socket socket;
var socket;
RemoteDevToolsMiddleware devtools;
setUp(() {
socket = new MockSocket();
Expand Down

0 comments on commit 824d9a9

Please sign in to comment.