Skip to content

Instantly share code, notes, and snippets.

@lsmith
lsmith / gist:5344236
Created April 9, 2013 09:08
Eventx design review, status update agenda
  1. Intro, history
  2. Goals
  • Performance
  • Memory usage
  • Size
  • Build to customize
  1. General design overview
  • Events are stateless, nameless
  • Publish events statically or on an instance
  • Subscriptions are managed on the target
@lsmith
lsmith / example.html
Last active December 15, 2015 16:39
WIP IO implementation using transports with send(requestObj, callback(err, data)) and a generic io(requestObj[, callback]) that returns promises.
<!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) {
@lsmith
lsmith / gist:5271961
Last active December 15, 2015 14:09
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);
@lsmith
lsmith / gist:5117861
Last active December 14, 2015 16:49
Getting an idea of what the expectation of behavior between on() and after() phase of a stopped event is.
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"); }
});
@lsmith
lsmith / gist:5106331
Created March 7, 2013 08:02
Publish a custom event that respects promises returned from the defaultFn.
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;
@lsmith
lsmith / gist:4403715
Created December 29, 2012 01:14
YUI 3 data binding. First pass. Supports lots of stuff that I don't have time to document at this very moment. Maybe you can figure it out from the code?
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;
}
};
@lsmith
lsmith / gist:4272500
Created December 12, 2012 23:04
Potential patch for 'tap' synthetic event's notifier custom event to allow e.preventDefault() or e.stopPropagation() to have that effect on the subsequent 'click' event.
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) {
@lsmith
lsmith / gist:3124468
Created July 16, 2012 19:17
Patch for 3.6.0pr2 and pr3 DataTable
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