Skip to content

Instantly share code, notes, and snippets.

View juandopazo's full-sized avatar

Juan Dopazo juandopazo

View GitHub Profile
Y.io.xhr = function (uri, options) {
options = options || {};
return new Y.Promise(function (resolve, reject) {
var io = Y.io(url, {
// reference options directly to avoid insertion of unwanted options
// into Y.io()
method: options.method,
data: options.data,
headers: options.headers,
test 123
@juandopazo
juandopazo / gist:5405383
Last active December 16, 2015 08:19
Storage module design and API for review

Storage

Motivation

There are 3 major types of storage is browsers up to date:

  • IndexedDB. The future.
  • localStorage. Limited in size and can be observed through the storage event.
  • WebSQL. Dropped by the W3C but it's still very present in the wild, with notable platforms like iOS and PhoneGap.
@juandopazo
juandopazo / gist:5404857
Created April 17, 2013 14:42
Using AsyncQueue and Promises to control the order in which expensive assets are loaded in a page
// AsyncQueue version
YUI().use('async-queue', function (Y) {
var queue = new Y.AsyncQueue(
function () {
queue.pause();
// Load a widget
YUI().use('tabview', function (Y) {
var tabview = new Y.TabView();
//...
@juandopazo
juandopazo / gist:5398897
Last active December 16, 2015 07:28
Lazy Views pattern
YUI().use('app', function (Y) {
var MyApp = Y.Base.create('myApp', Y.App, [], {
views: {
person: {
type: 'PersonView'
}
},
@juandopazo
juandopazo / gist:5095574
Last active December 14, 2015 13:48
ArrayPromise for array-like fun with YUI promises
function ArrayPromise() {
ArrayPromise.superclass.constructor.apply(this, arguments);
}
Y.extend(ArrayPromise, Y.Promise);
Y.Array.each(['each', 'map', 'filter', 'some', 'every', 'reject'], function (method) {
ArrayPromise.prototype[method] = function () {
var args = Array.prototype.slice.call(arguments);
return this.then(function (results) {
return Y.Array[method].apply(Y.Array, [results].concat(args));
@juandopazo
juandopazo / gist:5095552
Created March 5, 2013 23:59
async.js style using YUI promises
function async(args, fn) {
return Y.batch.apply(Y, Y.Array.map(args, function (arg) {
return new Y.Promise(function (resolve, reject) {
fn(arg, function (err, result) {
if (err) {
reject(err);
} else {
resolve(result);
}
});
@juandopazo
juandopazo / gist:4978418
Created February 18, 2013 16:01
A YUI Plugin for widgets that use WidgetStdMod which lets you collapse and expand the bodyNode
/**
A Plugin for widgets that use WidgetStdMod which lets you
collapse and expand the bodyNode
@class Plugin.Collapsible
@constructor
@extends Plugin.Base
@param {Object} config Object literal containing plugin configuration options
**/
function Collapsible() {
@juandopazo
juandopazo / adapter.js
Created February 11, 2013 16:34
File necessary to run the A+ Test Suite on the YUI implementation of Promises
var YUI = require('yui').YUI;
var Y = YUI({
useSync: true,
modules: {
promise: {
fullpath: '../yui3/build/promise/promise-min.js',
requires: [
"oop",
"timers"
// Inherit from Y.Promise as you would from any other class
function ListPromise() {
ListPromise.superclass.constructor.apply(this, arguments);
}
Y.extend(ListPromise, Y.Promise, {
map: function (fn, context) {
return this.then(function (values) {
return Y.Array.map(values, fn, context);
});
},