Skip to content

Instantly share code, notes, and snippets.

@lsmith
lsmith / gist:2494497
Created April 25, 2012 23:42
Flyweight proxy ArrayList for fast DataTable instantiation and rendering
var proxy = {
_data: {},
get: function (name) {
var model = this._data;
return model.isYUIModel ?
model.apply(model, arguments) :
model[name];
},
set: function () {
@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:6664382
Last active December 23, 2015 16:49
Custom event hacked up to support defaultFn that can return a promise to delay after subscribers. POC, mostly untested, so YMMV.
/*global SM:true*/
'use strict';
// Publish a very special, promise-compatible event that supports the default
// function behavior to chain on internally created promises before executing
// the after() subs. on() subs can still e.preventDefault(), which will
// reject the promise and thus skip the default behavior and after() subs.
var asyncEvent = eventTarget.publish('foo');
asyncEvent._firing = new Y.Promise(function (resolve) { resolve(); });