Skip to content

Commit 9cfbea4

Browse files
committed
new libs, fix lint rules
1 parent 1ed5279 commit 9cfbea4

File tree

9 files changed

+61
-61
lines changed

9 files changed

+61
-61
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"terms": ["todo", "fixme"]
146146
}
147147
],
148-
"object-curly-spacing": 2,
148+
"object-curly-spacing": [2, "always"],
149149
"padded-blocks": [2, "never"],
150150
"quote-props": [0, "as-needed"],
151151
"quotes": [

.prettierrc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# https://prettier.io/docs/en/options.html
22
semi: false
33
singleQuote: true
4-
bracketSpacing: false
4+
bracketSpacing: true
55
arrowParens: always
66
printWidth: 100
77
trailingComma: none

packages/web/src/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
WORKER_MSG_ERROR_COMMAND,
1111
ALL_COMMANDS
1212
} from './../../../shared/constants'
13-
import {uuid} from './../../../shared/uuid'
14-
import {activateVisibilityAPI} from './visibility'
13+
import { uuid } from './../../../shared/uuid'
14+
import { activateVisibilityAPI } from './visibility'
1515

1616
const DEFAULT_OPTIONS = {
1717
workerOptions: {
@@ -44,13 +44,13 @@ const triggerSubscriptionForChannel = (id, data) => {
4444
}
4545
}
4646

47-
const handleWorkerMessages = ({event, options = {}}) => {
47+
const handleWorkerMessages = ({ event, options = {} }) => {
4848
const message = event?.data || {}
4949

5050
switch (message?.command) {
5151
case PING_COMMAND: {
5252
// always response on ping
53-
workerPort.postMessage({command: PONG_COMMAND})
53+
workerPort.postMessage({ command: PONG_COMMAND })
5454
return
5555
}
5656
case WEBSOCKET_MESSAGE_COMMAND: {
@@ -92,7 +92,7 @@ const startWorker = ({
9292
return reject('Error to create worker')
9393
}
9494

95-
workerPort.addEventListener('message', (event) => handleWorkerMessages({event, options}))
95+
workerPort.addEventListener('message', (event) => handleWorkerMessages({ event, options }))
9696
if (options.onError) {
9797
workerPort.addEventListener('error', (event) => options.onError(event.toString()))
9898
workerPort.addEventListener('messageerror', (event) => options.onError(event.toString()))
@@ -107,15 +107,15 @@ const startWorker = ({
107107
timeout: options.visibilityTimeout,
108108
visible: (isChannelsWasPaused) => {
109109
if (isChannelsWasPaused) {
110-
workerPort.postMessage({command: VISIBILITY_SHOW_COMMAND})
110+
workerPort.postMessage({ command: VISIBILITY_SHOW_COMMAND })
111111
}
112112
if (options.onVisibilityChange) {
113113
options.onVisibilityChange(true, isChannelsWasPaused)
114114
}
115115
},
116116
hidden: (isChannelsWasPaused) => {
117117
if (isChannelsWasPaused) {
118-
workerPort.postMessage({command: VISIBILITY_HIDDEN_COMMAND})
118+
workerPort.postMessage({ command: VISIBILITY_HIDDEN_COMMAND })
119119
}
120120
if (options.onVisibilityChange) {
121121
options.onVisibilityChange(false, isChannelsWasPaused)
@@ -129,7 +129,7 @@ const startWorker = ({
129129
if (ALL_COMMANDS.indexOf(command) >= 0) {
130130
throw new Error(`Command ${command} busy by cable-shared-worker`)
131131
}
132-
workerPort.postMessage({command, data})
132+
workerPort.postMessage({ command, data })
133133
}
134134
})
135135
}
@@ -144,7 +144,7 @@ const initWorker = (workerUrl, options = {}) =>
144144
return reject('Need to provide worker url')
145145
}
146146

147-
const {workerOptions, ...restOptions} = options
147+
const { workerOptions, ...restOptions } = options
148148

149149
const mergedOptions = {
150150
...DEFAULT_OPTIONS,
@@ -208,7 +208,7 @@ const createChannel = (channel, params = {}, onReceiveMessage = () => ({})) =>
208208
if (workerPort) {
209209
workerPort.postMessage({
210210
command: WEBSOCKET_PERFORM_COMMAND,
211-
subscription: {id},
211+
subscription: { id },
212212
perform: {
213213
action: performAction,
214214
params: performParams
@@ -230,7 +230,7 @@ const createChannel = (channel, params = {}, onReceiveMessage = () => ({})) =>
230230
if (workerPort) {
231231
workerPort.postMessage({
232232
command: UNSUBSCRIBE_FROM_CHANNEL,
233-
subscription: {id}
233+
subscription: { id }
234234
})
235235
}
236236
}

packages/web/src/visibility.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const getVisibilityPropertyNames = () => {
1212

1313
const [visibilityState, visibilityChange] = getVisibilityPropertyNames()
1414

15-
export const activateVisibilityAPI = ({timeout, visible, hidden}) => {
15+
export const activateVisibilityAPI = ({ timeout, visible, hidden }) => {
1616
let visibilityTimer = null
1717
let isChannelsWasPaused = false
1818

packages/worker/src/cableWrapper.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ACTIONCABLE_TYPE, WEBSOCKET_MESSAGE_COMMAND} from './../../../shared/constants'
1+
import { ACTIONCABLE_TYPE, WEBSOCKET_MESSAGE_COMMAND } from './../../../shared/constants'
22

33
const UNSUBSCRIBE_CHECK_TIMEOUT = 300 // give time to unsubscribe from channels
44

@@ -71,10 +71,10 @@ export const initCableWrapper = (apiType = ACTIONCABLE_TYPE, api, options = {},
7171
}
7272
return resolve()
7373
}),
74-
subscribeTo: ({port, portID, id, channel, params = {}}) => {
74+
subscribeTo: ({ port, portID, id, channel, params = {} }) => {
7575
resumeConnectionIfNeeded()
7676

77-
const channelData = {channel, params}
77+
const channelData = { channel, params }
7878

7979
const addSubscription = (subscriptionChannel) => {
8080
portReceiverMapping = {
@@ -97,7 +97,7 @@ export const initCableWrapper = (apiType = ACTIONCABLE_TYPE, api, options = {},
9797
},
9898
{
9999
received: (data) => {
100-
port.postMessage({command: WEBSOCKET_MESSAGE_COMMAND, data, id})
100+
port.postMessage({ command: WEBSOCKET_MESSAGE_COMMAND, data, id })
101101
}
102102
}
103103
)
@@ -106,22 +106,22 @@ export const initCableWrapper = (apiType = ACTIONCABLE_TYPE, api, options = {},
106106
} else {
107107
return websocketConnection.subscribeTo(channel, params).then((subscriptionChannel) => {
108108
subscriptionChannel.on('message', (data) => {
109-
port.postMessage({command: WEBSOCKET_MESSAGE_COMMAND, data, id})
109+
port.postMessage({ command: WEBSOCKET_MESSAGE_COMMAND, data, id })
110110
})
111111

112112
return addSubscription(subscriptionChannel)
113113
})
114114
}
115115
},
116-
performInChannel: (portID, id, {action, params = {}}) => {
116+
performInChannel: (portID, id, { action, params = {} }) => {
117117
if (portReceiverMapping[portID] && portReceiverMapping[portID][id]?.channel) {
118-
const {channel} = portReceiverMapping[portID][id]
118+
const { channel } = portReceiverMapping[portID][id]
119119
channel.perform(action, params)
120120
}
121121
},
122122
unsubscribeFrom: (portID, id) => {
123123
if (portReceiverMapping[portID] && portReceiverMapping[portID][id]?.channel) {
124-
const {channel} = portReceiverMapping[portID][id]
124+
const { channel } = portReceiverMapping[portID][id]
125125
if (isActioncableAPI) {
126126
channel.unsubscribe()
127127
} else {
@@ -158,7 +158,7 @@ export const initCableWrapper = (apiType = ACTIONCABLE_TYPE, api, options = {},
158158
if (portKey === portID) {
159159
Object.keys(portReceiverMapping[portKey]).forEach((keySub) => {
160160
if (portReceiverMapping[portKey][keySub]?.channel) {
161-
const {channel} = portReceiverMapping[portKey][keySub]
161+
const { channel } = portReceiverMapping[portKey][keySub]
162162
if (isActioncableAPI) {
163163
channel.unsubscribe()
164164
} else {
@@ -179,7 +179,7 @@ export const initCableWrapper = (apiType = ACTIONCABLE_TYPE, api, options = {},
179179
setTimeout(() => pauseConnectionIfNeeded(), UNSUBSCRIBE_CHECK_TIMEOUT)
180180
}
181181
},
182-
resumeChannels: ({id, port}) => {
182+
resumeChannels: ({ id, port }) => {
183183
if (portReceiverMapping[id]) {
184184
resumeConnectionIfNeeded()
185185

@@ -201,15 +201,15 @@ export const initCableWrapper = (apiType = ACTIONCABLE_TYPE, api, options = {},
201201
portReceiverMapping[id][keySub]?.channelData &&
202202
!portReceiverMapping[id][keySub]?.channel
203203
) {
204-
const {channel, params} = portReceiverMapping[id][keySub].channelData
204+
const { channel, params } = portReceiverMapping[id][keySub].channelData
205205
const subscriptionChannel = websocketConnection.subscriptions.create(
206206
{
207207
...params,
208208
channel
209209
},
210210
{
211211
received: (data) => {
212-
port.postMessage({command: WEBSOCKET_MESSAGE_COMMAND, data, id: keySub})
212+
port.postMessage({ command: WEBSOCKET_MESSAGE_COMMAND, data, id: keySub })
213213
}
214214
}
215215
)
@@ -236,13 +236,13 @@ export const initCableWrapper = (apiType = ACTIONCABLE_TYPE, api, options = {},
236236
portReceiverMapping[id][keySub]?.channelData &&
237237
!portReceiverMapping[id][keySub]?.channel
238238
) {
239-
const {channelData} = portReceiverMapping[id][keySub]
240-
const {channel, params} = channelData
239+
const { channelData } = portReceiverMapping[id][keySub]
240+
const { channel, params } = channelData
241241
return websocketConnection
242242
.subscribeTo(channel, params)
243243
.then((subscriptionChannel) => {
244244
subscriptionChannel.on('message', (data) => {
245-
port.postMessage({command: WEBSOCKET_MESSAGE_COMMAND, data, id: keySub})
245+
port.postMessage({ command: WEBSOCKET_MESSAGE_COMMAND, data, id: keySub })
246246
})
247247

248248
return [
@@ -275,7 +275,7 @@ export const initCableWrapper = (apiType = ACTIONCABLE_TYPE, api, options = {},
275275
}
276276
}
277277
},
278-
pauseChannels: ({id}) => {
278+
pauseChannels: ({ id }) => {
279279
if (portReceiverMapping[id]) {
280280
portReceiverMapping = {
281281
...portReceiverMapping,
@@ -284,7 +284,7 @@ export const initCableWrapper = (apiType = ACTIONCABLE_TYPE, api, options = {},
284284
portReceiverMapping[id][keySub]?.channel &&
285285
portReceiverMapping[id][keySub]?.channelData
286286
) {
287-
const {channel, ...restData} = portReceiverMapping[id][keySub]
287+
const { channel, ...restData } = portReceiverMapping[id][keySub]
288288
if (isActioncableAPI) {
289289
channel.unsubscribe()
290290
} else {

packages/worker/src/index.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
WORKER_MSG_ERROR_COMMAND,
99
ALL_COMMANDS
1010
} from './../../../shared/constants'
11-
import {addPortForStore, updatePortPongTime, recurrentPortsChecks} from './workerPorts'
12-
import {loadCableApiWrapper} from './workerCable'
11+
import { addPortForStore, updatePortPongTime, recurrentPortsChecks } from './workerPorts'
12+
import { loadCableApiWrapper } from './workerCable'
1313

1414
const DEFAULT_OPTIONS = {
1515
cableType: 'actioncable', // anycable, actioncable
@@ -46,7 +46,7 @@ const activateChannelInQueue = () => {
4646
return
4747
}
4848

49-
const subscribeToChannel = ({id, port}, channelSettings = {}) => {
49+
const subscribeToChannel = ({ id, port }, channelSettings = {}) => {
5050
const params = {
5151
portID: id,
5252
port,
@@ -86,31 +86,31 @@ const performInChannel = (portID, id, perform) => {
8686
return
8787
}
8888

89-
const resumeChannelsForPort = ({id, port}) => {
89+
const resumeChannelsForPort = ({ id, port }) => {
9090
if (!cableAPI || cableAPI.isDisconnected()) {
9191
return
9292
}
9393

94-
cableAPI.resumeChannels({id, port})
94+
cableAPI.resumeChannels({ id, port })
9595

9696
return
9797
}
9898

99-
const pauseChannelsForPort = ({id, port}) => {
99+
const pauseChannelsForPort = ({ id, port }) => {
100100
if (!cableAPI || cableAPI.isDisconnected()) {
101101
return
102102
}
103103

104-
cableAPI.pauseChannels({id, port})
104+
cableAPI.pauseChannels({ id, port })
105105

106106
return
107107
}
108108

109-
const captureWorkerError = ({port, event}) => {
110-
port.postMessage({command: WORKER_MSG_ERROR_COMMAND, event: event.toString()})
109+
const captureWorkerError = ({ port, event }) => {
110+
port.postMessage({ command: WORKER_MSG_ERROR_COMMAND, event: event.toString() })
111111
}
112112

113-
const handleWorkerMessages = ({id, event, port}) => {
113+
const handleWorkerMessages = ({ id, event, port }) => {
114114
const message = event?.data || {}
115115

116116
switch (message?.command) {
@@ -120,7 +120,7 @@ const handleWorkerMessages = ({id, event, port}) => {
120120
return
121121
}
122122
case SUBSCRIBE_TO_CHANNEL: {
123-
subscribeToChannel({id, port}, message?.subscription)
123+
subscribeToChannel({ id, port }, message?.subscription)
124124
return
125125
}
126126
case UNSUBSCRIBE_FROM_CHANNEL: {
@@ -132,11 +132,11 @@ const handleWorkerMessages = ({id, event, port}) => {
132132
return
133133
}
134134
case VISIBILITY_SHOW_COMMAND: {
135-
resumeChannelsForPort({id, port})
135+
resumeChannelsForPort({ id, port })
136136
return
137137
}
138138
case VISIBILITY_HIDDEN_COMMAND: {
139-
pauseChannelsForPort({id, port})
139+
pauseChannelsForPort({ id, port })
140140
return
141141
}
142142
default: {
@@ -146,15 +146,15 @@ const handleWorkerMessages = ({id, event, port}) => {
146146
if (ALL_COMMANDS.indexOf(command) >= 0) {
147147
throw new Error(`Command ${command} busy by cable-shared-worker`)
148148
}
149-
port.postMessage({command, data})
149+
port.postMessage({ command, data })
150150
}
151151
cableOptions.handleCustomWebCommand(message?.command, message?.data, responseFn)
152152
}
153153
}
154154
}
155155
}
156156

157-
const disconnectSubscriptionsFromPort = ({id}) => {
157+
const disconnectSubscriptionsFromPort = ({ id }) => {
158158
if (!cableAPI) {
159159
return
160160
}
@@ -166,8 +166,8 @@ const disconnectSubscriptionsFromPort = ({id}) => {
166166

167167
const registerPort = (port) => {
168168
const id = addPortForStore(port)
169-
port.addEventListener('message', (event) => handleWorkerMessages({port, id, event}))
170-
port.addEventListener('messageerror', (event) => captureWorkerError({port, id, event}))
169+
port.addEventListener('message', (event) => handleWorkerMessages({ port, id, event }))
170+
port.addEventListener('messageerror', (event) => captureWorkerError({ port, id, event }))
171171
}
172172

173173
if (isSharedWorker) {
@@ -198,13 +198,13 @@ const initCableLibrary = (options = {}) => {
198198
if (cableAPI) {
199199
return cableAPI
200200
}
201-
cableOptions = {...DEFAULT_OPTIONS, ...options}
202-
const {cableType, cableLibrary, ...restOptions} = cableOptions
201+
cableOptions = { ...DEFAULT_OPTIONS, ...options }
202+
const { cableType, cableLibrary, ...restOptions } = cableOptions
203203
cableAPI = loadCableApiWrapper(cableType, cableLibrary, restOptions, {
204204
connect: afterConnect,
205205
disconnect: afterDisconnect
206206
})
207207
return cableAPI
208208
}
209209

210-
export {initCableLibrary}
210+
export { initCableLibrary }

packages/worker/src/workerCable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {ACTIONCABLE_TYPE, ANYCABLE_TYPE} from './../../../shared/constants'
2-
import {initCableWrapper} from './cableWrapper'
1+
import { ACTIONCABLE_TYPE, ANYCABLE_TYPE } from './../../../shared/constants'
2+
import { initCableWrapper } from './cableWrapper'
33

44
export const loadCableApiWrapper = (
55
cableType = ACTIONCABLE_TYPE,

0 commit comments

Comments
 (0)