Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

Commit

Permalink
Merge pull request #594 from ice-lab/release-next
Browse files Browse the repository at this point in the history
Release-rc.5
  • Loading branch information
ClarkXia authored Oct 27, 2022
2 parents 53fc7fe + cfad5df commit 24574fa
Show file tree
Hide file tree
Showing 139 changed files with 2,172 additions and 913 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ coverage
*.temp.json
*.swc

# yalc
.yalc
yalc.lock

# Packages
packages/*/lib/
packages/*/esm/
Expand Down
3 changes: 3 additions & 0 deletions examples/basic-project/src/components/PageUrl.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function PageUrl() {
return <span id="page-url">page url is {window.location.href}</span>;
}
5 changes: 3 additions & 2 deletions examples/basic-project/src/pages/about.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Link, useData, useConfig, history } from 'ice';
import type { RouteConfig } from 'ice';
import { isWeb } from '@uni/env';
import url from './ice.png';

Expand All @@ -8,7 +9,7 @@ interface Data {

export default function About() {
const data = useData<Data>();
const config = useConfig();
const config = useConfig<RouteConfig>();

console.log('render About', 'data', data, 'config', config);
console.log('history in component', history);
Expand All @@ -24,7 +25,7 @@ export default function About() {
);
}

export function getConfig() {
export function getConfig(): RouteConfig {
return {
title: 'About',
meta: [
Expand Down
6 changes: 3 additions & 3 deletions examples/basic-project/src/pages/blog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link, useData, useConfig } from 'ice';
import { Link, useData, useConfig, defineGetConfig } from 'ice';

export default function Blog() {
const data = useData();
Expand All @@ -14,9 +14,9 @@ export default function Blog() {
);
}

export function getConfig() {
export const getConfig = defineGetConfig(() => {
return {
title: 'Blog',
auth: ['guest'],
};
}
});
22 changes: 22 additions & 0 deletions examples/basic-project/src/pages/client-only.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { lazy, Suspense } from 'react';
import { ClientOnly as ClientOnlyComponent, useMounted } from 'ice';

export default function ClientOnly() {
const mounted = useMounted();

return (
<>
<div id="mounted">{mounted ? 'Client' : 'Server'}</div>
<ClientOnlyComponent>
{() => {
const PageUrl = lazy(() => import('@/components/PageUrl'));
return (
<Suspense>
<PageUrl />
</Suspense>
);
}}
</ClientOnlyComponent>
</>
);
}
16 changes: 15 additions & 1 deletion examples/basic-project/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Suspense, lazy } from 'react';
import { Link, useData, useAppData, useConfig } from 'ice';
import { Link, useData, useAppData, useConfig, ClientOnly, useMounted } from 'ice';
// not recommended but works
import { useAppContext } from '@ice/runtime';
import { useRequest } from 'ahooks';
Expand All @@ -16,6 +16,7 @@ export default function Home(props) {
const appData = useAppData<AppData>();
const data = useData();
const config = useConfig();
const mounted = useMounted();

if (typeof window !== 'undefined') {
console.log('render Home', props);
Expand All @@ -41,6 +42,19 @@ export default function Home(props) {
<div>userInfo: {JSON.stringify(userInfo)}</div>
<div>data from: <span id="data-from">{data.from}</span></div>
</div>
<p>
<div>{mounted ? 'Client' : 'Server'}</div>
<ClientOnly>
{() => {
const PageUrl = lazy(() => import('@/components/PageUrl'));
return (
<Suspense>
<PageUrl />
</Suspense>
);
}}
</ClientOnly>
</p>
</>
);
}
Expand Down
1 change: 1 addition & 0 deletions examples/miniapp-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@ice/app": "workspace:*",
"@ice/runtime": "workspace:*",
"@ice/plugin-miniapp": "workspace:*",
"@ice/miniapp-runtime": "workspace:*",
"ahooks": "^3.3.8",
"react": "^18.0.0",
"react-dom": "^18.0.0"
Expand Down
23 changes: 23 additions & 0 deletions examples/with-keep-alive/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# with-keep-alive

Experimental keep-alive with React 18 `<Offscreen />`.

## How to debug

First of all, publish the package to the yalc repo.

```bash
$ cd packages/ice && yalc publish --push

$ cd packages/runtime && yalc publish --push
```

Then, install the example dependencies.

```bash
$ cd examples/with-keep-alive && yarn install

$ yalc add @ice/app @ice/runtime

$ npm run start
```
3 changes: 3 additions & 0 deletions examples/with-keep-alive/ice.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineConfig } from '@ice/app';

export default defineConfig({});
18 changes: 18 additions & 0 deletions examples/with-keep-alive/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "with-keep-alive",
"version": "1.0.0",
"scripts": {
"start": "ice start",
"build": "ice build"
},
"dependencies": {
"@ice/runtime": "alpha",
"react": "experimental",
"react-dom": "experimental"
},
"devDependencies": {
"@ice/app": "alpha",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.2"
}
}
3 changes: 3 additions & 0 deletions examples/with-keep-alive/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineAppConfig } from 'ice';

export default defineAppConfig({});
12 changes: 12 additions & 0 deletions examples/with-keep-alive/src/components/Counter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useState } from 'react';

