Skip to content

Commit

Permalink
updating with-redux-saga example (#4356)
Browse files Browse the repository at this point in the history
  • Loading branch information
gastonfartek authored and timneutkens committed May 13, 2018
1 parent af10822 commit 4f59c95
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 22 deletions.
12 changes: 6 additions & 6 deletions examples/with-redux-saga/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"dependencies": {
"es6-promise": "4.1.1",
"isomorphic-unfetch": "2.0.0",
"next": "latest",
"next-redux-saga": "1.0.1",
"next-redux-wrapper": "1.2.0",
"next": "6.0.1",
"next-redux-saga": "3.0.0-beta.1",
"next-redux-wrapper": "2.0.0-beta.6",
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-redux": "5.0.5",
"redux": "3.7.2",
"redux-saga": "0.15.4"
"react-redux": "5.0.7",
"redux": "4.0.0",
"redux-saga": "0.16.0"
},
"devDependencies": {
"redux-devtools-extension": "2.13.2"
Expand Down
31 changes: 31 additions & 0 deletions examples/with-redux-saga/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import App, { Container } from 'next/app'
import React from 'react'
import { Provider } from 'react-redux'
import withRedux from 'next-redux-wrapper'
import createStore from '../store'
import withReduxSaga from 'next-redux-saga'

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({ async: true })(MyApp))
11 changes: 6 additions & 5 deletions examples/with-redux-saga/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react'

import {connect} from 'react-redux'
import {increment, loadData, startClock, tickClock} from '../actions'
import {withReduxSaga} from '../store'
import Page from '../components/page'

class Counter extends React.Component {
static async getInitialProps ({store, isServer}) {
store.dispatch(tickClock(isServer))
static async getInitialProps (props) {
const { store } = props.ctx
store.dispatch(tickClock(props.isServer))
store.dispatch(increment())

if (!store.getState().placeholderData) {
store.dispatch(loadData())
}
Expand All @@ -22,4 +23,4 @@ class Counter extends React.Component {
}
}

export default withReduxSaga(Counter)
export default connect()(Counter)
9 changes: 5 additions & 4 deletions examples/with-redux-saga/pages/other.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react'

import {connect} from 'react-redux'
import {increment, startClock, tickClock} from '../actions'
import {withReduxSaga} from '../store'
import Page from '../components/page'

class Counter extends React.Component {
static async getInitialProps ({store, isServer}) {
static async getInitialProps (props) {
const { store, isServer } = props.ctx
store.dispatch(tickClock(isServer))
store.dispatch(increment())
return { isServer }
}

componentDidMount () {
Expand All @@ -19,4 +20,4 @@ class Counter extends React.Component {
}
}

export default withReduxSaga(Counter)
export default connect()(Counter)
13 changes: 6 additions & 7 deletions examples/with-redux-saga/store.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {createStore, applyMiddleware} from 'redux'
import withRedux from 'next-redux-wrapper'
import nextReduxSaga from 'next-redux-saga'
import createSagaMiddleware from 'redux-saga'

import rootReducer, {exampleInitialState} from './reducer'
import rootSaga from './saga'

Expand All @@ -23,10 +20,12 @@ export function configureStore (initialState = exampleInitialState) {
bindMiddleware([sagaMiddleware])
)

store.sagaTask = sagaMiddleware.run(rootSaga)
store.runSagaTask = () => {
store.sagaTask = sagaMiddleware.run(rootSaga)
}

store.runSagaTask()
return store
}

export function withReduxSaga (BaseComponent) {
return withRedux(configureStore)(nextReduxSaga(BaseComponent))
}
export default configureStore

0 comments on commit 4f59c95

Please sign in to comment.