mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Lint examples (#4985)
* Lint examples/with-apollo-and-redux-saga * Lint examples/with-apollo-auth * Lint examples/with-apollo * Lint exampels/with-google-analytics * Lint examples/with-higher-order-component * Lint examples/with-react-i18next * Lint exampels/with-redux * Lint exampels/with-relay-modern * Lint examples/with-universal-configuration-runtime * Add **/examples/**/lib/** to linter
This commit is contained in:
parent
639df91c87
commit
5ff7c0742c
|
@ -3,7 +3,7 @@ export const actionTypes = {
|
||||||
TICK_CLOCK: 'TICK_CLOCK'
|
TICK_CLOCK: 'TICK_CLOCK'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function startClock(isServer=true) {
|
export function startClock (isServer = true) {
|
||||||
return {
|
return {
|
||||||
type: actionTypes.START_CLOCK,
|
type: actionTypes.START_CLOCK,
|
||||||
light: isServer,
|
light: isServer,
|
||||||
|
@ -11,7 +11,7 @@ export function startClock(isServer=true) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function tickClock(isServer) {
|
export function tickClock (isServer) {
|
||||||
return {
|
return {
|
||||||
type: actionTypes.TICK_CLOCK,
|
type: actionTypes.TICK_CLOCK,
|
||||||
light: !isServer,
|
light: !isServer,
|
||||||
|
|
|
@ -5,7 +5,7 @@ export const initialState = {
|
||||||
light: false
|
light: false
|
||||||
}
|
}
|
||||||
|
|
||||||
function reducer(state = initialState, action) {
|
function reducer (state = initialState, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case actionTypes.TICK_CLOCK:
|
case actionTypes.TICK_CLOCK:
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { actionTypes, tickClock } from './actions'
|
||||||
|
|
||||||
es6promise.polyfill()
|
es6promise.polyfill()
|
||||||
|
|
||||||
function* runClockSaga() {
|
function * runClockSaga () {
|
||||||
yield take(actionTypes.START_CLOCK)
|
yield take(actionTypes.START_CLOCK)
|
||||||
while (true) {
|
while (true) {
|
||||||
yield put(tickClock(false))
|
yield put(tickClock(false))
|
||||||
|
|
|
@ -3,10 +3,10 @@ export const actionTypes = {
|
||||||
COUNT_DECREASE: 'COUNT_DECREASE'
|
COUNT_DECREASE: 'COUNT_DECREASE'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function countIncrease() {
|
export function countIncrease () {
|
||||||
return { type: actionTypes.COUNT_INCREASE }
|
return { type: actionTypes.COUNT_INCREASE }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function countDecrease() {
|
export function countDecrease () {
|
||||||
return { type: actionTypes.COUNT_DECREASE }
|
return { type: actionTypes.COUNT_DECREASE }
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { actionTypes } from './actions'
|
||||||
|
|
||||||
const initialState = 0
|
const initialState = 0
|
||||||
|
|
||||||
function reducer(state = initialState, action) {
|
function reducer (state = initialState, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case actionTypes.COUNT_INCREASE:
|
case actionTypes.COUNT_INCREASE:
|
||||||
return state + 1
|
return state + 1
|
||||||
|
|
|
@ -10,7 +10,7 @@ if (!process.browser) {
|
||||||
global.fetch = fetch
|
global.fetch = fetch
|
||||||
}
|
}
|
||||||
|
|
||||||
function create(initialState) {
|
function create (initialState) {
|
||||||
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
|
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
|
||||||
return new ApolloClient({
|
return new ApolloClient({
|
||||||
connectToDevTools: process.browser,
|
connectToDevTools: process.browser,
|
||||||
|
@ -23,7 +23,7 @@ function create(initialState) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function initApollo(initialState) {
|
export default function initApollo (initialState) {
|
||||||
// Make sure to create a new client for every server-side request so that data
|
// Make sure to create a new client for every server-side request so that data
|
||||||
// isn't shared between connections (which would be bad)
|
// isn't shared between connections (which would be bad)
|
||||||
if (!process.browser) {
|
if (!process.browser) {
|
||||||
|
|
|
@ -4,18 +4,18 @@ export const actionTypes = {
|
||||||
LOAD_DATA_ERROR: 'LOAD_DATA_ERROR'
|
LOAD_DATA_ERROR: 'LOAD_DATA_ERROR'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadData() {
|
export function loadData () {
|
||||||
return { type: actionTypes.LOAD_DATA }
|
return { type: actionTypes.LOAD_DATA }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadDataSuccess(data) {
|
export function loadDataSuccess (data) {
|
||||||
return {
|
return {
|
||||||
type: actionTypes.LOAD_DATA_SUCCESS,
|
type: actionTypes.LOAD_DATA_SUCCESS,
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadDataError(error) {
|
export function loadDataError (error) {
|
||||||
return {
|
return {
|
||||||
type: actionTypes.LOAD_DATA_ERROR,
|
type: actionTypes.LOAD_DATA_ERROR,
|
||||||
error
|
error
|
||||||
|
|
|
@ -5,7 +5,7 @@ export const initialState = {
|
||||||
error: false
|
error: false
|
||||||
}
|
}
|
||||||
|
|
||||||
function reducer(state = initialState, action) {
|
function reducer (state = initialState, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case actionTypes.LOAD_DATA_SUCCESS:
|
case actionTypes.LOAD_DATA_SUCCESS:
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import { put, takeLatest } from 'redux-saga/effects'
|
import { put, takeLatest } from 'redux-saga/effects'
|
||||||
import es6promise from 'es6-promise'
|
import es6promise from 'es6-promise'
|
||||||
import 'isomorphic-unfetch'
|
import fetch from 'isomorphic-unfetch'
|
||||||
|
|
||||||
import { actionTypes, loadDataSuccess, loadDataError } from './actions'
|
import { actionTypes, loadDataSuccess, loadDataError } from './actions'
|
||||||
|
|
||||||
es6promise.polyfill()
|
es6promise.polyfill()
|
||||||
|
|
||||||
function* loadDataSaga() {
|
function * loadDataSaga () {
|
||||||
try {
|
try {
|
||||||
const res = yield fetch('https://jsonplaceholder.typicode.com/users')
|
const res = yield fetch('https://jsonplaceholder.typicode.com/users')
|
||||||
const data = yield res.json()
|
const data = yield res.json()
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { all } from 'redux-saga/effects'
|
||||||
import clock from './clock/sagas'
|
import clock from './clock/sagas'
|
||||||
import placeholder from './placeholder/sagas'
|
import placeholder from './placeholder/sagas'
|
||||||
|
|
||||||
function* rootSaga() {
|
function * rootSaga () {
|
||||||
yield all([clock, placeholder])
|
yield all([clock, placeholder])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import Head from 'next/head'
|
||||||
import initApollo from './initApollo'
|
import initApollo from './initApollo'
|
||||||
|
|
||||||
// Gets the display name of a JSX component for dev tools
|
// Gets the display name of a JSX component for dev tools
|
||||||
function getComponentDisplayName(Component) {
|
function getComponentDisplayName (Component) {
|
||||||
return Component.displayName || Component.name || 'Unknown'
|
return Component.displayName || Component.name || 'Unknown'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ export default ComposedComponent => {
|
||||||
serverState: PropTypes.object.isRequired
|
serverState: PropTypes.object.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getInitialProps(ctx) {
|
static async getInitialProps (ctx) {
|
||||||
// Initial serverState with apollo (empty)
|
// Initial serverState with apollo (empty)
|
||||||
let serverState = {
|
let serverState = {
|
||||||
apollo: {
|
apollo: {
|
||||||
|
@ -76,12 +76,12 @@ export default ComposedComponent => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor (props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.apollo = initApollo(props.serverState.apollo.data)
|
this.apollo = initApollo(props.serverState.apollo.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render () {
|
||||||
return (
|
return (
|
||||||
<ApolloProvider client={this.apollo}>
|
<ApolloProvider client={this.apollo}>
|
||||||
<ComposedComponent {...this.props} />
|
<ComposedComponent {...this.props} />
|
||||||
|
|
|
@ -10,7 +10,7 @@ import rootSaga from './rootSaga'
|
||||||
|
|
||||||
const sagaMiddleware = createSagaMiddleware()
|
const sagaMiddleware = createSagaMiddleware()
|
||||||
|
|
||||||
export function configureStore(initialState = {}) {
|
export function configureStore (initialState = {}) {
|
||||||
const store = createStore(
|
const store = createStore(
|
||||||
rootReducer,
|
rootReducer,
|
||||||
initialState,
|
initialState,
|
||||||
|
|
|
@ -10,7 +10,7 @@ if (!process.browser) {
|
||||||
global.fetch = fetch
|
global.fetch = fetch
|
||||||
}
|
}
|
||||||
|
|
||||||
function create(initialState) {
|
function create (initialState) {
|
||||||
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
|
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
|
||||||
return new ApolloClient({
|
return new ApolloClient({
|
||||||
connectToDevTools: process.browser,
|
connectToDevTools: process.browser,
|
||||||
|
@ -23,7 +23,7 @@ function create(initialState) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function initApollo(initialState) {
|
export default function initApollo (initialState) {
|
||||||
// Make sure to create a new client for every server-side request so that data
|
// Make sure to create a new client for every server-side request so that data
|
||||||
// isn't shared between connections (which would be bad)
|
// isn't shared between connections (which would be bad)
|
||||||
if (!process.browser) {
|
if (!process.browser) {
|
||||||
|
|
|
@ -41,4 +41,4 @@ export const addCount = () => dispatch => {
|
||||||
|
|
||||||
export const initStore = (initialState = exampleInitialState) => {
|
export const initStore = (initialState = exampleInitialState) => {
|
||||||
return createStore(reducer, initialState, composeWithDevTools(applyMiddleware(thunkMiddleware)))
|
return createStore(reducer, initialState, composeWithDevTools(applyMiddleware(thunkMiddleware)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import Head from 'next/head'
|
||||||
import initApollo from './initApollo'
|
import initApollo from './initApollo'
|
||||||
|
|
||||||
// Gets the display name of a JSX component for dev tools
|
// Gets the display name of a JSX component for dev tools
|
||||||
function getComponentDisplayName(Component) {
|
function getComponentDisplayName (Component) {
|
||||||
return Component.displayName || Component.name || 'Unknown'
|
return Component.displayName || Component.name || 'Unknown'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ export default ComposedComponent => {
|
||||||
serverState: PropTypes.object.isRequired
|
serverState: PropTypes.object.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getInitialProps(ctx) {
|
static async getInitialProps (ctx) {
|
||||||
// Initial serverState with apollo (empty)
|
// Initial serverState with apollo (empty)
|
||||||
let serverState = {
|
let serverState = {
|
||||||
apollo: {
|
apollo: {
|
||||||
|
@ -74,12 +74,12 @@ export default ComposedComponent => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor (props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.apollo = initApollo(this.props.serverState.apollo.data)
|
this.apollo = initApollo(this.props.serverState.apollo.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render () {
|
||||||
return (
|
return (
|
||||||
<ApolloProvider client={this.apollo}>
|
<ApolloProvider client={this.apollo}>
|
||||||
<ComposedComponent {...this.props} />
|
<ComposedComponent {...this.props} />
|
||||||
|
|
|
@ -6,7 +6,7 @@ import Head from 'next/head'
|
||||||
|
|
||||||
import initApollo from './initApollo'
|
import initApollo from './initApollo'
|
||||||
|
|
||||||
function parseCookies(req, options = {}) {
|
function parseCookies (req, options = {}) {
|
||||||
return cookie.parse(
|
return cookie.parse(
|
||||||
req ? req.headers.cookie || '' : document.cookie,
|
req ? req.headers.cookie || '' : document.cookie,
|
||||||
options
|
options
|
||||||
|
@ -20,7 +20,7 @@ export default App => {
|
||||||
apolloState: PropTypes.object.isRequired
|
apolloState: PropTypes.object.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getInitialProps(ctx) {
|
static async getInitialProps (ctx) {
|
||||||
const { Component, router, ctx: { req, res } } = ctx
|
const { Component, router, ctx: { req, res } } = ctx
|
||||||
const apollo = initApollo({}, {
|
const apollo = initApollo({}, {
|
||||||
getToken: () => parseCookies(req).token
|
getToken: () => parseCookies(req).token
|
||||||
|
@ -73,7 +73,7 @@ export default App => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor (props) {
|
||||||
super(props)
|
super(props)
|
||||||
// `getDataFromTree` renders the component first, the client is passed off as a property.
|
// `getDataFromTree` renders the component first, the client is passed off as a property.
|
||||||
// After that rendering is done using Next's normal rendering pipeline
|
// After that rendering is done using Next's normal rendering pipeline
|
||||||
|
@ -82,7 +82,7 @@ export default App => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render () {
|
||||||
return <App {...this.props} apolloClient={this.apolloClient} />
|
return <App {...this.props} apolloClient={this.apolloClient} />
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import { ApolloClient } from 'apollo-boost'
|
import { ApolloClient, InMemoryCache, HttpLink } from 'apollo-boost'
|
||||||
import { HttpLink } from 'apollo-boost'
|
|
||||||
import { InMemoryCache } from 'apollo-boost'
|
|
||||||
import fetch from 'isomorphic-unfetch'
|
import fetch from 'isomorphic-unfetch'
|
||||||
|
|
||||||
let apolloClient = null
|
let apolloClient = null
|
||||||
|
@ -10,7 +8,7 @@ if (!process.browser) {
|
||||||
global.fetch = fetch
|
global.fetch = fetch
|
||||||
}
|
}
|
||||||
|
|
||||||
function create(initialState) {
|
function create (initialState) {
|
||||||
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
|
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
|
||||||
return new ApolloClient({
|
return new ApolloClient({
|
||||||
connectToDevTools: process.browser,
|
connectToDevTools: process.browser,
|
||||||
|
@ -23,7 +21,7 @@ function create(initialState) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function initApollo(initialState) {
|
export default function initApollo (initialState) {
|
||||||
// Make sure to create a new client for every server-side request so that data
|
// Make sure to create a new client for every server-side request so that data
|
||||||
// isn't shared between connections (which would be bad)
|
// isn't shared between connections (which would be bad)
|
||||||
if (!process.browser) {
|
if (!process.browser) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import React from 'react'
|
||||||
import initApollo from './init-apollo'
|
import initApollo from './init-apollo'
|
||||||
import Head from 'next/head'
|
import Head from 'next/head'
|
||||||
import { getDataFromTree } from 'react-apollo'
|
import { getDataFromTree } from 'react-apollo'
|
||||||
|
|
|
@ -3,7 +3,7 @@ export const GA_TRACKING_ID = '<YOUR_GA_TRACKING_ID>'
|
||||||
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
|
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
|
||||||
export const pageview = url => {
|
export const pageview = url => {
|
||||||
window.gtag('config', GA_TRACKING_ID, {
|
window.gtag('config', GA_TRACKING_ID, {
|
||||||
page_location: url,
|
page_location: url
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,6 @@ export const event = ({ action, category, label, value }) => {
|
||||||
window.gtag('event', action, {
|
window.gtag('event', action, {
|
||||||
event_category: category,
|
event_category: category,
|
||||||
event_label: label,
|
event_label: label,
|
||||||
value: value,
|
value: value
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
export function getDisplayName(Component) {
|
export function getDisplayName (Component) {
|
||||||
return Component.displayName || Component.name || 'Unknown'
|
return Component.displayName || Component.name || 'Unknown'
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,12 +11,12 @@ export const withI18next = (namespaces = ['common']) => ComposedComponent => {
|
||||||
? await ComposedComponent.getInitialProps(ctx)
|
? await ComposedComponent.getInitialProps(ctx)
|
||||||
: {}
|
: {}
|
||||||
|
|
||||||
const i18nInitialProps = ctx.req
|
const i18nInitialProps = ctx.req
|
||||||
? getInitialProps(ctx.req, namespaces)
|
? getInitialProps(ctx.req, namespaces)
|
||||||
: await loadNamespaces({
|
: await loadNamespaces({
|
||||||
components: [{ props: { namespaces } }],
|
components: [{ props: { namespaces } }],
|
||||||
i18n: I18n,
|
i18n: I18n
|
||||||
});
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...composedInitialProps,
|
...composedInitialProps,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {initializeStore} from '../store'
|
||||||
const isServer = typeof window === 'undefined'
|
const isServer = typeof window === 'undefined'
|
||||||
const __NEXT_REDUX_STORE__ = '__NEXT_REDUX_STORE__'
|
const __NEXT_REDUX_STORE__ = '__NEXT_REDUX_STORE__'
|
||||||
|
|
||||||
function getOrCreateStore(initialState) {
|
function getOrCreateStore (initialState) {
|
||||||
// Always make a new store if server, otherwise state is shared between requests
|
// Always make a new store if server, otherwise state is shared between requests
|
||||||
if (isServer) {
|
if (isServer) {
|
||||||
return initializeStore(initialState)
|
return initializeStore(initialState)
|
||||||
|
@ -29,7 +29,7 @@ export default (App) => {
|
||||||
|
|
||||||
let appProps = {}
|
let appProps = {}
|
||||||
if (typeof App.getInitialProps === 'function') {
|
if (typeof App.getInitialProps === 'function') {
|
||||||
appProps = await App.getInitialProps.call(App, appContext)
|
appProps = await App.getInitialProps(appContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -38,12 +38,12 @@ export default (App) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor (props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.reduxStore = getOrCreateStore(props.initialReduxState)
|
this.reduxStore = getOrCreateStore(props.initialReduxState)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render () {
|
||||||
return <App {...this.props} reduxStore={this.reduxStore} />
|
return <App {...this.props} reduxStore={this.reduxStore} />
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ function fetchQuery (
|
||||||
operation,
|
operation,
|
||||||
variables,
|
variables,
|
||||||
cacheConfig,
|
cacheConfig,
|
||||||
uploadables,
|
uploadables
|
||||||
) {
|
) {
|
||||||
return fetch(process.env.RELAY_ENDPOINT, {
|
return fetch(process.env.RELAY_ENDPOINT, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
export default ('undefined' !== typeof window ? window.__ENV__ : process.env)
|
export default (typeof window !== 'undefined' ? window.__ENV__ : process.env)
|
||||||
|
|
|
@ -46,7 +46,6 @@
|
||||||
"parser": "babel-eslint",
|
"parser": "babel-eslint",
|
||||||
"ignore": [
|
"ignore": [
|
||||||
"**/node_modules/**",
|
"**/node_modules/**",
|
||||||
"**/examples/**/lib/**",
|
|
||||||
"**/examples/with-ioc/**",
|
"**/examples/with-ioc/**",
|
||||||
"**/examples/with-kea/**",
|
"**/examples/with-kea/**",
|
||||||
"**/examples/with-mobx/**",
|
"**/examples/with-mobx/**",
|
||||||
|
|
Loading…
Reference in a new issue