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
ningzbruc
January 24, 2013
Technology
66
1
Share
YUI3 EventTarget
This presentation shows how YUI3 Custom Event System works!
ningzbruc
January 24, 2013
More Decks by ningzbruc
See All by ningzbruc
如何写出一个优秀的开源库
ningzbruc
0
64
去啊无线前端的一天
ningzbruc
1
170
React & Component
ningzbruc
0
43
阿里旅行去啊H5首页总结&Promise
ningzbruc
0
270
KISSY.Base - all about that Base
ningzbruc
0
130
Hammer.js
ningzbruc
1
340
淘宝旅行门票iPad版开发
ningzbruc
0
140
Travel on KISSY mini
ningzbruc
0
200
Events
ningzbruc
2
130
Other Decks in Technology
See All in Technology
NgRx SignalStore: The Power of Extensibility
rainerhahnekamp
0
230
ある製造業の会社全体のAI化に1エンジニアが挑んだ話
kitami
2
990
ワールドカフェI /チューターを改良する / World Café I and Improving the Tutors
ks91
PRO
0
240
NOSTR, réseau social et espace de liberté décentralisé
rlifchitz
0
180
新規サービス開発におけるReact Nativeのリアル〜技術選定の裏側と実践的OSS活用〜
grandbig
2
200
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
16k
インターネットの技術 / Internet technology
ks91
PRO
0
120
マルチエージェント × ハーネスエンジニアリング × GitLab Duo Agent Platformで実現する「AIエージェントに仕事をさせる時代へ。」 / 20260421 GitLab Duo Agent Platform
n11sh1
0
110
Azure Speech で音声対応してみよう
kosmosebi
0
130
Introduction to Bill One Development Engineer
sansan33
PRO
0
410
システムは「動く」だけでは 足りない - 非機能要件・分散システム・トレードオフの基礎
nwiizo
29
9.1k
AWS DevOps Agentはチームメイトになれるのか?/ Can AWS DevOps Agent become a teammate
kinunori
3
480
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.4k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
99
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.4k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
98
Agile that works and the tools we love
rasmusluckow
331
21k
The untapped power of vector embeddings
frankvandijk
2
1.7k
Evolving SEO for Evolving Search Engines
ryanjones
0
180
WCS-LA-2024
lcolladotor
0
530
SEO for Brand Visibility & Recognition
aleyda
0
4.5k
Between Models and Reality
mayunak
3
260
Exploring anti-patterns in Rails
aemeredith
3
320
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. ]{