현재 프로젝트에서는 firebase websocket subscription을 다루고 있습니다. 다른 구성 요소는 다른 데이터에 가입 할 수 있습니다 (예 : 모든 항목의 목록에있는 ListItem
구성 요소는 SUBSCRIBE
작업을 에 디스패치하고 UNSUBSCRIBE
작업을 componentWillUnmount
에 디스패치하여 수신 거부를 설정하여 해당 특정 항목에 대한 웹 소켓 "이벤트"를 구독합니다.redux-saga로 수많은 이벤트에 가입/탈퇴 처리하기
내 무용담는 다음과 같다 :
const subscriptions = {}
export function * subscribeLoop() {
while (true) {
const { path } = yield take(SUBSCRIBE)
subscriptions[path] = yield fork(subscription, path)
}
}
export function * unsubscribeLoop() {
while (true) {
const { path } = yield take(UNSUBSCRIBE)
yield cancel(subscriptions[path])
}
}
export function * subscription (path) {
let ref
try {
const updateChannel = channel()
ref = api.child(path)
ref.on('value', snapshot => {
updateChannel.put(snapshot.val())
})
while (true) {
const data = yield take(updateChannel)
yield put(handleUpdate(path, data))
}
} finally {
if (yield cancelled()) {
ref.off()
ref = null
}
}
}
I는이 처리 할 수있는 권리 방법이 아니다 가정 - 그것은 참으로 500 개 항목의 목록에 다소 느립니다.
어떻게 성능을 최적화 할 수 있습니까?
- 포크가 필요합니까?
- 스레드에게 다른 것들을 처리 할 공간을주기 위해 일종의 지연을 도입해야합니까?
모든 힌트를 부탁드립니다.