Skip to content

Commit

Permalink
Merge pull request #3569 from alibaba/release-next
Browse files Browse the repository at this point in the history
Release 1.9.6
  • Loading branch information
luhc228 authored Sep 25, 2020
2 parents 0778360 + d1be342 commit 3d7afe0
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/basic-store/src/pages/About/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { Link, store as appStore } from 'ice';
import { Link, store as appStore } from 'ice';
import { store as pageStore } from 'ice/About';

const About = (props) => {
Expand Down
23 changes: 23 additions & 0 deletions examples/basic-store/src/pages/Detail/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import { store } from 'ice/Detail';

class Detail extends React.Component {
constructor(props) {
super(props);
console.log(this.props);
}

public render() {
const { default: detailStore } = this.props as any;
const [state, dispatcher] = detailStore;
return (
<>
<div>Detail Page</div>
<div>Title: {state.title}</div>
<button onClick={() => dispatcher.updateDetailTitle('test')} type="button">Change Title</button>
</>
);
}
}

export default store.withModel('default')(Detail);
26 changes: 26 additions & 0 deletions examples/basic-store/src/pages/Detail/model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const delay = (time) => new Promise((resolve) => setTimeout(() => resolve(), time));


export default {
state: {
title: 'detail'
},

reducers: {
update(prevState, payload) {
return {
...prevState,
...payload,
};
},
},

effects: (dispatch) => ({
async updateDetailTitle(title: string) {
await delay(1000);
dispatch.default.update({
title
});
},
}),
};
5 changes: 5 additions & 0 deletions examples/basic-store/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import Layout from '@/layouts/index';
import Home from '@/pages/Home';
import About from '@/pages/About';
import Detail from '@/pages/Detail';
import { NotFound } from '@/pages/NotFound';
import Index from '@/pages/Index';

Expand All @@ -25,6 +26,10 @@ export default [
path: '/about',
component: About
},
{
path: '/detail',
component: Detail
},
{
path: '/index',
component: Index
Expand Down
4 changes: 2 additions & 2 deletions packages/icejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ice.js",
"version": "1.9.5",
"version": "1.9.6",
"description": "command line interface and builtin plugin for icejs",
"author": "[email protected]",
"homepage": "",
Expand Down Expand Up @@ -33,7 +33,7 @@
"build-plugin-ice-request": "1.7.2",
"build-plugin-ice-router": "1.7.3",
"build-plugin-ice-ssr": "1.7.3",
"build-plugin-ice-store": "1.7.2",
"build-plugin-ice-store": "1.7.3",
"build-plugin-react-app": "1.7.6",
"build-plugin-miniapp": "0.1.5",
"create-cli-utils": "0.1.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-store/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "build-plugin-ice-store",
"version": "1.7.2",
"version": "1.7.3",
"description": "builtin `icestore` in icejs",
"author": "[email protected]",
"homepage": "",
Expand Down
23 changes: 20 additions & 3 deletions packages/plugin-store/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default class Generator {
const pageComponentName = `Page${pageName}`;
const pageComponentRenderData = {
isRax: this.isRax,
pageComponentImport: `import ${pageComponentName} from '${pageComponentSourcePath}'` ,
pageComponentImport: `import ${pageComponentName} from '${pageComponentSourcePath}'`,
pageComponentExport: pageComponentName,
hasPageStore: false,
pageStoreImport: existedStoreFile ? `import store from '${pageStoreFile}'` : 'import store from \'./store\''
Expand All @@ -156,12 +156,26 @@ export default class Generator {
pageComponentRenderData.hasPageStore = true;
}

this.renderFile(pageComponentTemplatePath, pageComponentTargetPath , pageComponentRenderData);
this.renderFile(pageComponentTemplatePath, pageComponentTargetPath, pageComponentRenderData);
}

private renderPageIndex(params) {
const { pageName, pageModelsDir, pageModelFile } = params;
const pageIndexTemplatePath = path.join(__dirname, './template/pageIndex.ts.ejs');
const pageComponentTargetPath = path.join(this.targetPath, 'pages', pageName, 'index.ts');

const existStore = fse.pathExistsSync(pageModelsDir) || fse.pathExistsSync(pageModelFile);
const pageComponentRenderData = {
pageImports: existStore ? 'import store from \'./store\'' : '',
pageExports: existStore ? ' store ' : ''
};

this.renderFile(pageIndexTemplatePath, pageComponentTargetPath, pageComponentRenderData);
}

private renderFile(templatePath: string, targetPath: string, extraData = {}) {
const templateContent = fse.readFileSync(templatePath, 'utf-8');
let content = ejs.render(templateContent, {...extraData});
let content = ejs.render(templateContent, { ...extraData });
try {
content = prettier.format(content, {
parser: 'typescript',
Expand Down Expand Up @@ -199,6 +213,9 @@ export default class Generator {

// generate .ice/pages/${pageName}/${pageName}.tsx
this.renderPageComponent(params);

// generate .ice/pages/${pageName}/index.ts
this.renderPageIndex(params);
});
}
}
3 changes: 2 additions & 1 deletion packages/plugin-store/src/template/pageComponent.tsx.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
<% } else { %>
import * as React from 'react';
<% } %>
<%- pageComponentImport %>

<% if(hasPageStore) { %>
<%- pageStoreImport %>
<% } %>

<%- pageComponentImport %>

const PageComponentName = <%= pageComponentExport %>;

<% if(hasPageStore) { %>
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin-store/src/template/pageIndex.ts.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%- pageImports %>

export {
<%= pageExports %>
}
4 changes: 2 additions & 2 deletions packages/rax-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rax-app",
"version": "3.0.0-7",
"version": "3.0.0-8",
"description": "command line interface and builtin plugin for rax app",
"author": "[email protected]",
"homepage": "https://github.com/alibaba/ice#readme",
Expand All @@ -16,7 +16,7 @@
"dependencies": {
"@alib/build-scripts": "^0.1.24",
"build-plugin-app-core": "0.1.15",
"build-plugin-ice-store": "1.7.2",
"build-plugin-ice-store": "1.7.3",
"build-plugin-rax-app": "5.2.6",
"chokidar": "^3.3.1",
"commander": "^5.0.0",
Expand Down

0 comments on commit 3d7afe0

Please sign in to comment.