Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
feat(examples): add example for Next.js with RTK, refactor anothe…
Browse files Browse the repository at this point in the history
…r examples

This commit adds an example for `Next.js` with **enabled** static generation and `Redux Toolkit`.
  • Loading branch information
fostyfost committed Oct 18, 2021
1 parent 6f33681 commit 7e84d9b
Show file tree
Hide file tree
Showing 248 changed files with 6,391 additions and 275 deletions.
115 changes: 114 additions & 1 deletion .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
8 changes: 4 additions & 4 deletions examples/example-next-gip/eggs/active-post/action-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export enum ActivePostActionType {
LOAD_ACTIVE_POST = 'active-post-egg/LOAD_ACTIVE_POST',
SET_ACTIVE_POST = 'active-post-egg/SET_ACTIVE_POST',
SET_ERROR = 'active-post-egg/SET_ERROR',
SET_LOADING_STATE = 'active-post-egg/SET_LOADING_STATE',
LOAD_ACTIVE_POST = 'active-post/LOAD_ACTIVE_POST',
SET_ACTIVE_POST = 'active-post/SET_ACTIVE_POST',
SET_ERROR = 'active-post/SET_ERROR',
SET_LOADING_STATE = 'active-post/SET_LOADING_STATE',
}
4 changes: 2 additions & 2 deletions examples/example-next-gip/eggs/active-post/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { ActivePostActionType } from '@/eggs/active-post/action-types'
import type { ActivePostState } from '@/eggs/active-post/contracts/state'
import { ActivePostLoadingState } from '@/eggs/active-post/contracts/state'

export const ACTIVE_POST_REDUCER_KEY = 'active-post' as const

const initialState: ActivePostState = {
loadingState: ActivePostLoadingState.NEVER,
}

export const ACTIVE_POST_REDUCER_KEY = 'active-post' as const

