Skip to content

Instantly share code, notes, and snippets.

@etienne-dldc
etienne-dldc / combineContext.js
Created March 28, 2018 18:38
A small function to combine react Contexts.
import React from 'react';
function onlyChild(children) {
return Array.isArray(children) ? children[0] : children;
}
export function combineContext(contexts) {
class Provider extends React.Component {
render() {
const init = this.props.children;
@bvaughn
bvaughn / create-subscriber-component-poc.js
Last active September 30, 2018 09:55
create-subscriber-component proof of concept
type SubscribableConfig = {
// Maps property names of subscribable data sources (e.g. 'someObservable'),
// To state names for subscribed values (e.g. 'someValue').
subscribablePropertiesMap: {[subscribableProperty: string]: string},
// Synchronously get data for a given subscribable property.
// It is okay to return null if the subscribable does not support sync value reading.
getDataFor: (subscribable: any, propertyName: string) => any,
// Subscribe to a given subscribable.
import { combineEpics } from 'redux-observable';
/*
* Let's assume each configuration has the following:
* {
* type: String|Array<String>,
* url: String,
* method: String,
* body: String|Function<Action, String|Object>,
* process: Function<ActionObservable, ActionObservable>,
@staltz
staltz / comment.md
Created March 15, 2017 15:27
Nested Pick<T, K> in TypeScript 2.2

TypeScript supports Pick to allow you to get a "subset" object type of a given type, but there is no built-in Pick for deeper nested fields.

If you have a function that takes a large object as argument, but you don't use all of its fields, you can use Pick, Pick2, Pick3, etc to narrow down the input type to be only just what you need. This will make it easier to test your function, because when mocking the input object, you don't need to pass all fields of the "large" object.

@scyrizales
scyrizales / SimpleVirtualRepeater.js
Created May 5, 2016 00:06
SimpleVirtualRepeater - This is an simple solution to handle thousands of results on an ng-repeat without sacrificing performance.
(function() {
'use strict';
angular.module('simple-virtual-repeater', [])
.directive('virtualRepeater', virtualRepeater);
virtualRepeater.$inject = ['$compile', '$timeout'];
function virtualRepeater($compile, $timeout) {
var directive = {
restrict: 'EA',
replace: 'true',
@btroncone
btroncone / ngrxintro.md
Last active February 9, 2024 15:37
A Comprehensive Introduction to @ngrx/store - Companion to Egghead.io Series

Comprehensive Introduction to @ngrx/store

By: @BTroncone

Also check out my lesson @ngrx/store in 10 minutes on egghead.io!

Update: Non-middleware examples have been updated to ngrx/store v2. More coming soon!

Table of Contents

@bishboria
bishboria / springer-free-maths-books.md
Last active April 25, 2024 06:27
Springer made a bunch of books available for free, these were the direct links
@paulirish
paulirish / what-forces-layout.md
Last active May 6, 2024 07:54
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
@finom
finom / addeventlistener.js
Created August 22, 2014 13:32
Simple addEventListener polyfill for IE8
( function( win, doc, s_add, s_rem ) {
if( doc[s_add] ) return;
Element.prototype[ s_add ] = win[ s_add ] = doc[ s_add ] = function( on, fn, self ) {
return (self = this).attachEvent( 'on' + on, function(e){
var e = e || win.event;
e.target = e.target || e.srcElement;
e.preventDefault = e.preventDefault || function(){e.returnValue = false};
e.stopPropagation = e.stopPropagation || function(){e.cancelBubble = true};
e.which = e.button ? ( e.button === 2 ? 3 : e.button === 4 ? 2 : e.button ) : e.keyCode;
fn.call(self, e);
<snippet>
<content><![CDATA[
<!-- begin $1 -->
<div class="$1">
$2
</div>
<!-- end $1 -->
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>di</tabTrigger>