Skip to content

Commit b4cc0cf

Browse files
author
wenzhao.fw
committed
- update ReactRouter to 2.8.1
- update Reflux to 0.5.x - provide a dynamic routers and api proxy demo - ES6 & ESLint
1 parent 739f85c commit b4cc0cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+828
-327
lines changed

README.md

100644100755
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ This template is used by [nowa init](https://github.com/nowa-webpack/nowa-init).
66

77
## Usage
88

9-
```shell
9+
```
1010
nowa init https://github.com/nowa-webpack/template-uxcore/archive/master.zip
1111
```
12+
13+
## Changes
14+
15+
This version has made some big changes as below:
16+
17+
- ReactRouter
18+
ReactRouter has upgraded to v2.8.1. A huge SPA demo is provided.
19+
20+
- All code was written with ECMAScript2015
21+
22+
- Reflux
23+
[Reflux](https://github.com/reflux/refluxjs) is 0.5.x now. setState method in page is not worked and mixin is no longer used.

mod.js

100644100755
File mode changed.

mod/src/components/__name__/__Name__.js

100644100755
Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,32 @@
1-
require('./<%- Name %>.less');
2-
1+
import './<%- Name %>.less';
2+
<% if (i18n) { %>
3+
import i18n from 'i18n';
4+
<% } %>
5+
const {PureRenderMixin} = React.addons;
36
class <%- Name %> extends React.Component {
47

5-
constructor(props) {
6-
super(props);
7-
this.state = {
8-
};
9-
}
10-
11-
render() {
12-
let me = this;
13-
return (
14-
<div className="<%= name %>">
15-
component <%= name %>
16-
</div>
17-
);
18-
}
19-
20-
componentWillMount() {
21-
}
22-
23-
componentDidMount() {
24-
}
25-
26-
componentWillReceiveProps(nextProps) {
27-
}
8+
constructor(props) {
9+
super(props);
10+
this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
11+
}
12+
13+
render() {
14+
let me = this;
15+
return (
16+
<div className="mod-<%= name %>">
17+
component <%= name %>
18+
</div>
19+
);
20+
}
21+
}
2822

29-
shouldComponentUpdate(nextProps, nextState) {
30-
return true;
31-
}
3223

33-
componentWillUpdate(nextProps, nextState) {
34-
}
24+
<%- Name %>.defaultProps ={
3525

36-
componentDidUpdate(prevProps, prevState) {
37-
}
26+
}
3827

39-
componentWillUnmount() {
40-
}
28+
<%- Name %>.propTypes = {
29+
4130
}
4231

43-
module.exports = <%- Name %>;
32+
export default <%- Name %>;

mod/src/components/__name__/__Name__.less

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
.<%= name %> {
2-
background-color: #f60;
1+
.mod-<%= name %> {
2+
background-color: #f60;
33
}

mod/src/components/__name__/index.js

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('./<%- Name %>');
1+
export default from './<%- Name %>';

page.js

100644100755
Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,51 @@
11
// prompt for page
2-
exports.prompts = [
3-
{
2+
exports.prompts = [{
43
name: 'store',
54
type: 'confirm',
65
message: 'Generate store & actions?'
7-
}
8-
];
6+
}];
97

108
// answer for mod
119
exports.answers = function(answers, abc) {
12-
answers.name = answers.name.toLowerCase();
13-
answers.Name = answers.name.replace(/[\W_]+(.)/g, function(p, p1) {
14-
return p1.toUpperCase();
15-
}).replace(/^./, function(p) {
16-
return p.toUpperCase();
17-
});
18-
answers.libraries = !!abc.options.libraries;
19-
answers.suffix = suffixByVars(abc.options.vars, abc.options.buildvars);
20-
return answers;
10+
answers.name = answers.name.toLowerCase();
11+
answers.Name = answers.name.replace(/[\W_]+(.)/g, function(p, p1) {
12+
return p1.toUpperCase();
13+
}).replace(/^./, function(p) {
14+
return p.toUpperCase();
15+
});
16+
answers.i18n = !!abc.options.vars.locale;
17+
answers.libraries = !!abc.options.libraries;
18+
answers.suffix = suffixByVars(abc.options.vars, abc.options.buildvars);
19+
answers.SPA = !abc.options.pages;
20+
return answers;
2121
};
2222

2323
// filter out files
2424
exports.filter = function(source, data) {
25-
if (!data.store) {
26-
return !/(actions|store)\.js$/.test(source);
27-
}
25+
var flag = true;
26+
if(data.SPA) {
27+
flag = !/\.html$/.test(source);
28+
}
29+
if (flag !== false && !data.store) {
30+
flag = !/(actions|store)\.js$/.test(source);
31+
}
32+
return flag;
2833
};
2934

3035
// make filename suffix by vars
3136
function suffixByVars(vars, buildvars) {
32-
if (vars) {
33-
var suffix = '';
34-
for (var key in vars) {
35-
var value = vars[key];
37+
if (vars) {
38+
var suffix = '';
39+
for (var key in vars) {
40+
var value = vars[key];
3641

37-
// filename suffix will not contain `/`
38-
if (value !== undefined && buildvars && buildvars[key] && buildvars[key].length > 1) {
39-
suffix += '-' + value.toString().replace(/\//, '');
40-
}
42+
// filename suffix will not contain `/`
43+
if (value !== undefined && buildvars && buildvars[key] && buildvars[key].length > 1) {
44+
suffix += '-' + value.toString().replace(/\//, '');
45+
}
46+
}
47+
return suffix;
48+
} else {
49+
return '';
4150
}
42-
return suffix;
43-
} else {
44-
return '';
45-
}
4651
}

page/html/__name__.html

100644100755
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,29 @@
66

77
<!-- 外部样式资源加载 -->
88
<% if (libraries) { %>
9-
<link rel="stylesheet" href="//g.alicdn.com/??platform/common/s/1.1/global/global.css,uxcore/uxcore-kuma/2.0.14/orange.min.css">
9+
<link rel="stylesheet" href="//g.alicdn.com/??platform/common/s/1.1/global/global.css,uxcore/uxcore-kuma/2.0.15/orange.min.css">
1010
<% } else { %>
1111
<link rel="stylesheet" href="//g.alicdn.com/??platform/common/s/1.1/global/global.css">
1212
<% } %>
1313

1414
<!-- 项目样式资源加载 -->
1515
<link rel="stylesheet" href="/app.css">
16-
<link rel="stylesheet" href="/<%= name %>.css">
1716

1817
<!-- 外部脚本资源加载 -->
1918
<!--[if lte IE 9]>
2019
<script src="//g.alicdn.com/platform/c/??es5-shim/4.1.12/es5-shim.min.js,es5-shim/4.1.12/es5-sham.min.js,console-polyfill/0.2.1/index.min.js,respond.js/1.4.2/respond.min.js"></script>
2120
<![endif]-->
22-
<script src="//g.alicdn.com/platform/c/??jquery/1.11.3/dist/jquery.min.js,lodash/3.10.1/lodash.min.js,react/0.14.2/react-with-addons.min.js,react/0.14.2/react-dom.min.js,lie/3.0.2/dist/lie.polyfill.min.js,natty-db/1.0.2/dist/natty-db.pc.min.js,reflux/0.4.1/dist/reflux.min.js"></script>
21+
<script src="//g.alicdn.com/platform/c/??jquery/1.11.3/dist/jquery.min.js,lodash/3.10.1/lodash.min.js,react/0.14.2/react-with-addons.min.js,react/0.14.2/react-dom.min.js,lie/3.0.2/dist/lie.polyfill.min.js,natty-db/1.0.2/dist/natty-db.pc.min.js,reflux/0.5.0rc1/dist/reflux.min.js"></script>
2322
<!-- 使用 Uxcore.Mention 时,需要引入 rangy -->
2423
<!-- <script src="//g.alicdn.com/platform/c/rangy/1.3.0/rangy-core.min.js"></script> -->
2524
<!-- 使用 Uxcore.Tinymce 或 Uxcore.Form.EditorFormField 时,需要引入 tinymce -->
2625
<!-- <script src="//g.alicdn.com/platform/c/tinymce/4.3.12/tinymce.min.js"></script> -->
2726

28-
<% if (libraries) { %>
29-
<!-- 项目中订制的 uxcore -->
30-
<script src="/uxcore.js"></script>
27+
<% if (library) { %>
28+
<!-- 项目中订制的 uxcore -->
29+
<script src="/uxcore.js"></script>
30+
<% } else { %>
31+
<script src="//g.alicdn.com/uxcore/uxcore/0.1.5/uxcore.min.js"></script>
3132
<% } %>
3233

3334
</head>

page/src/pages/__name__/Page__Name__.js

100644100755
Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,50 @@
1-
require('./Page<%- Name %>.less');
2-
<% if (store) { %>
3-
const reactMixin = require('react-mixin');
1+
import './Page<%- Name %>.less';
42

5-
const Actions = require('./actions');
6-
const Store = require('./store');
3+
import classnames from 'classnames';
4+
<% if (i18n) { %>
5+
import i18n from 'i18n';
76
<% } %>
8-
class <%- Name %> extends React.Component {
9-
10-
constructor(props) {
11-
super(props);
12-
this.state = {
13-
};
14-
}
15-
16-
render() {
17-
return (
18-
<div className="<%= name %>">
19-
page <%= name %>
20-
</div>
21-
);
22-
}
23-
24-
componentWillMount() {
25-
}
26-
27-
componentDidMount() {
28-
}
29-
30-
componentWillReceiveProps(nextProps) {
31-
}
7+
<% if (store) { %>
8+
import Actions from './actions';
9+
import Store from './store';
3210

33-
shouldComponentUpdate(nextProps, nextState) {
34-
return true;
35-
}
11+
class Page<%- Name %> extends Reflux.Component {
3612

37-
componentWillUpdate(nextProps, nextState) {
38-
}
13+
constructor(props) {
14+
super(props);
15+
this.store = Store;
16+
}
3917

40-
componentDidUpdate(prevProps, prevState) {
41-
}
18+
render() {
19+
return (
20+
<div className="page-<%= name %>">
21+
page <%= name %>
22+
</div>
23+
);
24+
}
4225

43-
componentWillUnmount() {
44-
}
4526
}
46-
<% if (store) { %>
47-
reactMixin.onClass(<%- Name %>, Reflux.connect(Store, '<%- Name %>'));
27+
<% } else { %>
28+
class Page<%- Name %> extends React.Component {
29+
30+
constructor(props) {
31+
super(props);
32+
this.state = {};
33+
}
34+
35+
render() {
36+
return (
37+
<div className="page-<%= name %>">
38+
page <%= name %>
39+
</div>
40+
);
41+
}
42+
}
43+
4844
<% } %>
49-
ReactDOM.render(<<%- Name %>/>, document.getElementById('App'));
5045

51-
module.exports = <%- Name %>;
46+
<% if(SPA){ %>
47+
export default ReactRouter.withRouter(Page<%- Name %>);
48+
<% } else {%>
49+
export default Page<%- Name %>;
50+
<% } %>

page/src/pages/__name__/Page__Name__.less

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
.<%= name %> {
2-
background-color: #fff;
1+
.page-<%= name %> {
2+
background-color: #fff;
33
}

page/src/pages/__name__/actions.js

100644100755
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
module.exports = Reflux.createActions([
2-
'fetch'
3-
]);
1+
import DB from '../../app/db';
2+
3+
const Actions = Reflux.createActions({
4+
updateState: {},
5+
search: {
6+
asyncResult: true,
7+
},
8+
});
9+
10+
Actions.updateState.listen((params) => {
11+
12+
});
13+
14+
Actions.search.listenAndPromise((params) => {
15+
const getSomeInfo = DB.SomeModuleAPI.getSomeInfo(params);
16+
return getSomeInfo;
17+
});
18+
19+
export default Actions;

page/src/pages/__name__/index.js

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require('./Page<%- Name %>');
1+
export default from './Page<%- Name %>';

page/src/pages/__name__/store.js

100644100755
Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
const Actions = require('./actions');
1+
import Actions from './actions';
22

3-
const DB = require('../../app/db');
3+
export default class <%- Name %>Store extends Reflux.Store {
4+
constructor() {
5+
super();
6+
this.listenables = Actions;
7+
this.state = {};
8+
}
49

5-
module.exports = Reflux.createStore({
6-
listenables: [Actions],
7-
data: {
8-
loaded: false
9-
},
10+
onUpdateState(obj) {
11+
this.setState(obj);
12+
}
1013

11-
onFetch: function(params, cb) {
12-
let t = this;
13-
t.data.loaded = true;
14-
t.updateComponent();
15-
cb && cb(t.data);
16-
},
14+
onSearch(content) {
15+
}
1716

18-
updateComponent: function() {
19-
this.trigger(this.data);
20-
},
17+
onSearchCompleted(content) {
18+
this.setState({ content });
19+
}
2120

22-
getInitialState: function() {
23-
return this.data;
24-
}
25-
});
21+
onSearchFailed(error) {
22+
this.setState({ error });
23+
}
24+
25+
static get id() {
26+
return '<%- Name %>Store'
27+
}
28+
}

0 commit comments

Comments
 (0)