File tree 2 files changed +27
-2
lines changed
2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -790,3 +790,23 @@ export function copyToClipboard (state) {
790
790
export function isEmptyObject ( obj ) {
791
791
return obj === UNDEFINED || ! obj || Object . keys ( obj ) . length === 0
792
792
}
793
+
794
+ /**
795
+ * chunk an array into smaller chunk of given size.
796
+ * @see https://stackoverflow.com/a/37826698
797
+ * @param array
798
+ * @param size
799
+ */
800
+ export function chunk ( array : unknown [ ] , size : number ) : unknown [ ] [ ] {
801
+ return array . reduce ( ( resultArray , item , index ) => {
802
+ const chunkIndex = Math . floor ( index / size )
803
+
804
+ if ( ! resultArray [ chunkIndex ] ) {
805
+ resultArray [ chunkIndex ] = [ ] // start a new chunk
806
+ }
807
+
808
+ resultArray [ chunkIndex ] . push ( item )
809
+
810
+ return resultArray
811
+ } , [ ] ) as unknown [ ] [ ]
812
+ }
Original file line number Diff line number Diff line change 1
1
import io from 'socket.io-client'
2
2
import { initBackend } from '@back'
3
3
import { installToast } from '@back/toast'
4
- import { Bridge , target } from '@vue-devtools/shared-utils'
4
+ import { Bridge , target , chunk } from '@vue-devtools/shared-utils'
5
5
6
6
const host = target . __VUE_DEVTOOLS_HOST__ || 'http://localhost'
7
7
const port = target . __VUE_DEVTOOLS_PORT__ !== undefined ? target . __VUE_DEVTOOLS_PORT__ : 8098
8
8
const fullHost = port ? host + ':' + port : host
9
9
const createSocket = target . __VUE_DEVTOOLS_SOCKET__ || io
10
10
const socket = createSocket ( fullHost )
11
+ const MAX_DATA_CHUNK = 2000
11
12
12
13
const connectedMessage = ( ) => {
13
14
if ( target . __VUE_DEVTOOLS_TOAST__ ) {
@@ -45,7 +46,11 @@ const bridge = new Bridge({
45
46
socket . on ( 'vue-message' , data => fn ( data ) )
46
47
} ,
47
48
send ( data ) {
48
- socket . emit ( 'vue-message' , data )
49
+ const chunks = chunk ( data , MAX_DATA_CHUNK )
50
+
51
+ for ( const chunk of chunks ) {
52
+ socket . emit ( 'vue-message' , chunk )
53
+ }
49
54
} ,
50
55
} )
51
56
You can’t perform that action at this time.
0 commit comments