锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
I/O
dojo.io.blind浠嬬粛
鍦ㄦ垜浠埗浣渄ojo鐨勬椂鍊欙紝鐩殑鏄鐢ㄦ埛鍜屽紑鍙戣呴兘鑳戒韓鍙楀埌DHTML紼嬪簭銆傚湪寰堝鏈嬪弸鐨勬敮鎸佷笅錛岀壒鍒槸Aaron
Boodman鍜孧ark Anderson錛屾垜浠凡緇忔壘鍒頒簡(jiǎn)瑙e喅鍙敤鎬х殑鏂規(guī)硶銆傛垜浠彁渚涗簡(jiǎn)涓涓崟鐙殑鏄撶敤鐨凙PI鍜屼竴涓寘瑁呯被錛岃繖涓被鍙渶瑕佷袱涓枃浠躲俤ojo.io鍖呮彁渚涗簡(jiǎn)瀵筙MLHTTP鍜屼竴浜涘叾浠栨洿澶嶆潅鐨勪紶杈撶粨鏋勭殑鏀寔銆?br />
鍦╠ojo.io鍖呬腑鎴戜滑涓鑸渶甯鎬嬌鐢ㄧ殑鏄痙ojo.io.bind()鏂規(guī)硶銆俤ojo.io.blind()鏄竴涓爣鍑嗙殑寮傛鐨勮姹侫PI錛屽畠鍖呭惈浜?jiǎn)鍚効U嶄紶杈撳眰錛坱ransport layers錛夛紝鍖呮嫭queues of iFrames,XMLHTTP,mod_pubsub,LivePage絳夌瓑銆侱ojo浼?xì)璇曞浘湄?fù)褰撳墠鐨勮姹傞夋嫨鏈鍚堥傜殑浼犺緭鏂規(guī)硶錛屽洜涓哄湪鍋氱綉绔欐椂涓鑸笉浼?xì)鋴社敤鍒板叾浠栦紶杈撳Q屾墍浠ユ垜浠彧鐢ㄥ埌XMLHTTP銆俤ojo鎺ュ彈涓涓尶鍚嶇殑綾伙紝浣嗘槸鍦ㄧ煡閬撹繖涓被鐨勫睘鎬х殑鎯呭喌涓嬶紝鎶婂畠浣滀負(fù)鏂規(guī)硶鍙傛暟錛坒unction argument錛夈備笅闈㈢殑浠g爜鏄垱寤轟竴涓姹傦紙request錛夛紝榪欎釜璇鋒眰浼?xì)浠嶶RL榪斿洖鍘熷鐨勫瓧絎︿覆銆?br />
聽(tīng)聽(tīng)聽(tīng)聽(tīng)url:聽(tīng)"http://foo.bar.com/sampleData.txt",
聽(tīng)聽(tīng)聽(tīng)聽(tīng)load:聽(tīng)function(type,聽(tīng)data,聽(tīng)evt){聽(tīng)/*do聽(tīng)something聽(tīng)w/聽(tīng)the聽(tīng)data聽(tīng)*/聽(tīng)},
聽(tīng)聽(tīng)聽(tīng)聽(tīng)mimetype:聽(tīng)"text/plain"
});
榪欏氨鏄叏閮紝浣犳彁渚涗簡(jiǎn)涓涓暟鎹湴鍧錛岃繕鏈変竴涓綋浣犲緱鍒拌繑鍥炲兼椂瑕佹墽琛岀殑function銆備絾鏄鏋滃湪璇鋒眰榪囩▼涓嚭閿欎簡(jiǎn)鎬庝箞鍔炲憿錛熸垜浠啀鏉ュ垱寤轟竴涓猺egister鏉ヨВ鍐籌細(xì)
聽(tīng)聽(tīng)聽(tīng)聽(tīng)url:聽(tīng)"http://foo.bar.com/sampleData.txt",
聽(tīng)聽(tīng)聽(tīng)聽(tīng)load:聽(tīng)function(type,聽(tīng)data,聽(tīng)evt){聽(tīng)/*do聽(tīng)something聽(tīng)w/聽(tīng)the聽(tīng)data聽(tīng)*/聽(tīng)},
聽(tīng)聽(tīng)聽(tīng)聽(tīng)error:聽(tīng)function(type,聽(tīng)error){聽(tīng)/*do聽(tīng)something聽(tīng)w/聽(tīng)the聽(tīng)error*/聽(tīng)},
聽(tīng)聽(tīng)聽(tīng)聽(tīng)mimetype:聽(tīng)"text/plain"
});
鍚屾牱涔熷彲浠ュ彧鍒涘緩涓涓崟鐙殑handler鏉ヨВ鍐籌細(xì)
聽(tīng)聽(tīng)聽(tīng)聽(tīng)url:聽(tīng)"http://foo.bar.com/sampleData.txt",
聽(tīng)聽(tīng)聽(tīng)聽(tīng)handle:聽(tīng)function(type,聽(tīng)data,聽(tīng)evt){
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)if(type聽(tīng)==聽(tīng)"load"){
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)//聽(tīng)do聽(tīng)something聽(tīng)with聽(tīng)the聽(tīng)data聽(tīng)object
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)}else聽(tīng)if(type聽(tīng)==聽(tīng)"error"){
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)//聽(tīng)here,聽(tīng)"data"聽(tīng)is聽(tīng)our聽(tīng)error聽(tīng)object
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)//聽(tīng)respond聽(tīng)to聽(tīng)the聽(tīng)error聽(tīng)here
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)}else{
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)//聽(tīng)other聽(tīng)types聽(tīng)of聽(tīng)events聽(tīng)might聽(tīng)get聽(tīng)passed,聽(tīng)handle聽(tīng)them聽(tīng)here
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)}
聽(tīng)聽(tīng)聽(tīng)聽(tīng)},
聽(tīng)聽(tīng)聽(tīng)聽(tīng)mimetype:聽(tīng)"text/plain"
});
涓嬮潰鐨勪唬鐮佹彁浜や竴孌礿avascript紼嬪簭孌碉紝鐒跺悗璁╂湇鍔″櫒榪愯瀹冿紝涓鑸垜浠繖涔堝仛鏄負(fù)浜?jiǎn)鍔犻熺▼搴忚繍琛岋紝娉ㄦ剰mimetype錛?br />
聽(tīng)聽(tīng)聽(tīng)聽(tīng)url:聽(tīng)"http://foo.bar.com/sampleData.js",
聽(tīng)聽(tīng)聽(tīng)聽(tīng)load:聽(tīng)function(type,聽(tīng)evaldObj){聽(tīng)/*聽(tīng)do聽(tīng)something聽(tīng)*/聽(tīng)},
聽(tīng)聽(tīng)聽(tīng)聽(tīng)mimetype:聽(tīng)"text/javascript"
});
濡傛灉浣犳兂紜繚紼嬪簭浣跨敤XMLHTTP錛屽彲浠ヨ繖鏍峰啓錛?br />
聽(tīng)聽(tīng)聽(tīng)聽(tīng)url:聽(tīng)"http://foo.bar.com/sampleData.js",
聽(tīng)聽(tīng)聽(tīng)聽(tīng)load:聽(tīng)function(type,聽(tīng)evaldObj){聽(tīng)/*聽(tīng)do聽(tīng)something聽(tīng)*/聽(tīng)},
聽(tīng)聽(tīng)聽(tīng)聽(tīng)mimetype:聽(tīng)"text/plain",聽(tīng)//聽(tīng)get聽(tīng)plain聽(tīng)text,聽(tīng)don't聽(tīng)eval()
聽(tīng)聽(tīng)聽(tīng)聽(tīng)transport:聽(tīng)"XMLHTTPTransport"
});
浣滀負(fù)涓涓猨ack-of-all-trades錛堜竾浜嬮氾級(jí)錛宐ind()鍚屾牱鏀寔鏉ヨ嚜浜庤〃鍗曟彁浜ょ殑鏁版嵁銆?br />
聽(tīng)聽(tīng)聽(tīng)聽(tīng)url:聽(tīng)"http://foo.bar.com/processForm.cgi",
聽(tīng)聽(tīng)聽(tīng)聽(tīng)load:聽(tīng)function(type,聽(tīng)evaldObj){聽(tīng)/*聽(tīng)do聽(tīng)something聽(tīng)*/聽(tīng)},
聽(tīng)聽(tīng)聽(tīng)聽(tīng)formNode:聽(tīng)document.getElementById("formToSubmit")
});
RPC
浣犲彲浠ョ湅鍒幫紝Dojo閫氳繃dojo.io.bind鎻愪緵浜?jiǎn)绠鍗曪紝寮哄ぇ鐨勬柟娉曚嬌鐢ㄥ縐嶅鏍風(fēng)殑I/O functions銆備絾鏄湪寮鍙戣繃紼嬩腑錛岀▼搴忓憳?shù)細(xì)璋冪敤寰堝寰堝I/O錛岃繖鍚屾椂浼?xì)缁欐湇鍔″櫒鍜屽鎴风鍔犻噸璐熸媴銆侱ojo鐨凴PC鏈嶅姟灝辨槸涓轟簡(jiǎn)鍑忓皯璐熸媴錛屾槗鐢紝綺劇畝浠g爜鑰岀敓鐨勩?br />
RPC鐨勫叏鍚嶆槸Remote Procedre Calls,鎴栬匯emote Method Invocation,錛堣瘧鑰咃細(xì)榪滅▼method璋冪敤錛夈傛渶鍩烘湰鐨勶紝RPC鍏佽寮鍙戣呰皟鐢ㄥ湪榪滅▼鏈嶅姟鍣ㄤ笂鐨勬柟娉曪紙method錛夈侱ojo涓嶄粎鎻愪緵浜?jiǎn)鍩烘湰鐨凴PC client鍖咃紝鑰屼笖榪樻墿灞曚簡(jiǎn)瀹冿紝浣垮畠鏀寔JSON-RPC鏈嶅姟鍜孻AHOO鏈嶅姟銆傚悓鏃朵綘涔熷彲浠ヨ嚜宸卞啓鍑虹浉瀵逛簬鍏朵粬鏈嶅姟鐨勭被銆?br />
鎴戜滑鍋囧畾鏈変竴涓渶瑕佽皟鐢ㄦ湇鍔″櫒绔▼搴忕殑灝忕▼搴忥紝鍋囪瑕佽皟鐢╝dd(x,y)鍜宻ubtract(x,y)銆傚湪娌℃湁鐗規(guī)畩鎯呭喌鐨勬潯浠朵笅錛屾垜浠殑瀹㈡埛绔細(xì)榪欐牱鍐欙細(xì)
聽(tīng)聽(tīng)聽(tīng)聽(tīng)request聽(tīng)=聽(tīng){x:聽(tīng)x,聽(tīng)y:聽(tīng)y};
聽(tīng)聽(tīng)聽(tīng)聽(tīng)dojo.io.bind({
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)url:聽(tīng)"add.php",
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)load:聽(tīng)onAddResults,
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)mimetype:聽(tīng)"text/plain",
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)content:聽(tīng)request
聽(tīng)聽(tīng)聽(tīng)聽(tīng)});
}
subtract聽(tīng)=聽(tīng)function(x,y)聽(tīng){
聽(tīng)聽(tīng)聽(tīng)聽(tīng)request聽(tīng)=聽(tīng){x:聽(tīng)x,聽(tīng)y:聽(tīng)y};
聽(tīng)聽(tīng)聽(tīng)聽(tīng)
聽(tīng)聽(tīng)聽(tīng)聽(tīng)dojo.io.bind({
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)url:聽(tīng)"subract",
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)load:聽(tīng)onSubtractResults,
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)mimetype:聽(tīng)"text/plain"
聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)聽(tīng)content:聽(tīng)request
聽(tīng)聽(tīng)聽(tīng)聽(tīng)});
}
浣犵湅錛岃繖涓嶆槸寰堥毦銆備絾鏄棤璁烘槸鎴戜滑璁╂湇鍔″櫒榪愯add鍜宻ubtract榪樻槸璁╁鎴風(fēng)鑷繁璁$畻錛岃繖鍙槸涓涓潪甯哥畝鍗曠殑紼嬪簭銆傚鏋滄垜浠璋冪敤鍦ㄦ湇鍔″櫒涓?0涓笉鍚宮ethod浼?xì)鎬庝箞鏍峰憿錛熸垜鐚滄垜浠彲鑳借閲嶅鐨勫啓鍑犱箮涓鏍風(fēng)殑浠g爜涓閬嶅張涓閬嶏紝姣忔閮借鍒涘緩涓涓姹傜被錛坮equest object),璁懼畾URL錛岃瀹氬彉閲忕瓑絳夈傝繖涓嶄粎瀹規(guī)槗鍑洪敊錛岃屼笖榪樺緢鏋嚗銆?br />Dojo鐨凴PC瀹㈡埛绔畝鍖栦簡(jiǎn)榪欎釜榪囩▼錛?p>