- Intro, history
- Goals
- Performance
- Memory usage
- Size
- Build to customize
- General design overview
- Events are stateless, nameless
- Publish events statically or on an instance
- Subscriptions are managed on the target
| <!doctype html> | |
| <html> | |
| <head> | |
| <title>IO with transports and promises</title> | |
| </head> | |
| <body> | |
| <script src="http://yui.yahooapis.com/3.9.1/build/yui/yui.js"></script> | |
| <script> | |
| // sm-io is an alias for sm-io-core and sm-io-xhr. The two modules don't require one another. | |
| YUI({ filter: 'raw' }).use('sm-io', function (Y) { |
| var dataPromise = new Y.Promise(function (resolve, reject) { | |
| var data = []; | |
| function getData(offset) { | |
| return new Y.Promise(function (dataResolve, dataReject) { | |
| Y.io('getdata.php?offset=' + offset, { | |
| on: { | |
| success: function (id, response) { | |
| var dataset = Y.JSON.parse(response.responseText); |
| var child = new Y.EventTarget({ emitFacade: true }), | |
| parent = new Y.EventTarget({ emitFacade: true }), | |
| grandparent = new Y.EventTarget({ emitFacade: true }); | |
| child.addTarget(parent); | |
| parent.addTarget(grandparent); | |
| child.publish('foo', { | |
| defaultFn: function () { console.log("default function"); } | |
| }); |
| function promiseFire(data) { | |
| var event = this, | |
| target = this.host; | |
| event._firing = event._firing.then(function () { | |
| return new Y.Promise(function (resolve, reject) { | |
| // Execute on() subscribers | |
| var e = Y.merge({ | |
| preventDefault: function () { | |
| this.prevented = true; |
| YUI.add('data-bind', function (Y) { | |
| Y.DataBind = function (config) { | |
| if (!Y.Base || !(this instanceof Y.Base)) { | |
| // Being used as a standalone class | |
| this.initializer(config); | |
| // alias instance.destroy() to destructor for convenience | |
| this.destroy = this.destructor; | |
| } | |
| }; |
| notifier.handle.evt.fire = function (e) { | |
| var subs = this._subscribers.concat(this._afters), | |
| args = Y.Array(arguments, 0, true), | |
| i, len, halt; | |
| for (i = 0, len = subs.length; i < len; ++i) { | |
| halt = subs[i].notify(args, this); | |
| // stopImmediatePropagation | |
| if (halt === false || e.stopped > 1) { |
| Y.DataTable.BodyView.prototype._afterModelListChange = function (e) { | |
| var handles = this._eventHandles; | |
| if (handles.dataChange) { | |
| handles.dataChange.detach(); | |
| delete handles.dataChange; // <-- this line is missing in the core code | |
| this.bindUI(); | |
| } | |
| if (this.tbodyNode) { |
| columns: [ | |
| 'item', | |
| 'cost', | |
| { | |
| key: 'price', | |
| allowHTML: true, | |
| formatter: function (o) { | |
| var words = o.value.split(/\s+/), | |
| i = words.length, | |
| word; |
| var suite = new Y.Test.Suite("yo yo ma"); | |
| suite.add(new Y.Test.Case({ | |
| "foo should bar": function () { | |
| var test = this, | |
| node = Y.one('#foo'); | |
| node.on('focus', function () { | |
| test.resume(function () { | |
| // Assertions go here |