perfect the scaffolding
This commit is contained in:
parent
a64321863e
commit
138fc9d88e
|
@ -1,14 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
App.ES6TodoApp = Nuclear.create({
|
||||
add: function add(evt) {
|
||||
evt.preventDefault();
|
||||
this.option.items.push(this.textBox.value);
|
||||
},
|
||||
render: function render() {
|
||||
return "<div>\n <h3>ES6 Todo</h3>\n <ul> {{#items}} <li>{{.}}</li> {{/items}}</ul>\n <form onsubmit=\"add(event)\" >\n <input nc-id=\"textBox\" type=\"text\" />\n <button>Add #{{items.length}}</button>\n </form>\n </div>";
|
||||
},
|
||||
style: function style() {
|
||||
return "h3 { color:red; }\n button{ color:green;}";
|
||||
}
|
||||
});
|
|
@ -1,12 +0,0 @@
|
|||
App.componentRes['component/hello/index.html'] =
|
||||
'<div>Hello , {{name}} !</div>';
|
||||
|
||||
"use strict";
|
||||
|
||||
App.Util.loadFile("component/hello/index.html", function (tpl) {
|
||||
App.HelloMessage = Nuclear.create({
|
||||
render: function render() {
|
||||
return tpl;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,14 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
App.Timer = Nuclear.create({
|
||||
install: function install() {
|
||||
//react这里不需要加bind(this),会导致对javascript上下文的误解
|
||||
this.interval = setInterval(this.tick.bind(this), 1000);
|
||||
},
|
||||
tick: function tick() {
|
||||
this.option.secondsElapsed++;
|
||||
},
|
||||
render: function render() {
|
||||
return ' <div>Seconds Elapsed: {{secondsElapsed}}</div>';
|
||||
}
|
||||
});
|
|
@ -1,30 +0,0 @@
|
|||
App.componentRes['component/todo/index.html'] =
|
||||
'<div>\
|
||||
<h3>TODO</h3>\
|
||||
<ul> {{#items}} <li>{{.}}</li> {{/items}}</ul>\
|
||||
<form onsubmit="add(event)" >\
|
||||
<input nc-id="textBox" type="text" />\
|
||||
<button>Add #{{items.length}}</button>\
|
||||
</form>\
|
||||
</div>';
|
||||
|
||||
App.componentRes['component/todo/index.css'] =
|
||||
'h3 { color:red; }\
|
||||
button{ color:green;}';
|
||||
|
||||
"use strict";
|
||||
|
||||
App.Util.loadFile("component/todo/index.html", "component/todo/index.css", function (tpl, css) {
|
||||
App.TodoApp = Nuclear.create({
|
||||
add: function add(evt) {
|
||||
evt.preventDefault();
|
||||
this.option.items.push(this.textBox.value);
|
||||
},
|
||||
render: function render() {
|
||||
return tpl;
|
||||
},
|
||||
style: function style() {
|
||||
return css;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -11,11 +11,10 @@
|
|||
<div id="todoListContainer"></div>
|
||||
<script src="js/nuclear.js"></script>
|
||||
<script src="js/app.js"></script>
|
||||
<script src="js/util.js"></script>
|
||||
<script src="component/hello.js"></script>
|
||||
<script src="component/todo.js"></script>
|
||||
<script src="component/timer.js"></script>
|
||||
<script src="component/es6_test.js"></script>
|
||||
<script src="component/hello/index.js"></script>
|
||||
<script src="component/todo/index.js"></script>
|
||||
<script src="component/timer/index.js"></script>
|
||||
<script src="component/es6_test/index.js"></script>
|
||||
<script src="js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,3 +1,14 @@
|
|||
"use strict";
|
||||
var App = {};
|
||||
|
||||
var App = {};
|
||||
App.componentRes={};
|
||||
|
||||
App.getFileExt = function(filename) {
|
||||
var index1 = filename.lastIndexOf(".")
|
||||
var index2 = filename.length;
|
||||
return filename.substring(index1, index2).toLowerCase();
|
||||
}
|
||||
|
||||
App.loadFile = function (path) {
|
||||
return App.componentRes[path];
|
||||
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
App.Util={};
|
||||
App.componentRes={};
|
||||
|
||||
App.Util.getFileExt = function(filename) {
|
||||
var index1 = filename.lastIndexOf(".")
|
||||
var index2 = filename.length;
|
||||
return filename.substring(index1, index2).toLowerCase();
|
||||
}
|
||||
|
||||
App.Util.loadFile = function (tpl, css, callback) {
|
||||
if (arguments.length === 2) {
|
||||
css(App.componentRes[tpl]);
|
||||
} else {
|
||||
callback(App.componentRes[tpl],App.componentRes[css]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
var App = {};
|
||||
|
||||
App.componentRes={};
|
||||
|
||||
App.getFileExt = function(filename) {
|
||||
var index1 = filename.lastIndexOf(".")
|
||||
var index2 = filename.length;
|
||||
return filename.substring(index1, index2).toLowerCase();
|
||||
}
|
||||
|
||||
App.loadFile = function (path) {
|
||||
return App.componentRes[path];
|
||||
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
App.Util={};
|
||||
App.componentRes={};
|
||||
|
||||
App.Util.getFileExt = function(filename) {
|
||||
var index1 = filename.lastIndexOf(".")
|
||||
var index2 = filename.length;
|
||||
return filename.substring(index1, index2).toLowerCase();
|
||||
}
|
||||
|
||||
App.Util.loadFile = function (tpl, css, callback) {
|
||||
if (arguments.length === 2) {
|
||||
css(App.componentRes[tpl]);
|
||||
} else {
|
||||
callback(App.componentRes[tpl],App.componentRes[css]);
|
||||
}
|
||||
}
|
|
@ -29,8 +29,8 @@ gulp.task('readFile',function(callback) {
|
|||
}
|
||||
|
||||
contentArr.push( bc.transform(fs.readFileSync("src/component/"+key+"/index.js", "utf8"), { presets: ['es2015'] }) .code);
|
||||
file(key+".js", contentArr.join("") , { src: true })
|
||||
.pipe(gulp.dest('dev/component'))
|
||||
file("index.js", contentArr.join("") , { src: true })
|
||||
.pipe(gulp.dest('dev/component/'+key))
|
||||
|
||||
}
|
||||
callback();
|
||||
|
@ -38,11 +38,7 @@ gulp.task('readFile',function(callback) {
|
|||
})
|
||||
|
||||
gulp.task('copyHTML', function () {
|
||||
return gulp.src('src/*.html')
|
||||
.pipe(replace(/<script src="component\/(.*?)\/index.js"><\/script>/gm ,function(a,b,c){
|
||||
return '<script src="component\/'+b+'.js"><\/script>';
|
||||
}))
|
||||
.pipe(gulp.dest('dev'));
|
||||
return gulp.src('src/*.html').pipe(gulp.dest('dev'));
|
||||
});
|
||||
|
||||
gulp.task('copyJS', function () {
|
||||
|
@ -52,7 +48,7 @@ gulp.task('copyJS', function () {
|
|||
});
|
||||
|
||||
gulp.task('fixUtil', function () {
|
||||
return gulp.src('fix/util.js').pipe(gulp.dest('dev/js'));
|
||||
return gulp.src('fix/app.js').pipe(gulp.dest('dev/js'));
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
App.Util.loadFile("component/hello/index.html", function (tpl) {
|
||||
App.HelloMessage = Nuclear.create({
|
||||
render: function () {
|
||||
return tpl;
|
||||
}
|
||||
})
|
||||
|
||||
App.HelloMessage = Nuclear.create({
|
||||
render: function () {
|
||||
return App.loadFile("component/hello/index.html");
|
||||
}
|
||||
})
|
|
@ -1,15 +1,12 @@
|
|||
App.Util.loadFile("component/todo/index.html", "component/todo/index.css", function (tpl, css) {
|
||||
App.TodoApp = Nuclear.create({
|
||||
App.TodoApp = Nuclear.create({
|
||||
add: function (evt) {
|
||||
evt.preventDefault();
|
||||
this.option.items.push(this.textBox.value);
|
||||
},
|
||||
render: function () {
|
||||
return tpl;
|
||||
return App.loadFile('component/todo/index.html');
|
||||
},
|
||||
style: function () {
|
||||
return css;
|
||||
return App.loadFile('component/todo/index.css');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
|
@ -11,7 +11,6 @@
|
|||
<div id="todoListContainer"></div>
|
||||
<script src="js/nuclear.js"></script>
|
||||
<script src="js/app.js"></script>
|
||||
<script src="js/util.js"></script>
|
||||
<script src="component/hello/index.js"></script>
|
||||
<script src="component/todo/index.js"></script>
|
||||
<script src="component/timer/index.js"></script>
|
||||
|
|
|
@ -1 +1,15 @@
|
|||
var App = {};
|
||||
var App = {};
|
||||
|
||||
App.getFileExt = function(filename) {
|
||||
var index1 = filename.lastIndexOf(".")
|
||||
var index2 = filename.length;
|
||||
return filename.substring(index1, index2).toLowerCase();
|
||||
}
|
||||
|
||||
App.loadFile = function (path) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", path, false);
|
||||
xhr.send();
|
||||
return xhr.responseText;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
App.Util={};
|
||||
|
||||
App.Util.getFileExt = function(filename) {
|
||||
var index1 = filename.lastIndexOf(".")
|
||||
var index2 = filename.length;
|
||||
return filename.substring(index1, index2).toLowerCase();
|
||||
}
|
||||
|
||||
App.Util.loadFile = function (tpl, css, callback) {
|
||||
if (arguments.length === 2) {
|
||||
var tplHttp = new XMLHttpRequest();
|
||||
tplHttp.open("GET", tpl, false);
|
||||
tplHttp.send();
|
||||
css(tplHttp.responseText);
|
||||
} else {
|
||||
var tplHttp = new XMLHttpRequest();
|
||||
tplHttp.open("GET", tpl, false);
|
||||
tplHttp.send();
|
||||
|
||||
var cssHttp = new XMLHttpRequest();
|
||||
cssHttp.open("GET", css, false);
|
||||
cssHttp.send();
|
||||
|
||||
callback(tplHttp.responseText, cssHttp.responseText);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue