Skip to content

Instantly share code, notes, and snippets.

View alexandrebodin's full-sized avatar

Alexandre BODIN alexandrebodin

View GitHub Profile
@alexandrebodin
alexandrebodin / index.md
Last active May 17, 2018 12:12
Context binding vs factory

Comparing two different ways to do dependency injection

Simple factory (straight forward)

 const createStuff = (dependencies) => {
 
  const newStuff = {
    //... using the dependencies
  }
 
@alexandrebodin
alexandrebodin / index.js
Last active November 12, 2017 01:12
implementing a directive with custom resolver to handle globalIds easily
const {
GraphQLObjectType,
GraphQLScalarType,
TypeInfo,
visit,
visitWithTypeInfo,
findDeprecatedUsages,
parse,
validate,
execute,
@alexandrebodin
alexandrebodin / db.js
Last active September 20, 2017 11:38
db transaction overlay
import knex from 'knex';
import userQueries from './user';
function DB(qb) {
this.qb = qb;
}
DB.prototype.startTransaction = function(fn) {
this.knex.transaction(trx => {
const proto = {
timeout: null,
promise: null,
racer: null,
then(fn) {
this.promise = this.promise.then(result => {
return Promise.race([this.racer, fn(result)]);
});
return this;
// no need to load any addon here only register
storiesOf('newAPI', module)
.add('story', ({ knob , note, state: { counter, setCounter } }, context) => {
note('myNotes')
return <div onClick={() => setCounter(n => n + 1)}>{knob.text('name', 'Alex')} - {counter} </div>
});
@alexandrebodin
alexandrebodin / index.js
Created May 31, 2017 07:04
jest expect add asymetricMatchers
const definedProto = {
$$typeof: Symbol.for('jest.asymmetricMatcher'),
asymmetricMatch(o) {
return typeof o !== undefined;
},
toAsymmetricMatcher() {
return 'Defined';
},
@alexandrebodin
alexandrebodin / addon api v1
Last active June 7, 2017 09:08
Storybook ideas
const stories = storiesOf('Button');
// this will apply the decorator to every story
stories.addDecorator(withKnobs)
// this will call the function with the final storyFn computed in `add`
stories.addMiddleware(fn)
stories.addMiddleware(fn(options))
@alexandrebodin
alexandrebodin / index.js
Created April 15, 2017 20:23
entitySave
// db/utils/buildSaver.js
const buildEntitySaver = (tableName, entityToDB) => {
function create(entity) {
return queryBuilder(tableName)
.insert(entityToDB(entity))
.returning('id')
.then(([id]) => id);
@alexandrebodin
alexandrebodin / index.js
Last active April 11, 2017 15:24
A query filtering generator for knex
const mapping = {
userId: 'user_id',
comment: 'comment',
date: 'date',
id: 'id',
createdAt: 'created_at',
updatedAt: 'updated_at',
};
var R = require('ramda');
var db = require('./db/queries');
const a = db.filterUser({}, {})
.addContact('contact')
.addCompany(['contact', 'company'])
.then(res => {
console.log(res.splice(0, 1))
});