Skip to content

Commit

Permalink
Merge pull request #43 from risenforces/docs/update-test-app
Browse files Browse the repository at this point in the history
[Documentation] Update test app
  • Loading branch information
Evgeny Zakharov authored Apr 24, 2023
2 parents 5623c2e + 1c6b2cb commit 0503561
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 421 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ yarn add nextjs-effector @effector/next effector-react effector

## Usage

### Examples

- [Test App](/apps/test-app) - used for testing the `nestjs-effector` library. You can find some architecture notes in [README](/apps/test-app/README.md).

### Initial setup

First, add `effector/babel-plugin` to your `.babelrc`:
Expand Down
6 changes: 6 additions & 0 deletions apps/test-app/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ module.exports = configure({
presets.effector(),
presets.typescript(),
],

extend: {
rules: {
'effector/no-watch': 'off',
},
},
})
39 changes: 6 additions & 33 deletions apps/test-app/README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,11 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
## Architecture

## Getting Started
- `src/shared/events` - exports `appStarted` for global usage

First, run the development server:
- `src/layouts/factories` - exports GIP/GSP/GSSP factories. Uses `appStarted` from `src/shared/events`

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```
- `src/processes/*` - initiates application global logic. Uses `appStarted` from `src/shared/events`

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
- `src/pages/*` - declares pages views and models. Exports `pageStarted` for using with GIP/GSP/GSSP factories

You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
- `pages/*` - declares Next.js pages. Uses GIP/GSP/GSSP factories from `src/layouts/factories` to bind `appStarted` and `pageStarted` to page
1 change: 1 addition & 0 deletions apps/test-app/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@fontsource/acme'
import '@fontsource/fira-mono'
import '@app/shared/ui/globals.css'
import '@app/processes'
import App from 'next/app'
import { withEffector } from 'nextjs-effector'

Expand Down
4 changes: 2 additions & 2 deletions apps/test-app/pages/blog/[slug].tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { GetStaticPaths, NextPage } from 'next'
import { usePageEvent } from 'nextjs-effector'
import { createGSP } from '@app/layouts/factories'
import { BlogPostPage, pageStarted } from '@app/pages/blog-post'
import { createGSP } from '@app/pages/shared/bindings'
import { appStarted } from '@app/pages/shared/model'
import { localApi } from '@app/shared/api'
import { appStarted } from '@app/shared/events'

const Page: NextPage = () => {
console.info('[Render] BlogPostPage')
Expand Down
4 changes: 2 additions & 2 deletions apps/test-app/pages/blog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NextPage } from 'next'
import { usePageEvent } from 'nextjs-effector'
import { createGSP } from '@app/layouts/factories'
import { BlogPage, pageStarted } from '@app/pages/blog'
import { createGSP } from '@app/pages/shared/bindings'
import { appStarted } from '@app/pages/shared/model'
import { appStarted } from '@app/shared/events'

const Page: NextPage = () => {
console.info('[Render] BlogPage')
Expand Down
2 changes: 1 addition & 1 deletion apps/test-app/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NextPage } from 'next'
import { createGIP } from '@app/layouts/factories'
import { HomePage, pageStarted } from '@app/pages/home'
import { createGIP } from '@app/pages/shared'

const Page: NextPage = () => {
console.info('[Render] HomePage')
Expand Down
2 changes: 1 addition & 1 deletion apps/test-app/pages/profile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NextPage } from 'next'
import NextErrorPage from 'next/error'
import { createGIP } from '@app/layouts/factories'
import { MyProfilePage, pageStarted } from '@app/pages/my-profile'
import { $bio } from '@app/pages/my-profile/model'
import { createGIP } from '@app/pages/shared'

interface Props {
notFound?: boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createGIPFactory, createGSPFactory } from 'nextjs-effector'
import { appStarted } from './model'
import { appStarted } from '../shared/events'

export const createGIP = createGIPFactory({
sharedEvents: [appStarted],
Expand Down
1 change: 0 additions & 1 deletion apps/test-app/src/pages/shared/index.ts

This file was deleted.

11 changes: 0 additions & 11 deletions apps/test-app/src/pages/shared/model.ts

This file was deleted.

8 changes: 8 additions & 0 deletions apps/test-app/src/processes/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { sample } from 'effector'
import { loadAuthenticatedUser } from '../entities/authenticated-user'
import { appStarted } from '../shared/events'

sample({
clock: appStarted,
target: loadAuthenticatedUser,
})
1 change: 1 addition & 0 deletions apps/test-app/src/processes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './auth'
5 changes: 5 additions & 0 deletions apps/test-app/src/shared/events/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createEvent } from 'effector'

export const appStarted = createEvent()

appStarted.watch(() => console.info('[Event] appStarted'))
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
"react-dom": "^18.2.0",
"typescript": "^5.0.4",
"vite": "^4.3.1",
"vitest": "^0.30.1",
"zx": "^7.2.1"
"vitest": "^0.30.1"
},
"peerDependencies": {
"@effector/next": "^0.3.0",
Expand Down
Loading

1 comment on commit 0503561

@vercel
Copy link

@vercel vercel bot commented on 0503561 Apr 24, 2023

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:

nextjs-effector – ./

nextjs-effector-risen.vercel.app
nextjs-effector.vercel.app
nextjs-effector-git-main-risen.vercel.app

Please sign in to comment.