Skip to content

Instantly share code, notes, and snippets.

View benjasHu's full-sized avatar

Benja Osuna benjasHu

View GitHub Profile
@benjasHu
benjasHu / index.js
Created May 15, 2018 16:53
Render dynamically React children passing props
/*
You can use this function to dynamically render children in a Rect component, passing into parent's props.
It checks if the children call is a function or a React element and render it with parent's props
*/
function renderChildren( children, props ) {
return toString.call(children) == '[object Function]' ? children(props) : React.Children.map(children, child => React.cloneElement(child, props))
}
@benjasHu
benjasHu / main.js
Created September 27, 2015 16:43
Extract element data attributes and return as an object [ES6]
/**
* Extract only data attributes from an element (or a jQuery element) and return it as an object
* @param {Element} el JS raw element or jQuery element
* @param {String} dataTag data key from extract the rest. Could start with "data-" or not
* @param {Boolean} camelCase keys returned camelCased or not
* @return {Object}
*
* IMPORTANT: It use lodash/underscore as a dependency!
* IMPORTANT: Made in ES6
*
@benjasHu
benjasHu / jquery-plugin.js
Last active March 13, 2021 07:36
ES6 Module jQuery Plugin Definition
import pluginify from 'pluginify';
class Plugin {
constructor() {
/* ... */
}
}
/*
Convert plugin class into a jQuery plugin
@benjasHu
benjasHu / app.js
Last active August 29, 2015 14:07
Facebook Share in a RequireJS Module (with callbacks)
define([
'jquery',
'domReady',
'path/to/facebook'
],
function( $, domReady, Facebook ) {
"use strict";
var app = {