FRONT-END SKILLS
中间件定制平台
“中间件定制平台”项目中用到的SKILLS
前端工程
1,纯静态的前台工程,不依赖web server,可独立工程、独立开发
2、开发过程使用JSON file/MockJS,通过配置切换Angular Service数据源
1 2 3 4 5
|
window.__service.factory('templateRES',function($resource) { var url = framework.getFinalURL('api/template/:method/1','../template/api/:method.json'); var json = $resource(url,{}); return json; });
|
3、使用AngularJS,构建完善的前端MVC,简单高效的实现业务逻辑
4-2、组件的封装和组织
4-3、组件的HTML化使用
4-4、组件的MVC化控制
后端工程
1、Sequelize实现ORM,简化数据库开发工作量
1 2 3 4 5 6 7 8 9 10
|
module.exports = function (sequelize, DataTypes) { var WebSite = sequelize.define('Website', { name: DataTypes.STRING, status: DataTypes.INTEGER }, { tableName: 'bf_website', timestamps: false }); return WebSite; }
|
1-2、Sequelize的Models
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
function (_) { _ = _ || {}; this.id = _.id || 0; this.status = _.status || 0; this.name = _.name || ''; } Website.findById = function (callback) { Website.find({ where: {'id': this.id } } ).complete(function (err, obj) { callback(err, obj); }); }; Website.prototype.save = function(callback) { Website.create(this).complete(function (err, obj) { callback(err, obj); }); }; module.exports = Website;
|
2、使用LinqJS,进一步简化ORM对象的操作
1 2 3 4 5 6 7 8
|
var Enumerable = require('linq'); var xpath = Enumerable.from(xpathArr) .select(function(xpath){ if(xpath.name == inputs.xpath.name){ xpath = 'new value'; } return xpath; }).toArray();
|
3、使用ThenJS,直观管理数据库的多表操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
then(function(defer){ WebsiteDomain.del(inputs.ids , defer); }) .then(function(defer, value){ Xpath.delByDomainId(inputs.ids, defer); }) .all(function (defer, err) { if(!err){ callback(null, { code: '00',message: 'success.' }); } }). fail(function (defer, err) { callback(null, { code: '01',message: err }); });
|
4、自行开发的API系统(Model Proxy?),使NodeJS后端服务化,直接向前端开放业务接口
4-2、API的调用
实践中的全端开发技术家族
原文:大专栏 前后端分离(二)淘宝基于NODEJS的前后端分离