Skip to content

Instantly share code, notes, and snippets.

View icfantv's full-sized avatar

Adam Gordon icfantv

View GitHub Profile
import { Pipe } from 'angular2/core.js';
/**
* Map to Iteratble Pipe
*
* It accepts Objects and [Maps](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
*
* Example:
*
* <div *ngFor="#keyValuePair of someObject | mapToIterable">
@zachlysobey
zachlysobey / q-advice.md
Last active June 8, 2016 19:52
breakingthings's $q advice

@breakingthings's promise advice

How not to suck at $q

  1. success / error are not promise flow. They're pseudopromise demons. Use then and catch instead.
  2. $q.defer is satan. You should basically never use it. There is an alternative syntax that is superior, $q(function(resolve, reject) {}) but chances are that what you’re working with already returns a promise, and if it does there is absolutely no need for either of these.
  3. Don’t use the promiseFn().then(successFn, errorFn) pattern, as errorFn will only catch errors caused by promiseFn, but not by successFn. Use then(successFn).catch(errorFn) instead. Also note that you can chain several thenables and catch all of them this way, ala then(a).then(b).then(c).catch(errorFn), in which errorFn will handle errors that happen for any of a, b, or c.
  4. Whatever you return from a then-able is turned into a resolving promise. Whatever you throw is turned into a rejecting one. For instance, `.catch
@paulirish
paulirish / what-forces-layout.md
Last active April 24, 2024 12:47
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent