This repository was archived by the owner on Aug 29, 2018. It is now read-only.
File tree 2 files changed +38
-4
lines changed
2 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -4,11 +4,22 @@ export default function(connection) {
4
4
if ( ! connection ) {
5
5
throw new Error ( 'Socket.io connection needs to be provided' ) ;
6
6
}
7
+
8
+ const defaultService = function ( name ) {
9
+ return new Service ( { name, connection, method : 'emit' } ) ;
10
+ } ;
7
11
8
- return function ( ) {
12
+ const initialize = function ( ) {
13
+ if ( typeof this . defaultService === 'function' ) {
14
+ throw new Error ( 'Only one default client provider can be configured' ) ;
15
+ }
16
+
9
17
this . io = connection ;
10
- this . defaultService = function ( name ) {
11
- return new Service ( { name, connection, method : 'emit' } ) ;
12
- } ;
18
+ this . defaultService = defaultService ;
13
19
} ;
20
+
21
+ initialize . Service = Service ;
22
+ initialize . service = defaultService ;
23
+
24
+ return initialize ;
14
25
}
Original file line number Diff line number Diff line change @@ -32,6 +32,29 @@ describe('feathers-socketio/client', function() {
32
32
it ( 'app has the io attribute' , ( ) => {
33
33
assert . ok ( app . io ) ;
34
34
} ) ;
35
+
36
+ it ( 'throws an error when configured twice' , ( ) => {
37
+ try {
38
+ app . configure ( socketio ( socket ) ) ;
39
+ assert . ok ( false , 'Should never get here' ) ;
40
+ } catch ( e ) {
41
+ assert . equal ( e . message , 'Only one default client provider can be configured' ) ;
42
+ }
43
+ } ) ;
44
+
45
+ it ( 'can initialize a client instance' , done => {
46
+ const init = socketio ( socket ) ;
47
+ const todos = init . service ( 'todos' ) ;
48
+
49
+ assert . ok ( todos instanceof init . Service , 'Returned service is a client' ) ;
50
+ todos . find ( { } ) . then ( todos => assert . deepEqual ( todos , [
51
+ {
52
+ text : 'some todo' ,
53
+ complete : false ,
54
+ id : 0
55
+ }
56
+ ] ) ) . then ( ( ) => done ( ) ) . catch ( done ) ;
57
+ } ) ;
35
58
36
59
baseTests ( service ) ;
37
60
} ) ;
You can’t perform that action at this time.
0 commit comments