export default function Counter() {
const [count, setCount] = useState(0);

return (
<div>
count: {count}
<button onClick={() => setCount((count) => count + 1)}>add</button>
</div>
);
}
22 changes: 22 additions & 0 deletions examples/with-keep-alive/src/document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Meta, Title, Links, Main, Scripts } from 'ice';

function Document() {
return (
<html>
<head>
<meta charSet="utf-8" />
<meta name="description" content="ICE 3.0 Demo" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Title />
<Links />
</head>
<body>
<Main />
<Scripts />
</body>
</html>
);
}

export default Document;
20 changes: 20 additions & 0 deletions examples/with-keep-alive/src/pages/about/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Link } from 'ice';
import Counter from '@/components/Counter';

export default function About() {
return (
<>
<h3>About</h3>
<Counter />
<Link to="/">Home</Link>
<br />
<Link to="/about/me">About Me</Link>
</>
);
}

export function getConfig() {
return {
title: 'About',
};
}
10 changes: 10 additions & 0 deletions examples/with-keep-alive/src/pages/about/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Outlet } from 'ice';

export default function AboutLayout() {
return (
<>
<h2>About Layout </h2>
<Outlet />
</>
);
}
18 changes: 18 additions & 0 deletions examples/with-keep-alive/src/pages/about/me.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Link } from 'ice';

export default function About() {
return (
<>
<h3>About Me</h3>
<input />
<br />
<Link to="/about">About</Link>
</>
);
}

export function getConfig() {
return {
title: 'About Me',
};
}
18 changes: 18 additions & 0 deletions examples/with-keep-alive/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Link } from 'ice';
import Counter from '@/components/Counter';

export default function Home() {
return (
<main>
<h2>Home</h2>
<Counter />
<Link to="/about">About</Link>
</main>
);
}

export function getConfig() {
return {
title: 'Home',
};
}
10 changes: 10 additions & 0 deletions examples/with-keep-alive/src/pages/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { KeepAliveOutlet } from 'ice';

export default function Layout() {
return (
<>
<h1>I'm Keep Alive</h1>
<KeepAliveOutlet />
</>
);
}
32 changes: 32 additions & 0 deletions examples/with-keep-alive/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"compileOnSave": false,
"buildOnSave": false,
"compilerOptions": {
"baseUrl": ".",
"outDir": "build",
"module": "esnext",
"target": "es6",
"jsx": "react-jsx",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"lib": ["es6", "dom"],
"sourceMap": true,
"allowJs": true,
"rootDir": "./",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": false,
"importHelpers": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./src/*"],
"ice": [".ice"]
}
},
"include": ["src", ".ice", "ice.config.*"],
"exclude": ["build", "public"]
}
6 changes: 4 additions & 2 deletions examples/with-pha/src/pages/home.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { defineGetConfig } from 'ice';

export default function Home() {
return (
<>
Expand All @@ -6,7 +8,7 @@ export default function Home() {
);
}

export function getConfig() {
export const getConfig = defineGetConfig(() => {
return {
queryParamsPassKeys: [
'questionId',
Expand All @@ -15,4 +17,4 @@ export function getConfig() {
],
title: 'Home',
};
}
});
1 change: 1 addition & 0 deletions examples/with-plugin-request/ice.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineConfig } from '@ice/app';
import request from '@ice/plugin-request';

export default defineConfig({
dataLoader: false,
plugins: [
request(),
],
Expand Down
10 changes: 10 additions & 0 deletions examples/with-plugin-request/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { request as requestAPI } from 'ice';
import { defineRequestConfig } from '@ice/plugin-request/esm/types';

const requestConfig = {
// 可选的,全局设置 request 是否返回 response 对象,默认为 false
withFullResponse: false,
Expand Down Expand Up @@ -50,6 +52,14 @@ const requestConfig = {
},
};

export async function getAppData() {
try {
return await requestAPI('/user');
} catch (err) {
console.log('request error', err);
}
}

export default {
app: {
rootId: 'app',
Expand Down
3 changes: 2 additions & 1 deletion examples/with-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"devDependencies": {
"@ice/plugin-store": "workspace:*",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0"
"@types/react-dom": "^18.0.0",
"tslib": "^2.4.0"
}
}
Loading

0 comments on commit 24574fa

Please sign in to comment.