Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SeaJS TUI实践
Search
luolonghao
May 22, 2013
Technology
0
91
SeaJS TUI实践
luolonghao
May 22, 2013
Tweet
Share
More Decks by luolonghao
See All by luolonghao
About HRT and TPM
luolonghao
0
63
KindEditor 设计思路 V2
luolonghao
1
180
Other Decks in Technology
See All in Technology
60以上のプロダクトを持つ組織における開発者体験向上への取り組み - チームAPIとBackstageで構築する組織の可視化基盤 - / sre next 2025 Efforts to Improve Developer Experience in an Organization with Over 60 Products
vtryo
2
640
事例で学ぶ!B2B SaaSにおけるSREの実践例/SRE for B2B SaaS: A Real-World Case Study
bitkey
1
280
20250707-AI活用の個人差を埋めるチームづくり
shnjtk
6
4.1k
サイバーエージェントグループのSRE10年の歩みとAI時代の生存戦略
shotatsuge
4
730
助けて! XからWaylandに移行しないと新しいGNOMEが使えなくなっちゃう 2025-07-12
nobutomurata
2
130
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
54
22k
How to Quickly Call American Airlines®️ U.S. Customer Care : Full Guide
flyaahelpguide
0
240
【LT会登壇資料】TROCCO新コネクタ「スマレジ」を活用した直営店データの分析
kazari0425
1
140
american airlines®️ USA Contact Numbers: Complete 2025 Support Guide
supportflight
1
120
Copilot coding agentにベットしたいCTOが開発組織で取り組んだこと / GitHub Copilot coding agent in Team
tnir
0
130
SEQUENCE object comparison - db tech showcase 2025 LT2
nori_shinoda
0
270
DatabricksにOLTPデータベース『Lakebase』がやってきた!
inoutk
0
150
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.9k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Speed Design
sergeychernyshev
32
1k
The Pragmatic Product Professional
lauravandoore
35
6.7k
Adopting Sorbet at Scale
ufuk
77
9.5k
Designing Experiences People Love
moore
142
24k
GraphQLとの向き合い方2022年版
quramy
49
14k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
700
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
54k
Reflections from 52 weeks, 52 projects
jeffersonlam
351
21k
Thoughts on Productivity
jonyablonski
69
4.7k
Transcript
SeaJS + TUI实践 2012.10.08
SeaJS、CMD SeaJS:模块加载器 CMD:SeaJS的模块定义规范
入门代码(HTML) <!doctype html> <html> <head> <title>Hello</title> </head> <body> <script src=“http://js.tudouui.com/js/v3/seajs/sea.js"></script>
<script> seajs.config({ alias: { 'jquery‘ : ‘jquery/1.7.2/jquery.js‘, ‘hello’ : ’hello/dist/hello.js’ }, base : ‘http://js.tudouui.com/js/v3/’ }); seajs.use('/page/demo/dist/main.js'); </script> </body> </html>
入门代码(main.js) define(function(require, exports, module) { var Hello = require(‘hello'); new
Hello(); });
入门代码(hello.js) define(function(require, exports, module) { var $ = require('jquery'); function
Hello(){ this.render(); }; Hello.prototype.render = function(){ $('<h1>Hello SeaJS !</h1>').appendTo('body'); }; return Hello; });
目录结构 static/v3/ jquery/ 1.8.1/ json/ 1.0.2/ tui/ dist/ src/ tuilib/
dist/ src/ hello/ dist/ src/ page/ demo/ dist/ src/
改造老代码 • 用define(function(require) {…});包起来 • @import ./xxx.js改成require(‘./xxx’); • 用window暴露全局变量,或用exports返回 •
TUI.module.use(‘/fn/tuidefer’, fn)改成require.async(‘tuidefer’, fn) • TUI.convertTpl(‘./xxx.tpl‘, data)改成TUI.convertTpl(require(‘./xxx.tpl’), data)
这样做有什么好处? • 可在浏览器端加载依赖,这样页面可以直 接调用源代码,无需打包,对单元测试友 好 • 控制入口,可重写任何URL(比如,加时间 戳,用debug插件调试) • 与Node模块非常相近,很容易迁移
单元测试(V2) // stat.js,通过打包工具合并后才能调用 /** * @import fn/MRG32k3a.js * @import fn/global/common_stat.js
* @import fn/global/pv_stat.js * @import fn/global/expose_stat.js */ var ComboPvStat = { // some code }; ComboPvStat.send();
单元测试(V3) // stat.js,可以直接调用,无需打包 define(function(require, exports, module) { require('./MRG32k3a'); require('./common_stat'); require('./pv_stat');
require('./expose_stat'); var ComboPvStat = { // some code }; ComboPvStat.send(); });
调试(V2) 依赖本地代理(makeasy)
调试(V3) 本地运行HTTP服务,URL后加seajs-debug参数 // debug.js rules.push([ 'http://js.tudouui.com/js/v3/page/demo/dist', 'http://localhost/js/v3/page/demo/src' ]);
打包、压缩(V2)
打包、压缩(V3) // 安装SPM $ git clone https://github.com/seajs/spm.git $ cd spm
$ npm install –g // 打包、压缩 $ cd v3/hello $ spm build
参考文档 V3代码: trunk/static/js/v3 SeaJS:http://seajs.org/docs/#api CMD:https://github.com/seajs/seajs/issues/242 SPM:https://github.com/seajs/spm/wiki