Skip to content

Instantly share code, notes, and snippets.

View boopathi's full-sized avatar
💭
I may be slow to respond.

Boopathi Rajaa boopathi

💭
I may be slow to respond.
View GitHub Profile
const productLoader = new DataLoader(getBackendProducts);
const resolvers = {
Query: {
async product(_, { id }, __, info) {
const fields = getFields(info);
const backendFields = getBackendFields(fields, dependencyMap);
const backendResponse = await productLoader.load({ id, fields: backendFields });
const schemaResponse = getSchemaResponse(backendResponse, fields, transformerMap);
return schemaResponse;
const resolvers = {
Query: {
async product(_, { id }, __, info) {
const fields = getFields(info);
const backendFields = getBackendFields(fields, dependencyMap);
const backendResponse = await fetch(`/product?id=${id}&fields=${backendFields}`);
const schemaResponse = getSchemaResponse(backendResponse, fields, transformerMap);
return schemaResponse;
}
}
@boopathi
boopathi / git-cleanup.sh
Last active January 13, 2018 20:37
Cleanup git branches
#!/bin/bash
git branch -r |
awk '{print $1}' |
egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) |
awk '{print $1}'
class A {
  #x;
  constructor(x, a) {
    #x = x;
    this.foo = this.foo.bind(a);
  }
  foo() {
    console.log(this?.#x); // optional chaining
 // Possible to use optional chaining?

Motivation -

  1. use private keyword
  2. Use class private and not instance private.
  3. Statically analysable.

Based on this issue - tc39/proposal-private-fields#14, there is a lot of interest in using the private keyword and no sigils, and sigils cannot be avoided for multiple reasons specified in the FAQ.

Addressing some of the comments by littledan,

@boopathi
boopathi / system-import-sync-plugin.js
Created October 31, 2016 15:14
Converts System.import to a synchronous require call. For NodeJS
const template = require("babel-template");
module.exports = function SystemImportPlugin() {
return {
visitor: {
CallExpression(path) {
const callee = path.get("callee");
if (!callee.isMemberExpression()) return;
const object = callee.get("object");

Keybase proof

I hereby claim:

  • I am boopathi on github.
  • I am boopathi (https://keybase.io/boopathi) on keybase.
  • I have a public key whose fingerprint is 1FAC 1419 710A D0DB 6C4B 7A11 873B 84CB 3041 903B

To claim this, I am signing this object:

@boopathi
boopathi / cli.js
Created August 30, 2016 11:23
Transform babel-minify tests
#!/usr/bin/env node
const fs = require("fs");
const minimist = require("minimist");
const transform = require("./index");
module.exports = run;
if (require.main === module) {
run(process.argv.slice(2))
@boopathi
boopathi / combine-chunks-plugin.js
Created March 17, 2016 22:00
Combine Chunks Plugin
var ConcatSource = require('webpack/lib/ConcatSource');
var loaderUtils = require('loader-utils');
module.exports = CombineChunksPlugin;
// opts.filename = 'vendor.[contenthash].js'
function CombineChunksPlugin(opts) {
if (opts) {
this.filename = opts.filename ? opts.filename : 'vendor.bundle.js';
@boopathi
boopathi / gist:57e0e63976d27e969f9c
Last active September 6, 2015 16:46 — forked from bolshchikov/gist:8069009
Creating read-only JS object
// lo-dash lib is the dependency
function readOnly(target){
var _readOnly = function (target, acc) {
// acc is passed into the function to be used for observer
var _defineProperty = function (propName, target, acc) {
var i, len;
// operation to be performed when add occurred