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
7b8a4ea2
Commit
7b8a4ea2
authored
Jun 19, 2017
by
Henrik
Committed by
Arunoda Susiripala
Jun 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create displayName util (#2286)
parent
fe77397f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
6 deletions
+8
-6
dynamic.js
lib/dynamic.js
+2
-1
side-effect.js
lib/side-effect.js
+1
-4
utils.js
lib/utils.js
+5
-1
No files found.
lib/dynamic.js
View file @
7b8a4ea2
import
React
from
'react'
import
React
from
'react'
import
{
getDisplayName
}
from
'./utils'
let
currentChunks
=
new
Set
()
let
currentChunks
=
new
Set
()
...
@@ -55,7 +56,7 @@ export default function dynamicComponent (p, o) {
...
@@ -55,7 +56,7 @@ export default function dynamicComponent (p, o) {
loadComponent
()
{
loadComponent
()
{
promise
.
then
((
AsyncComponent
)
=>
{
promise
.
then
((
AsyncComponent
)
=>
{
// Set a readable displayName for the wrapper component
// Set a readable displayName for the wrapper component
const
asyncCompName
=
AsyncComponent
.
displayName
||
AsyncComponent
.
name
const
asyncCompName
=
getDisplayName
(
AsyncComponent
)
if
(
asyncCompName
)
{
if
(
asyncCompName
)
{
DynamicComponent
.
displayName
=
`DynamicComponent for
${
asyncCompName
}
`
DynamicComponent
.
displayName
=
`DynamicComponent for
${
asyncCompName
}
`
}
}
...
...
lib/side-effect.js
View file @
7b8a4ea2
import
React
,
{
Component
}
from
'react'
import
React
,
{
Component
}
from
'react'
import
{
getDisplayName
}
from
'./utils'
export
default
function
withSideEffect
(
reduceComponentsToState
,
handleStateChangeOnClient
,
mapStateOnServer
)
{
export
default
function
withSideEffect
(
reduceComponentsToState
,
handleStateChangeOnClient
,
mapStateOnServer
)
{
if
(
typeof
reduceComponentsToState
!==
'function'
)
{
if
(
typeof
reduceComponentsToState
!==
'function'
)
{
...
@@ -13,10 +14,6 @@ export default function withSideEffect (reduceComponentsToState, handleStateChan
...
@@ -13,10 +14,6 @@ export default function withSideEffect (reduceComponentsToState, handleStateChan
throw
new
Error
(
'Expected mapStateOnServer to either be undefined or a function.'
)
throw
new
Error
(
'Expected mapStateOnServer to either be undefined or a function.'
)
}
}
function
getDisplayName
(
WrappedComponent
)
{
return
WrappedComponent
.
displayName
||
WrappedComponent
.
name
||
'Component'
}
return
function
wrap
(
WrappedComponent
)
{
return
function
wrap
(
WrappedComponent
)
{
if
(
typeof
WrappedComponent
!==
'function'
)
{
if
(
typeof
WrappedComponent
!==
'function'
)
{
throw
new
Error
(
'Expected WrappedComponent to be a React component.'
)
throw
new
Error
(
'Expected WrappedComponent to be a React component.'
)
...
...
lib/utils.js
View file @
7b8a4ea2
...
@@ -42,12 +42,16 @@ export function printAndExit (message, code = 1) {
...
@@ -42,12 +42,16 @@ export function printAndExit (message, code = 1) {
process
.
exit
(
code
)
process
.
exit
(
code
)
}
}
export
function
getDisplayName
(
Component
)
{
return
Component
.
displayName
||
Component
.
name
||
'Unknown'
}
export
async
function
loadGetInitialProps
(
Component
,
ctx
)
{
export
async
function
loadGetInitialProps
(
Component
,
ctx
)
{
if
(
!
Component
.
getInitialProps
)
return
{}
if
(
!
Component
.
getInitialProps
)
return
{}
const
props
=
await
Component
.
getInitialProps
(
ctx
)
const
props
=
await
Component
.
getInitialProps
(
ctx
)
if
(
!
props
&&
(
!
ctx
.
res
||
!
ctx
.
res
.
finished
))
{
if
(
!
props
&&
(
!
ctx
.
res
||
!
ctx
.
res
.
finished
))
{
const
compName
=
Component
.
displayName
||
Component
.
name
const
compName
=
getDisplayName
(
Component
)
const
message
=
`"
${
compName
}
.getInitialProps()" should resolve to an object. But found "
${
props
}
" instead.`
const
message
=
`"
${
compName
}
.getInitialProps()" should resolve to an object. But found "
${
props
}
" instead.`
throw
new
Error
(
message
)
throw
new
Error
(
message
)
}
}
...
...
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