Skip to content

Commit

Permalink
Merge pull request #4204 from alibaba/release-next
Browse files Browse the repository at this point in the history
  • Loading branch information
ClarkXia authored Apr 12, 2021
2 parents 78f51e8 + fb06b2f commit 5535141
Show file tree
Hide file tree
Showing 68 changed files with 2,473 additions and 2,483 deletions.
File renamed without changes.
5 changes: 5 additions & 0 deletions examples/basic-custom-store/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"store": {
"resetPageState": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "example-custom-app-store",
"description": "store management with icejs",
"dependencies": {
"ice.js": "^1.0.0",
"react": "^16.4.1",
"react-dom": "^16.4.1"
},
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ export default () => {

return (
<>
<h2>HOME</h2>
<h2>About</h2>

<div>
<button type="button" onClick={() => counterActions.increment()}>+</button>
<span>{counterState.count}</span>
<button type="button" onClick={() => counterActions.decrementAsync()}>-</button>
</div>

<Link to="/about">about</Link>
<Link to="/">home</Link>
</>
);
};
47 changes: 47 additions & 0 deletions examples/basic-custom-store/src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react';
import { Link } from 'ice';
import appStore from '../../store';
import store from './store';

export default () => {
const [counterState, counterActions] = appStore.useModel('counter');
const [todoState, todoActions] = store.useModel('todo');
let input;

return (
<>
<h2>HOME</h2>

<div style={{marginTop: 20}}>
<button type="button" onClick={() => counterActions.increment()}>+</button>
<span>{counterState.count}</span>
<button type="button" onClick={() => counterActions.decrementAsync()}>-</button>
</div>

<form
style={{marginTop: 20}}
onSubmit={e => {
e.preventDefault();
if (!input.value.trim()) {
return;
}
todoActions.add(input.value);
input.value = '';
}}>
<input ref={node => input = node} />
<button type="submit">
Add todo
</button>
</form>
<ul style={{marginTop: 20}}>
{
todoState.todos.map(todo => (
<li>{todo}</li>
))
}
</ul>

<Link to="/about">about</Link>
</>
);
};
10 changes: 10 additions & 0 deletions examples/basic-custom-store/src/pages/Home/models/todo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
state: {
todos: [],
},
reducers: {
add(prevState, payload) {
prevState.todos.push(payload);
}
}
};
10 changes: 10 additions & 0 deletions examples/basic-custom-store/src/pages/Home/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createStore } from 'ice';
import todo from './models/todo';

const models = {
todo
};

const store = createStore(models);

export default store;
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// import { lazy } from 'ice';

import Layout from '@/layouts/index';
import Home from '@/pages/Home';

// const Home = lazy(() => import('@/pages/Home'));
// const About =lazy(() => import('@/pages/About'));
// const NotFound = lazy(() => import('@/pages/NotFound'));
import About from '@/pages/About';

export default [
{
Expand All @@ -17,6 +12,11 @@ export default [
exact: true,
component: Home
},
{
path: '/about',
exact: true,
component: About
},
]
}
];
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions examples/basic-spa/src/routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lazy } from 'ice';
import { lazy, IRouterConfig } from 'ice';
import Layout from '@/layouts';
import wrapperPage from '@/components/WrapperPage';

Expand All @@ -7,7 +7,7 @@ const Home = lazy(() => import('@/pages/Home'));
const About = lazy(() => import('@/pages/About'));
const Notfound = lazy(() => import('@/pages/NotFound'));

export default [
const routes: IRouterConfig[] = [
{
path: '/',
component: Layout,
Expand Down Expand Up @@ -35,3 +35,5 @@ export default [
]
}
];

export default routes;
3 changes: 3 additions & 0 deletions examples/basic-store/build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"router": {
"lazy": false
},
"store": {
"resetPageState": true
},
"tsChecker": true
}
1 change: 0 additions & 1 deletion examples/basic-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "example-basic-store",
"description": "store management with icejs",
"dependencies": {
"ice.js": "^1.0.0",
"react": "^16.4.1",
"react-dom": "^16.4.1"
},
Expand Down
25 changes: 19 additions & 6 deletions examples/basic-store/src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,31 @@ import { store as pageStore } from 'ice/Home';

