Skip to content
Open

Ht5 #31

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import firebase from 'firebase'

export const appName = 'advreact-1610'
const appId = 'ec352'

firebase.initializeApp({
apiKey: "AIzaSyB31xpTtp4Jln_hb2kAbE4PGf6Mi8EgLyA",
authDomain: `${appName}.firebaseapp.com`,
databaseURL: `https://${appName}.firebaseio.com`,
projectId: appName,
storageBucket: "",
messagingSenderId: "397157634637"
})
apiKey: "AIzaSyB3LVTO7RSDrZAkHBkpzg9T5KkuoCoy4qo",
authDomain: `${appName}-${appId}.firebaseapp.com`,
databaseURL: `https://${appName}-${appId}.firebaseio.com`,
projectId: `${appName}-${appId}`,
storageBucket: `${appName}-${appId}.appspot.com`,
messagingSenderId: "651090769196"
})
43 changes: 35 additions & 8 deletions src/ducks/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import {appName} from '../config'
import {Record} from 'immutable'
import firebase from 'firebase'
import {createSelector} from 'reselect'
import {call, put, all, take} from 'redux-saga/effects'
import {call, put, all, take, spawn} from 'redux-saga/effects'
import {replace} from 'react-router-redux'
import {eventChannel} from 'redux-saga'

/**
* Constants
Expand Down Expand Up @@ -69,14 +70,14 @@ export function signIn(email, password) {
}
}

firebase.auth().onAuthStateChanged(user => {
if (!user) return
// firebase.auth().onAuthStateChanged(user => {
// if (!user) return

window.store.dispatch({
type: SIGN_IN_SUCCESS,
payload: { user }
})
})
// window.store.dispatch({
// type: SIGN_IN_SUCCESS,
// payload: { user }
// })
// })

/**
* Sagas
Expand Down Expand Up @@ -134,7 +135,33 @@ export function * watchStatusChangeSaga() {
}
}

const createAuthSocket = () => eventChannel(emit => {
const authChannel = eventChannel(emit => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему ты 2 раза eventChannel пытаешься создать?

const unsubscribe = firebase.auth().onAuthStateChanged(
user => emit({ user }),
error => emit({ error })
)

return unsubscribe;
});
})

export const realtimeAuthSaga = function * () {
const task = yield call(createAuthSocket)

while (true) {
const { user } = yield take(createAuthSocket)

yield put({
type: SIGN_IN_SUCCESS,
payload: { user }
})
}
}

export function * saga() {
yield spawn(realtimeAuthSaga)

yield all([
signUpSaga(),
signInSaga(),
Expand Down
11 changes: 10 additions & 1 deletion src/ducks/people.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {delay, eventChannel} from 'redux-saga'
import firebase from 'firebase'
import {createSelector} from 'reselect'
import {fbToEntities} from './utils'
import {LOCATION_CHANGE} from 'react-router-redux'

/**
* Constants
Expand Down Expand Up @@ -193,11 +194,19 @@ export const realtimePeopleSyncSaga = function * () {
}
}

export const cancelRealtimePeopleSyncSaga = function * (action) {
if (action && action.payload && action.payload.pathname !== '/people') {
const watcher = yield fork(realtimePeopleSyncSaga);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ты подписался и сразу убил, никакого смысла в этом нет. Синхронизация по прежнему продолжается в другой саге

yield cancel(watcher);
}
}

export function * saga() {
yield spawn(realtimePeopleSyncSaga)

yield all([
takeEvery(ADD_PERSON_REQUEST, addPersonSaga),
takeEvery(ADD_EVENT_REQUEST, addEventToPersonSaga)
takeEvery(ADD_EVENT_REQUEST, addEventToPersonSaga),
takeEvery(LOCATION_CHANGE, cancelRealtimePeopleSyncSaga)
])
}