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
YUI3 EventTarget
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
ningzbruc
January 24, 2013
Technology
1
64
YUI3 EventTarget
This presentation shows how YUI3 Custom Event System works!
ningzbruc
January 24, 2013
Tweet
Share
More Decks by ningzbruc
See All by ningzbruc
如何写出一个优秀的开源库
ningzbruc
0
59
去啊无线前端的一天
ningzbruc
1
170
React & Component
ningzbruc
0
42
阿里旅行去啊H5首页总结&Promise
ningzbruc
0
260
KISSY.Base - all about that Base
ningzbruc
0
120
Hammer.js
ningzbruc
1
340
淘宝旅行门票iPad版开发
ningzbruc
0
130
Travel on KISSY mini
ningzbruc
0
200
Events
ningzbruc
2
130
Other Decks in Technology
See All in Technology
【NGK2026S】日本株のシステムトレードに入門してみた
kazuhitotakahashi
0
190
書籍執筆での生成AIの活用
sat
PRO
1
230
「AIでできますか?」から「Agentを作ってみました」へ ~「理論上わかる」と「やってみる」の隔たりを埋める方法
applism118
10
7k
一番人に近いコードレビューア CodeRabbit
kinopeee
0
110
Databricks Free Edition講座 データサイエンス編
taka_aki
0
230
エンジニアとして長く走るために気づいた2つのこと_大賀愛一郎
nanaism
1
260
AWSと暗号技術
nrinetcom
PRO
1
190
Claude Codeベストプラクティスまとめ
minorun365
50
28k
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.3k
MySQLのJSON機能の活用術
ikomachi226
0
100
「全社導入」は結果。1人の熱狂が組織に伝播したmikanのn8n活用
sota_mikami
0
570
SMTP完全に理解した ✉️
yamatai1212
0
110
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
0
250
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
47
Reality Check: Gamification 10 Years Later
codingconduct
0
2k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
85
The SEO Collaboration Effect
kristinabergwall1
0
340
ラッコキーワード サービス紹介資料
rakko
1
2.1M
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
60
The Curious Case for Waylosing
cassininazir
0
230
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
46
Designing for humans not robots
tammielis
254
26k
A designer walks into a library…
pauljervisheath
210
24k
Transcript
YUI3 Custom Event System ]{
Pub/Sub
Observer Design Pattern
Subject Observer Notify Attach
YUINode.on('click', function(e) { console.log(e.type); // click });
Subject Observer
MySlider.on('switch', function(e) { // more code here
});
Y.EventTarget
Y.EventTarget Y.CustomEvent Y.Subscriber Y.EventHandle Y.EventFacade
// Step 1 var MyEventTarget = new Y.EventTarget(); //
Step 2 var MyCustomEvent = ET.publish('myevent'); // Step 3 var MySubscriber = function(MyEventFacade) { // Step 6 console.log(MyEventFacade.foo); // 1 }; // Step 4 var MyEventHandle = MyEventTarget.on('myevent', MySubscriber); // Step 5 ET.fire('myevent', { foo: 1, bar: 2 }); // Step 7 MyEventHandle.detach();
publish on fire ... Y.EventTarget _yuievt.events {eventtype: new Y.CustomEvent()}
on fire detach ... Y.CustomEvent subscribers {id: new Y.Subscriber()}
notify ... Y.Subscriber fn context args id
detach batch ... Y.EventHandle evt: Y.CustomEvent sub: Y.Subscriber
preventDefault stopPropagation halt ... Y.EventFacade type target currentTarget details args
...
function MyWidget() { this.name = 'mywidget'; }
Y.augment(MyWidget, Y.EventTarget); // MyWidget.publish(...) // MyWidget.on(...) // MyWidget.fire(...)
Y Y.Global Attribute Base Widget Model ...
function Mod(name) { this.name = name;
this.publish('render', { fireOnce: true }); } Y.augment(Mod, Y.EventTarget); Mod.prototype = { render: function() { // more code this.fire('render', { args: YArray(arguments, 0, true) }); return this; } }; Mod.create = function(name, methods) { return Y.mix(new Mod(name), methods); }
var Mod_A = Mod.create('a', { getModBData: function()
{ Mod_B.on('render', function(e) {...}) } }); var Mod_B = Mod.create('b', methods); Mod_A.render().getModBData(); // more code // lazyload Mod_B.render();
Just Do It!
Y.Do
Y.Do.before(fn, obj, sFn, c, args)
None
The end. ]{