Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
4f59c951
Commit
4f59c951
authored
May 13, 2018
by
Gaston Fartek
Committed by
Tim Neutkens
May 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updating with-redux-saga example (#4356)
parent
af108228
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
22 deletions
+54
-22
package.json
examples/with-redux-saga/package.json
+6
-6
_app.js
examples/with-redux-saga/pages/_app.js
+31
-0
index.js
examples/with-redux-saga/pages/index.js
+6
-5
other.js
examples/with-redux-saga/pages/other.js
+5
-4
store.js
examples/with-redux-saga/store.js
+6
-7
No files found.
examples/with-redux-saga/package.json
View file @
4f59c951
...
@@ -10,14 +10,14 @@
...
@@ -10,14 +10,14 @@
"dependencies"
:
{
"dependencies"
:
{
"es6-promise"
:
"4.1.1"
,
"es6-promise"
:
"4.1.1"
,
"isomorphic-unfetch"
:
"2.0.0"
,
"isomorphic-unfetch"
:
"2.0.0"
,
"next"
:
"
latest
"
,
"next"
:
"
6.0.1
"
,
"next-redux-saga"
:
"
1.0
.1"
,
"next-redux-saga"
:
"
3.0.0-beta
.1"
,
"next-redux-wrapper"
:
"
1.2.0
"
,
"next-redux-wrapper"
:
"
2.0.0-beta.6
"
,
"react"
:
"^16.0.0"
,
"react"
:
"^16.0.0"
,
"react-dom"
:
"^16.0.0"
,
"react-dom"
:
"^16.0.0"
,
"react-redux"
:
"5.0.
5
"
,
"react-redux"
:
"5.0.
7
"
,
"redux"
:
"
3.7.2
"
,
"redux"
:
"
4.0.0
"
,
"redux-saga"
:
"0.1
5.4
"
"redux-saga"
:
"0.1
6.0
"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"redux-devtools-extension"
:
"2.13.2"
"redux-devtools-extension"
:
"2.13.2"
...
...
examples/with-redux-saga/pages/_app.js
0 → 100644
View file @
4f59c951
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
))
examples/with-redux-saga/pages/index.js
View file @
4f59c951
import
React
from
'react'
import
React
from
'react'
import
{
connect
}
from
'react-redux'
import
{
increment
,
loadData
,
startClock
,
tickClock
}
from
'../actions'
import
{
increment
,
loadData
,
startClock
,
tickClock
}
from
'../actions'
import
{
withReduxSaga
}
from
'../store'
import
Page
from
'../components/page'
import
Page
from
'../components/page'
class
Counter
extends
React
.
Component
{
class
Counter
extends
React
.
Component
{
static
async
getInitialProps
({
store
,
isServer
})
{
static
async
getInitialProps
(
props
)
{
store
.
dispatch
(
tickClock
(
isServer
))
const
{
store
}
=
props
.
ctx
store
.
dispatch
(
tickClock
(
props
.
isServer
))
store
.
dispatch
(
increment
())
store
.
dispatch
(
increment
())
if
(
!
store
.
getState
().
placeholderData
)
{
if
(
!
store
.
getState
().
placeholderData
)
{
store
.
dispatch
(
loadData
())
store
.
dispatch
(
loadData
())
}
}
...
@@ -22,4 +23,4 @@ class Counter extends React.Component {
...
@@ -22,4 +23,4 @@ class Counter extends React.Component {
}
}
}
}
export
default
withReduxSaga
(
Counter
)
export
default
connect
()
(
Counter
)
examples/with-redux-saga/pages/other.js
View file @
4f59c951
import
React
from
'react'
import
React
from
'react'
import
{
connect
}
from
'react-redux'
import
{
increment
,
startClock
,
tickClock
}
from
'../actions'
import
{
increment
,
startClock
,
tickClock
}
from
'../actions'
import
{
withReduxSaga
}
from
'../store'
import
Page
from
'../components/page'
import
Page
from
'../components/page'
class
Counter
extends
React
.
Component
{
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
(
tickClock
(
isServer
))
store
.
dispatch
(
increment
())
store
.
dispatch
(
increment
())
return
{
isServer
}
}
}
componentDidMount
()
{
componentDidMount
()
{
...
@@ -19,4 +20,4 @@ class Counter extends React.Component {
...
@@ -19,4 +20,4 @@ class Counter extends React.Component {
}
}
}
}
export
default
withReduxSaga
(
Counter
)
export
default
connect
()
(
Counter
)
examples/with-redux-saga/store.js
View file @
4f59c951
import
{
createStore
,
applyMiddleware
}
from
'redux'
import
{
createStore
,
applyMiddleware
}
from
'redux'
import
withRedux
from
'next-redux-wrapper'
import
nextReduxSaga
from
'next-redux-saga'
import
createSagaMiddleware
from
'redux-saga'
import
createSagaMiddleware
from
'redux-saga'
import
rootReducer
,
{
exampleInitialState
}
from
'./reducer'
import
rootReducer
,
{
exampleInitialState
}
from
'./reducer'
import
rootSaga
from
'./saga'
import
rootSaga
from
'./saga'
...
@@ -23,10 +20,12 @@ export function configureStore (initialState = exampleInitialState) {
...
@@ -23,10 +20,12 @@ export function configureStore (initialState = exampleInitialState) {
bindMiddleware
([
sagaMiddleware
])
bindMiddleware
([
sagaMiddleware
])
)
)
store
.
sagaTask
=
sagaMiddleware
.
run
(
rootSaga
)
store
.
runSagaTask
=
()
=>
{
store
.
sagaTask
=
sagaMiddleware
.
run
(
rootSaga
)
}
store
.
runSagaTask
()
return
store
return
store
}
}
export
function
withReduxSaga
(
BaseComponent
)
{
export
default
configureStore
return
withRedux
(
configureStore
)(
nextReduxSaga
(
BaseComponent
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment