Skip to content

Commit

Permalink
Remove getPaused setPaused (#149)
Browse files Browse the repository at this point in the history
* Remove getPause setPause

* Add example
  • Loading branch information
Willy Brauner committed Nov 9, 2023
1 parent b9e93be commit 9eccbb8
Show file tree
Hide file tree
Showing 18 changed files with 2,019 additions and 2,438 deletions.
6 changes: 5 additions & 1 deletion .codesandbox/ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"buildCommand": "build",
"sandboxes": ["/examples/example-client", "/examples/example-ssr"],
"sandboxes": [
"/examples/example-client",
"/examples/example-ssr",
"/examples/example-history-block"
],
"node": "18"
}
15 changes: 15 additions & 0 deletions examples/example-history-block/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parser: "@typescript-eslint/parser",
plugins: ["react-refresh"],
rules: {
"react-refresh/only-export-components": ["warn", { allowConstantExport: true }],
},
}
24 changes: 24 additions & 0 deletions examples/example-history-block/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
27 changes: 27 additions & 0 deletions examples/example-history-block/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
13 changes: 13 additions & 0 deletions examples/example-history-block/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
29 changes: 29 additions & 0 deletions examples/example-history-block/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "example-history-block",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite --host",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@cher-ami/router": "^3.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vitejs/plugin-react-swc": "^3.3.2",
"eslint": "^8.45.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"typescript": "^5.0.2",
"vite": "^4.4.5"
}
}
1 change: 1 addition & 0 deletions examples/example-history-block/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
62 changes: 62 additions & 0 deletions examples/example-history-block/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Link, Stack, useRouter } from "@cher-ami/router"
import { useRef, useState } from "react"

export function App() {
const { history } = useRouter()
const unblockRef = useRef<any>()
const [isBlock, setIsBlock] = useState(false)

const crossedTransitions = ({
previousPage,
currentPage,
unmountPreviousPage,
}: any): Promise<void> =>
new Promise(async (resolve) => {
const $current = currentPage?.$element
if ($current) $current.style.visibility = "hidden"
if (previousPage) {
previousPage.playOut?.()
}
if (currentPage) {
if ($current) $current.style.visibility = "visible"
await currentPage.playIn?.()
unmountPreviousPage()
}
resolve()
})

return (
<div key={`${isBlock}`}>
<nav>
<Link to={"/a"}>A</Link>
<Link to={"/b"}>B</Link>
</nav>

<section>
<button
onClick={() => {
setIsBlock(true)
unblockRef.current = history!.block(() => {
console.log("blocked")
})
}}
>
block history
</button>
<br />
<button
onClick={() => {
setIsBlock(false)
unblockRef.current?.()
}}
>
unblock history
</button>
</section>

<div key={`${isBlock}`}>History is blocked: {isBlock ? "true" : "false"}</div>

<Stack manageTransitions={crossedTransitions} />
</div>
)
}
1 change: 1 addition & 0 deletions examples/example-history-block/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions examples/example-history-block/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}

body {
margin: 0;
font-size: 2rem;
}

button {
font-size: 2rem;
}
37 changes: 37 additions & 0 deletions examples/example-history-block/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import ReactDOM from "react-dom/client"
import { App } from "./App.tsx"
import "./index.css"
import { LangService, Router } from "@cher-ami/router"
import { createBrowserHistory } from "history"
import { forwardRef } from "react"

const base = "/base/"
type TLang = "en" | "fr" | "de"

const langService = new LangService<TLang>({
languages: [{ key: "en" }, { key: "fr" }, { key: "de" }],
showDefaultLangInUrl: false,
base,
})

const routesList = [
{
path: "/a",
component: forwardRef((_, ref: any) => <div ref={ref}>A</div>),
},
{
path: "/b",
component: forwardRef((_, ref: any) => <div ref={ref}>B</div>),
},
]

ReactDOM.createRoot(document.getElementById("root")!).render(
<Router
history={createBrowserHistory()}
langService={langService}
routes={routesList}
base={base}
>
<App />
</Router>,
)
1 change: 1 addition & 0 deletions examples/example-history-block/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
25 changes: 25 additions & 0 deletions examples/example-history-block/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
10 changes: 10 additions & 0 deletions examples/example-history-block/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
7 changes: 7 additions & 0 deletions examples/example-history-block/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react-swc"

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})
Loading

0 comments on commit 9eccbb8

Please sign in to comment.