export default () => {
const [counterState, counterActions] = appStore.useModel('counter');
const [pageState] = pageStore.useModel('default');
const [titleState, titleAction] = pageStore.useModel('title');
const [appTitleState] = appStore.useModel('title');
let input;

return (
<>
<h2>{appTitleState.title}</h2>
<h2>{pageState.title}</h2>

<div>
<button type="button" onClick={counterActions.increment}>+</button>
<h2>{titleState.title}</h2>
<form onSubmit={e => {
e.preventDefault();
if (!input.value.trim()) {
return;
}
titleAction.update(input.value);
input.value = '';
}}>
<input ref={node => input = node} />
<button type="submit">
Update Title
</button>
</form>
<div style={{ marginTop: 30 }}>
<button type="button" id="increment" onClick={counterActions.increment}>+</button>
<span>{counterState.count}</span>
<button type="button" onClick={counterActions.decrementAsync}>-</button>
<button type="button" id="decrement" onClick={counterActions.decrementAsync}>-</button>
</div>

<Link to="/about">about</Link>
Expand Down
5 changes: 0 additions & 5 deletions examples/basic-store/src/pages/Home/model.ts

This file was deleted.

10 changes: 10 additions & 0 deletions examples/basic-store/src/pages/Home/models/title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
state: {
title: 'Home Page'
},
reducers: {
update(prevState, payload) {
return { title: payload };
},
}
};
4 changes: 4 additions & 0 deletions packages/build-user-config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.3.4

- [fix] remove deprecated api of esbuild-loader

## 0.3.3

- [feat] support resolve absolute cli options module path
Expand Down
4 changes: 2 additions & 2 deletions packages/build-user-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@builder/user-config",
"version": "0.3.3",
"version": "0.3.4",
"description": "Includes methods which are releated to set base user config for framework",
"homepage": "",
"license": "MIT",
Expand All @@ -15,7 +15,7 @@
"copy-webpack-plugin": "^5.0.4",
"core-js": "^3.3.1",
"debug": "^4.1.1",
"esbuild-loader": "^2.9.2",
"esbuild-loader": "^2.11.0",
"eslint-loader": "^4.0.0",
"eslint-reporting-webpack-plugin": "^0.1.0",
"fork-ts-checker-webpack-plugin": "^5.0.5",
Expand Down
2 changes: 0 additions & 2 deletions packages/build-user-config/src/userConfig/esbuild.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const {
ESBuildPlugin,
ESBuildMinifyPlugin
} = require('esbuild-loader');

Expand All @@ -16,6 +15,5 @@ module.exports = (config, options) => {
...defaultOptions,
...options,
}]);
config.plugin('ESBuildPlugin').use(ESBuildPlugin);
}
};
4 changes: 4 additions & 0 deletions packages/create-app-shared/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.2.3

- [fix] ts types of export apis

## 0.2.2

- [feat] compatible with cjs and esm when excute runtime module
2 changes: 1 addition & 1 deletion packages/create-app-shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-app-shared",
"version": "0.2.2",
"version": "0.2.3",
"description": "",
"author": "[email protected]",
"homepage": "https://github.com/alibaba/ice#readme",
Expand Down
3 changes: 2 additions & 1 deletion packages/create-app-shared/src/createBaseApp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { History } from 'history';
import RuntimeModule from './runtimeModule';
import { createHistory } from './history';
import { isMiniAppPlatform } from './env';
Expand All @@ -22,7 +23,7 @@ export default ({ loadRuntimeModules, createElement, initHistory = true }) => {
appConfig = deepmerge(DEFAULE_APP_CONFIG, appConfig);

// Set history
let history: any = {};
let history: History;
if (!isMiniAppPlatform && initHistory) {
const { router } = appConfig;
const { type, basename, history: customHistory } = router;
Expand Down
3 changes: 2 additions & 1 deletion packages/create-app-shared/src/emitLifeCycles.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { History } from 'history';
import { getHistory } from './history';
import router from './router';
import { LAUNCH, SHOW, HIDE } from './constants';
Expand All @@ -13,7 +14,7 @@ function emitLifeCycles() {
};
} else {
// Get history
const history = getHistory();
const history = getHistory() as History;
const pathname = history && history.location ?
history.location.pathname : typeof window !== 'undefined' && window.location.pathname;

Expand Down
10 changes: 9 additions & 1 deletion packages/create-app-shared/src/enhanceWithRouter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { RouteComponentProps, WithRouterStatics, WithRouterProps } from 'react-router';
import { isMiniAppPlatform } from './env';

function enhanceWithRouter({ withRouter, createElement }) {
// ref: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/ca5e189854d26c10bd5e9ba078ab33bd3749af43/types/react-router/index.d.ts#L172
export interface IWithRouter {
<P extends RouteComponentProps<any>, C extends React.ComponentType<P>>(
component: C & React.ComponentType<P>,
): React.ComponentClass<Omit<P, keyof RouteComponentProps<any>> & WithRouterProps<C>> & WithRouterStatics<C>;
}

function enhanceWithRouter({ withRouter, createElement }): IWithRouter {
if (isMiniAppPlatform) {
withRouter = function (Component) {
function Wrapper(props) {
Expand Down
27 changes: 20 additions & 7 deletions packages/create-app-shared/src/history.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import {
createBrowserHistory,
createHashHistory,
createMemoryHistory
createMemoryHistory,
History,
Location
} from 'history';
import { createMiniAppHistory } from 'miniapp-history';
import { isMiniAppPlatform, isWeex, isKraken } from './env';

// eslint-disable-next-line
let history;

function createHistory({ routes, customHistory, type, basename, location }: any) {
let history: History;
function createHistory({
routes,
customHistory,
type,
basename,
location
}: {
routes?: any[],
customHistory?: History,
type?: string,
basename?: string,
location?: Location
}) {
if (process.env.__IS_SERVER__) {
history = createMemoryHistory();
history.location = location;
Expand All @@ -25,9 +38,9 @@ function createHistory({ routes, customHistory, type, basename, location }: any)
} else if (type === 'browser') {
history = createBrowserHistory({ basename });
} else if (isMiniAppPlatform) {
(window as any).history = createMiniAppHistory(routes);
(window as any).history = createMiniAppHistory(routes) as History;
window.location = (window.history as any).location;
history = window.history;
history = (window as any).history;
} else {
history = createMemoryHistory();
}
Expand All @@ -36,7 +49,7 @@ function createHistory({ routes, customHistory, type, basename, location }: any)
}

function getHistory() {
return isMiniAppPlatform ? window.history : history;
return history;
}

export { getHistory, createHistory, history };
Loading

0 comments on commit 5535141

Please sign in to comment.