export const activePostReducer = produce((draft: Draft<ActivePostState>, action: ActivePostActionsUnion): void => {
switch (action.type) {
case ActivePostActionType.SET_ERROR:
Expand Down
25 changes: 15 additions & 10 deletions examples/example-next-gip/eggs/active-post/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { ActivePostResponseItem } from '@/eggs/active-post/contracts/api-re
import { ActivePostLoadingState } from '@/eggs/active-post/contracts/state'
import { errorSelector } from '@/eggs/active-post/selectors'
import { fetchAsJson } from '@/utils/fetch-as-json'
import { getServerHost } from '@/utils/get-server-host'

function* loadActivePostWorker({ payload }: ReturnType<typeof ActivePostPublicAction.loadActivePost>) {
yield put(ActivePostReducerAction.setLoadingState(ActivePostLoadingState.LOADING))
Expand All @@ -19,18 +18,24 @@ function* loadActivePostWorker({ payload }: ReturnType<typeof ActivePostPublicAc
}

try {
const response: ActivePostResponseItem = yield call(
const responseItems: ActivePostResponseItem[] = yield call(
fetchAsJson,
typeof window === 'undefined' ? `${getServerHost()}/api/posts/${payload}` : `/api/posts/${payload}`,
'https://jsonplaceholder.typicode.com/posts',
)

yield put(
ActivePostReducerAction.setActivePost({
id: `${response.id}`,
title: response.title,
body: response.body,
}),
)
const post = responseItems.slice(0, 10).find(post => `${post.id}` === payload)

if (post) {
yield put(
ActivePostReducerAction.setActivePost({
id: `${post.id}`,
title: post.title,
body: post.body,
}),
)
} else {
yield put(ActivePostReducerAction.setError(`Post #${payload} not found`))
}
} catch (error: any) {
console.error('[Error in `loadActivePostWorker`]', error)
yield put(ActivePostReducerAction.setError(error.message))
Expand Down
12 changes: 6 additions & 6 deletions examples/example-next-gip/eggs/aviasales/action-types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export enum AviasalesActionType {
ADD_TICKETS = 'aviasales-egg/ADD_TICKETS',
ADD_TICKETS_SEGMENTS = 'aviasales-egg/ADD_TICKETS_SEGMENTS',
SET_LOADING_STATE = 'aviasales-egg/SET_LOADING_STATE',
SET_SEARCH_ID = 'aviasales-egg/SET_SEARCH_ID',
SET_CURRENT_SORT = 'aviasales-egg/SET_CURRENT_SORT',
SET_STOPS = 'aviasales-egg/SET_STOPS',
ADD_TICKETS = 'aviasales/ADD_TICKETS',
ADD_TICKETS_SEGMENTS = 'aviasales/ADD_TICKETS_SEGMENTS',
SET_LOADING_STATE = 'aviasales/SET_LOADING_STATE',
SET_SEARCH_ID = 'aviasales/SET_SEARCH_ID',
SET_CURRENT_SORT = 'aviasales/SET_CURRENT_SORT',
SET_STOPS = 'aviasales/SET_STOPS',
}
4 changes: 2 additions & 2 deletions examples/example-next-gip/eggs/aviasales/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import mitt from 'mitt'
export const AviasalesEventEmitter = mitt()

export enum AviasalesEvent {
GET_TICKETS = 'aviasales-egg/GET_TICKETS',
CHANGE_STOPS = 'aviasales-egg/CHANGE_STOPS',
GET_TICKETS = 'aviasales/GET_TICKETS',
CHANGE_STOPS = 'aviasales/CHANGE_STOPS',
}

export enum ChangeStopsMassive {
Expand Down
4 changes: 2 additions & 2 deletions examples/example-next-gip/eggs/aviasales/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { DEFAULT_SORT, DEFAULT_STOPS } from '@/eggs/aviasales/constants'
import { AviasalesLoadingState } from '@/eggs/aviasales/contracts/loading-state'
import type { AviasalesState } from '@/eggs/aviasales/contracts/state'

export const AVIASALES_REDUCER_KEY = 'aviasales' as const

const initialState: AviasalesState = {
tickets: {},
ticketsSegments: {},
Expand All @@ -15,8 +17,6 @@ const initialState: AviasalesState = {
stops: DEFAULT_STOPS,
}

export const AVIASALES_REDUCER_KEY = 'aviasales' as const

export const aviasalesReducer = produce((draft: Draft<AviasalesState>, action: AviasalesActionsUnion): void => {
switch (action.type) {
case AviasalesActionType.SET_SEARCH_ID:
Expand Down
8 changes: 4 additions & 4 deletions examples/example-next-gip/eggs/chuck-norris/action-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export enum ChuckNorrisActionType {
LOAD_JOKE = 'chuck-norris-egg/LOAD_JOKE',
SET_JOKE = 'chuck-norris-egg/SET_JOKE',
SET_ERROR = 'chuck-norris-egg/SET_ERROR',
SET_LOADING_STATE = 'chuck-norris-egg/SET_LOADING_STATE',
LOAD_JOKE = 'chuck-norris/LOAD_JOKE',
SET_JOKE = 'chuck-norris/SET_JOKE',
SET_ERROR = 'chuck-norris/SET_ERROR',
SET_LOADING_STATE = 'chuck-norris/SET_LOADING_STATE',
}
4 changes: 2 additions & 2 deletions examples/example-next-gip/eggs/chuck-norris/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { ChuckNorrisActionType } from '@/eggs/chuck-norris/action-types'
import type { ChuckNorrisState } from '@/eggs/chuck-norris/contracts/state'
import { ChuckNorrisLoadingState } from '@/eggs/chuck-norris/contracts/state'

export const CHUCK_NORRIS_REDUCER_KEY = 'chuck-norris' as const

const initialState: ChuckNorrisState = {
loadingState: ChuckNorrisLoadingState.NEVER,
}

export const CHUCK_NORRIS_REDUCER_KEY = 'chuck-norris' as const

export const chuckNorrisReducer = produce((draft: Draft<ChuckNorrisState>, action: ChuckNorrisActionsUnion): void => {
switch (action.type) {
case ChuckNorrisActionType.SET_ERROR:
Expand Down
4 changes: 2 additions & 2 deletions examples/example-next-gip/eggs/clock/action-creators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const ClockPublicAction = {
}

export const ClockReducerAction = {
tickClock() {
return createAction(ClockActionType.TICK_CLOCK, Date.now())
tickClock(payload: number) {
return createAction(ClockActionType.TICK_CLOCK, payload)
},
}

Expand Down
4 changes: 2 additions & 2 deletions examples/example-next-gip/eggs/clock/action-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum ClockActionType {
START_CLOCK = 'clock-egg/START_CLOCK',
TICK_CLOCK = 'clock-egg/TICK_CLOCK',
START_CLOCK = 'clock/START_CLOCK',
TICK_CLOCK = 'clock/TICK_CLOCK',
}
Loading

2 comments on commit 7e84d9b

@vercel
Copy link

@vercel vercel bot commented on 7e84d9b Oct 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

redux-eggs-example-next-gip – ./examples/example-next-gip

redux-eggs-example-next-gip-git-main-fostyfost.vercel.app
redux-eggs-example-next-gip-fostyfost.vercel.app
redux-eggs-example-next-gip.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 7e84d9b Oct 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

redux-eggs-example-next – ./examples/example-next

redux-eggs-example-next.vercel.app
redux-eggs-example-next-git-main-fostyfost.vercel.app
redux-eggs-example-next-fostyfost.vercel.app

Please sign in to comment.