Skip to content

Instantly share code, notes, and snippets.

View XEngine's full-sized avatar

Cem Yılmaz XEngine

  • DePauli A.G
  • İzmir
View GitHub Profile
@getify
getify / 1.md
Last active October 15, 2020 01:44
BetterPromise: a strawman experiment in subclassing Promise and "fixing" a bunch of its awkward/bad parts

Some things that are "better" with this BetterPromise implementation:

  • BetterPromise # then(..) accepts a BetterPromise (or Promise) instance passed directly, instead of requiring a function to return it, so that the promise is linked into the chain.

    var p = BetterPromise.resolve(42);
    
    var q = Promise.resolve(10);
    
    p.then(console.log).then(q).then(console.log);
@akmandev
akmandev / fabric.getItem.js
Created October 13, 2016 13:01
FabricJS - Get Item By ID
fabric.Canvas.prototype.getItem = function(id) {
var object = null,
objects = this.getObjects();
for (var i = 0, len = this.size(); i < len; i++) {
if (objects[i].id && objects[i].id === id) {
object = objects[i];
break;
}
}
@KiaraGrouwstra
KiaraGrouwstra / proxy-async.js
Last active January 3, 2021 15:36
using ES6 Proxy to let Promises/Observables pretend like they're regular values
// using ES6 Proxy to let Promises/Observables pretend like they're regular values.
// get the mapping function used for async objects
let getMapper = (target) => target instanceof Promise ? 'then' :
target instanceof Observable ? 'switchMap' : null;
// ^ fails if the Observable is in a local namespace e.g. Rx.Observable
// bind a value to its object if it's a function
let bindFn = (val, obj) => typeof val == 'function' ? val.bind(obj) : val;