Commit 1d66da15 authored by Corbin Crutchley's avatar Corbin Crutchley Committed by Luis Fernando Alvarez D

with apollo and redux saga example: Update deps (#6734)

* with apollo and redux saga example: Update deps

* Fix linting problems
parent e0326600
import { delay } from 'redux-saga'
import { call, put, take } from 'redux-saga/effects'
import es6promise from 'es6-promise'
import { delay, call, put, take } from 'redux-saga/effects'
import { polyfill } from 'es6-promise'
import 'isomorphic-unfetch'
import { actionTypes, tickClock } from './actions'
es6promise.polyfill()
polyfill()
function * runClockSaga () {
yield take(actionTypes.START_CLOCK)
while (true) {
yield put(tickClock(false))
yield call(delay, 800)
yield delay(800)
}
}
......
import { put, takeLatest } from 'redux-saga/effects'
import es6promise from 'es6-promise'
import { polyfill } from 'es6-promise'
import fetch from 'isomorphic-unfetch'
import { actionTypes, loadDataSuccess, loadDataError } from './actions'
es6promise.polyfill()
polyfill()
function * loadDataSaga () {
try {
......
import { all } from 'redux-saga/effects'
import clock from './clock/sagas'
import placeholder from './placeholder/sagas'
import 'isomorphic-unfetch'
import clockSaga from './clock/sagas'
import placeholderSaga from './placeholder/sagas'
function * rootSaga () {
yield all([clock, placeholder])
yield all([clockSaga, placeholderSaga])
}
export default rootSaga
import { applyMiddleware, createStore } from 'redux'
import createSagaMiddleware from 'redux-saga'
import rootReducer from './rootReducer'
import rootSaga from './rootSaga'
const bindMiddleware = middleware => {
if (process.env.NODE_ENV !== 'production') {
const { composeWithDevTools } = require('redux-devtools-extension')
return composeWithDevTools(applyMiddleware(...middleware))
}
return applyMiddleware(...middleware)
}
function configureStore (initialState) {
const sagaMiddleware = createSagaMiddleware()
const store = createStore(
rootReducer,
initialState,
bindMiddleware([sagaMiddleware])
)
store.sagaTask = sagaMiddleware.run(rootSaga)
return store
}
export default configureStore
......@@ -4,28 +4,31 @@
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
"start": "cross-env NODE_ENV=production node server.js"
},
"dependencies": {
"apollo-client-preset": "^1.0.4",
"es6-promise": "^4.1.1",
"graphql": "^0.11.7",
"graphql": "^14.1.1",
"graphql-anywhere": "^4.0.2",
"graphql-tag": "^2.5.0",
"isomorphic-unfetch": "^2.0.0",
"isomorphic-unfetch": "^3.0.0",
"next": "latest",
"next-redux-saga": "^1.0.0",
"next-redux-wrapper": "^1.3.5",
"next-redux-saga": "^4.0.1",
"next-redux-wrapper": "^2.1.0",
"next-routes": "^1.2.0",
"prop-types": "^15.6.0",
"react": "^16.7.0",
"react-apollo": "^2.0.0",
"react-dom": "^16.7.0",
"react-redux": "^5.0.0",
"redux": "^3.7.0",
"react-redux": "^6.0.1",
"redux": "^4.0.1",
"redux-devtools-extension": "^2.13.2",
"redux-saga": "^0.16.0"
"redux-saga": "^1.0.2"
},
"author": "",
"license": "ISC"
"license": "ISC",
"devDependencies": {
"cross-env": "^5.2.0"
}
}
import App, { Container } from 'next/app'
import React from 'react'
import { Provider } from 'react-redux'
import withRedux from 'next-redux-wrapper'
import withReduxSaga from 'next-redux-saga'
import createStore from '../lib/store'
class MyApp extends App {
static async getInitialProps ({ Component, ctx }) {
let pageProps = {}
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps({ ctx })
}
return { pageProps }
}
render () {
const { Component, pageProps, store } = this.props
return (
<Container>
<Provider store={store}>
<Component {...pageProps} />
</Provider>
</Container>
)
}
}
export default withRedux(createStore)(withReduxSaga(MyApp))
......@@ -12,7 +12,7 @@ import PostList from '../../components/PostList'
class BlogIndex extends React.Component {
componentDidMount () {
this.props.dispatch(startClock())
this.props.store.dispatch(startClock())
}
render () {
......
import React from 'react'
import withReduxSaga from '../lib/withReduxSaga'
import { connect } from 'react-redux'
import { startClock } from '../lib/clock/actions'
import { countIncrease } from '../lib/count/actions'
......@@ -11,7 +11,7 @@ import Header from '../components/Header'
import Page from '../components/Page'
class PageIndex extends React.Component {
static async getInitialProps ({ store }) {
static async getInitialProps ({ ctx: { store } }) {
store.dispatch(countIncrease())
if (!store.getState().placeholder.data) {
store.dispatch(loadData())
......@@ -32,4 +32,4 @@ class PageIndex extends React.Component {
}
}
export default withReduxSaga(PageIndex)
export default connect()(PageIndex)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment