$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
YUI3 EventTarget
Search
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
56
去啊无线前端的一天
ningzbruc
1
160
React & Component
ningzbruc
0
39
阿里旅行去啊H5首页总结&Promise
ningzbruc
0
260
KISSY.Base - all about that Base
ningzbruc
0
120
Hammer.js
ningzbruc
1
330
淘宝旅行门票iPad版开发
ningzbruc
0
130
Travel on KISSY mini
ningzbruc
0
200
Events
ningzbruc
2
130
Other Decks in Technology
See All in Technology
ハッカソンから社内プロダクトへ AIエージェント ko☆shi 開発で学んだ4つの重要要素
leveragestech
0
110
AWS運用を効率化する!AWS Organizationsを軸にした一元管理の実践/nikkei-tech-talk-202512
nikkei_engineer_recruiting
0
170
Amazon Quick Suite で始める手軽な AI エージェント
shimy
1
1.8k
特別捜査官等研修会
nomizone
0
560
半年で、AIゼロ知識から AI中心開発組織の変革担当に至るまで
rfdnxbro
0
140
MySQLとPostgreSQLのコレーション / Collation of MySQL and PostgreSQL
tmtms
1
1.2k
テストセンター受験、オンライン受験、どっちなんだい?
yama3133
0
140
[Data & AI Summit '25 Fall] AIでデータ活用を進化させる!Google Cloudで作るデータ活用の未来
kirimaru
0
3.7k
Entity Framework Core におけるIN句クエリ最適化について
htkym
0
120
ソフトウェアエンジニアとAIエンジニアの役割分担についてのある事例
kworkdev
PRO
0
220
AWS re:Invent 2025~初参加の成果と学び~
kubomasataka
0
180
TED_modeki_共創ラボ_20251203.pdf
iotcomjpadmin
0
150
Featured
See All Featured
Crafting Experiences
bethany
0
22
Building Flexible Design Systems
yeseniaperezcruz
330
39k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.1k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
0
210
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
34
Optimizing for Happiness
mojombo
379
70k
30 Presentation Tips
portentint
PRO
1
170
A Tale of Four Properties
chriscoyier
162
23k
Building an army of robots
kneath
306
46k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Heart Work Chapter 1 - Part 1
lfama
PRO
3
35k
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. ]{