Skip to content

Instantly share code, notes, and snippets.

View garbles's full-sized avatar
🇨🇦

Gabe garbles

🇨🇦
View GitHub Profile
@garbles
garbles / shadow-root.html
Last active August 29, 2015 14:08
Example directive for creating elements wrapped in a `#shadow-root`
<shadow-root style="app/styles/isolated-styles.css">
<div some-directive></div>
</shadow-root>
@garbles
garbles / BaseStore.js
Created December 23, 2014 01:34
Base Store class with ES6 and CommonJS for Flux
let EventEmitter = require('events').EventEmitter;
const CHANGE_EVENT = 'CHANGE_EVENT';
class BaseStore extends EventEmitter {
emitChange () {
this.emit(CHANGE_EVENT);
}
addChangeListener (callback) {
// From http://stackoverflow.com/questions/11381673/javascript-solution-to-detect-mobile-browser#answer-13819253
var isMobile = {
Android: navigator.userAgent.match(/Android/i),
BlackBerry: navigator.userAgent.match(/BlackBerry/i),
iOS: navigator.userAgent.match(/iPhone|iPad|iPod/i),
Opera: navigator.userAgent.match(/Opera Mini/i),
Windows: navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/WPDesktop/i)
};
{
"presets": ["es-2015"],
"plugins": ["syntax-flow"],
"env": {
"development": {
"plugins": ["strip-flow-types"]
},
"test": {
"plugins": ["flow-to-gen", "strip-flow-types"]
}
import {sample, sampleOne} from 'babel-plugin-transform-flow-to-gen/api';
type Person = {
name: string,
age: number
}
// creates a generator
const personGen = Person();
import {sample, sampleOne, types} from 'babel-plugin-transform-flow-to-gen/api';
import type {Animal, Dog} from './types';
const dogGen = Animal(types.literal('dog'));
const anySpeciesGen = Animal(types.string());
const dog = sampleOne(dogGen);
console.log(dog);
// { "species": "dog", "name": "ahKL9p" }
import {sampleOne, types} from 'babel-plugin-transform-flow-to-gen/api';
const personGen =
types.plainObject({
name: types.string(),
age: types.number()
});
console.log(sampleOne(personGen));
// { "name": "rJJ9", "age": -1 }
import {sampleOne} from 'babel-plugin-transform-flow-to-gen/api';
type Person = {
name: string,
age: number
}
function setName(person: Person, name: string): Person {
return {
...person,
@garbles
garbles / $Gen.js
Last active January 30, 2018 02:03
import uuid from 'uuid-v4';
import {sample} from 'babel-plugin-transform-flow-to-gen/api';
import type {$Gen} from 'babel-plugin-transform-flow-to-gen/Gen';
// FYI,
// type $Gen<T, _U> = T;
type User = {
id: $Gen<string, uuid>, // $Gen only supports references to function calls
name: string
import setName from './setName';
import {types} from 'babel-plugin-transform-flow-to-gen/api';
import type {Person} from './types';
require('jasmine-check').install();
describe('setName', () => {
it.check('sets a new name', [Person(), types.string()], (person, newName) => {
const next = setName(person, newName);