Skip to content

Instantly share code, notes, and snippets.

View aaronshaf's full-sized avatar

Aaron Shafovaloff aaronshaf

View GitHub Profile
class ThingsFetcher extends React.Component {
constructor (props) {
super(props)
this.state = {
data: null,
isLoading: false,
wasLoadedSuccessfully: false,
error: null
}
}
shouldComponentUpdate (nextProps, nextState) {
const changedProps = {}
for (const prop in this.props) {
if (this.props[prop] !== nextProps[prop]) {
changedProps[prop] = true
}
}
if (Object.keys(changedProps).length) {
console.debug(changedProps)
@aaronshaf
aaronshaf / custom-element.js
Last active March 25, 2017 22:37
How I minimize the flash of non-upgraded children of a custom element
export default class TimeagoElement extends HTMLElement {
connectedCallback() {
if (this.querySelector('time')) {
this.init()
} else {
window.requestAnimationFrame(() => {
this.init()
})
}
}
@aaronshaf
aaronshaf / keybase.md
Created February 9, 2017 00:46
keybase.md

Keybase proof

I hereby claim:

  • I am aaronshaf on github.
  • I am aaronshaf (https://keybase.io/aaronshaf) on keybase.
  • I have a public key ASDOisGXmsm_9g4PRTg7t1pSwEiR-pQfznNpKGWE5zdtXwo

To claim this, I am signing this object:

@aaronshaf
aaronshaf / example.js
Created December 15, 2016 05:48
why no links from imported state?
import React from 'react'
import ReactDOM from 'react-dom'
import { Editor, EditorState, RichUtils } from 'draft-js'
import { stateToMarkdown } from 'draft-js-export-markdown'
import { stateFromHTML } from 'draft-js-import-html'
class MyEditor extends React.Component {
constructor (props) {
super(props)
this.state = {
@aaronshaf
aaronshaf / pattern.html
Last active November 26, 2016 01:39
Custom Element pattern with i18n
<my-element>
<!--
provided content kept active (not inert)
.screenreader-only added in Custom Element lifecycle
-->
<select class="screenreader-only">
<option></option>
</select>
<template class="intl-messages">

Your First Custom Element in Five Easy Steps

npm install create-element-class --save

2. Create the element

@aaronshaf
aaronshaf / generator.js
Last active May 13, 2022 11:00
Use async generators and async iterators with DynamoDB's scan
const { docClient } = require('../services/dynamodb')
exports.findAllItems = async function* () {
let response = {}
let ExclusiveStartKey
do {
response = await docClient.scan({
TableName: 'mytable',
Limit: 500,
ExclusiveStartKey
const Ajv = require('ajv')
const ajv = Ajv()
module.exports = function (schema) {
const validate = ajv.compile(schema)
return (req, res, next) => {
const isValid = validate(res.body)
if (!isValid) {
console.log('invalid list response', validate.errors)
res.status(500)
@aaronshaf
aaronshaf / fromFormDataToObjectLiteral.js
Created May 28, 2016 16:24
Is there a more terse/blessed way to do this?
Array.from(new FormData(this.refs.form)).reduce((previousValue, currentValue) => {
return Object.assign({}, previousValue, {[currentValue[0]]: currentValue[1]})
}, {})