Skip to content

Commit

Permalink
fix(realtime): 🔧 Reorder subscribeWhenReady arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
CPatchane committed Feb 6, 2019
1 parent fbc7dfa commit 40b81dc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions packages/cozy-realtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const getTypeAndIdFromListenerKey = listenerKey => {
// only if it is in a ready state. If not, retry a few milliseconds later.
const MAX_SOCKET_POLLS = 500 // to avoid infinite polling
export function subscribeWhenReady(
doctype,
socket,
doctype,
docId,
remainingTries = MAX_SOCKET_POLLS
) {
Expand All @@ -64,7 +64,7 @@ export function subscribeWhenReady(
throw error
} else {
setTimeout(() => {
subscribeWhenReady(doctype, socket, docId, --remainingTries)
subscribeWhenReady(socket, doctype, docId, --remainingTries)
}, 10)
}
}
Expand Down Expand Up @@ -169,7 +169,7 @@ export function connectWebSocket(
if (isRetry && subscriptionsState.size) {
for (let listenerKey of subscriptionsState) {
const { doctype, docId } = getTypeAndIdFromListenerKey(listenerKey)
subscribeWhenReady(doctype, socket, docId)
subscribeWhenReady(socket, doctype, docId)
}
}

Expand Down Expand Up @@ -263,7 +263,7 @@ export function getCozySocket(config) {

if (!listeners.has(listenerKey)) {
listeners.set(listenerKey, {})
subscribeWhenReady(doctype, socket, docId)
subscribeWhenReady(socket, doctype, docId)
}

listeners.set(listenerKey, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ MessageEvent {
exports[`(cozy-realtime) connectWebSocket: socket should send doctype and docId subscriptions again if this is a retry and if there are subscriptionsState 1`] = `
Array [
Array [
"io.cozy.mocks",
WebSocket {
"binaryType": "blob",
"listeners": Object {
Expand All @@ -245,10 +244,10 @@ Array [
"readyState": 0,
"url": "ws://localhost:8880/realtime/",
},
"io.cozy.mocks",
"id1234",
],
Array [
"io.cozy.mocks2",
WebSocket {
"binaryType": "blob",
"listeners": Object {
Expand All @@ -269,6 +268,7 @@ Array [
"readyState": 0,
"url": "ws://localhost:8880/realtime/",
},
"io.cozy.mocks2",
null,
],
]
Expand All @@ -277,7 +277,6 @@ Array [
exports[`(cozy-realtime) connectWebSocket: socket should send doctype subscriptions again if this is a retry and if there are subscriptionsState 1`] = `
Array [
Array [
"io.cozy.mocks",
WebSocket {
"binaryType": "blob",
"listeners": Object {
Expand All @@ -298,10 +297,10 @@ Array [
"readyState": 0,
"url": "ws://localhost:8880/realtime/",
},
"io.cozy.mocks",
null,
],
Array [
"io.cozy.mocks2",
WebSocket {
"binaryType": "blob",
"listeners": Object {
Expand All @@ -322,6 +321,7 @@ Array [
"readyState": 0,
"url": "ws://localhost:8880/realtime/",
},
"io.cozy.mocks2",
null,
],
]
Expand Down
12 changes: 6 additions & 6 deletions packages/cozy-realtime/test/subscribe.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('(cozy-realtime) subscribeWhenReady: ', () => {
send: jest.fn()
}
jest.useFakeTimers()
mockSubscribe('io.cozy.mocks', mockSocket)
mockSubscribe(mockSocket, 'io.cozy.mocks')
// we run pending timers for a number less one
Array.apply(null, { length: MAX_RETRIES - 1 }).forEach(() => {
jest.runOnlyPendingTimers()
Expand All @@ -42,7 +42,7 @@ describe('(cozy-realtime) subscribeWhenReady: ', () => {
send: jest.fn()
}
jest.useFakeTimers()
mockSubscribe('io.cozy.mocks', mockSocket, 'id1234')
mockSubscribe(mockSocket, 'io.cozy.mocks', 'id1234')
// we run pending timers for a number less one
Array.apply(null, { length: MAX_RETRIES - 1 }).forEach(() => {
jest.runOnlyPendingTimers()
Expand All @@ -66,7 +66,7 @@ describe('(cozy-realtime) subscribeWhenReady: ', () => {
jest.useFakeTimers()
console.warn = jest.fn()
expect(() => {
mockSubscribe('io.cozy.mocks', mockSocket, null, maxRetries)
mockSubscribe(mockSocket, 'io.cozy.mocks', null, maxRetries)
// we run pending timers for all retries
Array.apply(null, { length: maxRetries }).forEach(() => {
jest.runOnlyPendingTimers()
Expand All @@ -86,7 +86,7 @@ describe('(cozy-realtime) subscribeWhenReady: ', () => {
}
jest.useFakeTimers()
expect(() => {
mockSubscribe('io.cozy.mocks', mockSocket)
mockSubscribe(mockSocket, 'io.cozy.mocks')
// we run pending timers for all retries
Array.apply(null, { length: MAX_RETRIES }).forEach(() => {
jest.runOnlyPendingTimers()
Expand All @@ -103,7 +103,7 @@ describe('(cozy-realtime) subscribeWhenReady: ', () => {
}
jest.useFakeTimers()
expect(() => {
mockSubscribe('io.cozy.mocks', mockSocket, 'id1234')
mockSubscribe(mockSocket, 'io.cozy.mocks', 'id1234')
// we run pending timers for all retries
Array.apply(null, { length: MAX_RETRIES }).forEach(() => {
jest.runOnlyPendingTimers()
Expand All @@ -124,7 +124,7 @@ describe('(cozy-realtime) subscribeWhenReady: ', () => {
jest.useFakeTimers()
console.warn = jest.fn()
expect(() => {
mockSubscribe('io.cozy.mocks', mockSocket)
mockSubscribe(mockSocket, 'io.cozy.mocks')
// we run pending timers for all retries
Array.apply(null, { length: MAX_RETRIES }).forEach(() => {
jest.runOnlyPendingTimers()
Expand Down

0 comments on commit 40b81dc

Please sign in to comment.