Skip to content

Instantly share code, notes, and snippets.

View kamleshchandnani's full-sized avatar

Kamlesh Chandnani kamleshchandnani

View GitHub Profile
@kamleshchandnani
kamleshchandnani / ContextMenu.js
Created February 6, 2017 12:39
react-native context-menu/stackoverflow-menu
import React, { Component, PropTypes } from 'react'
import { View, UIManager, findNodeHandle, TouchableOpacity } from 'react-native'
import { Icon } from 'native-base';
const ICON_SIZE = 24
export default class ContextMenu extends Component {
static propTypes = {
// array of strings, will be list items of Menu
actions: PropTypes.arrayOf(PropTypes.string).isRequired,
onPress: PropTypes.func.isRequired
@kamleshchandnani
kamleshchandnani / reactiveconf-2017-progressive-loading-cfp.md
Last active June 29, 2020 08:22
Progressive loading for modern web applications via code splitting!
@kamleshchandnani
kamleshchandnani / rollup.config.js
Created November 10, 2017 12:33 — forked from transitive-bullshit/rollup.config.js
example rollup config for react module transpilation
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
import postcss from 'rollup-plugin-postcss'
import resolve from 'rollup-plugin-node-resolve'
import pkg from './package.json'
export default {
input: 'src/index.js',
output: [
@kamleshchandnani
kamleshchandnani / reactfoo2018-react-design-patterns.md
Last active November 30, 2017 17:55
Design patterns/techniques that can be used while developing with React

Design patterns/techniques that can be used while developing with React


Design patterns help us to make our applications more flexible, perform better, and easier to maintain, giving our workflow a huge boost when it comes to speed without reducing quality.

// File log.js
function log(){
console.log('Example of CJS module system');
}
// expose log to other modules
module.exports = { log }
// File index.js
var logModule = require('./log');
logModule.log();
// File log.js
define(['logModule'], function(){
// export (expose) foo for other modules
return {
log: function(){
console.log('Example of AMD module system');
}
};
});
// File log.js
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(["exports"], factory);
} else if (typeof exports !== "undefined") {
factory(exports);
} else {
var mod = {
exports: {}
};
// File log.js
const log = () => {
console.log('Example of ES module system');
}
export default log
// File index.js
import log from "./log"
log();
// File shakebake.js
const shake = () => console.log('shake');
const bake = () => console.log('bake');
//can be tree shaken as we export as es modules
export { shake, bake };
// File index.js
import { shake } from './shakebake.js'
// only shake is included in the output

No, .mjs is not a Python 3-like split

Seen a few tweets on this. I want to dispel some FUD.

Node is probably going to introduce a new file extension for JavaScript modules, .mjs. The reasons for this are long and perilous, and trying to summarize the discussion that led to it is maddening. The short version is that ES6 modules have different semantics from existing scripts, and need to be executed differently. In browsers, this is done with <script type="module">. In Node, this will be done by analyzing the file extension of the imported file.

I'll be honest: I don't love this solution! I was rooting for the TC39 counter-proposal. But I also understand the solution that the Node developers chose, and why they chose it.

The new file extension is a good enough solution. You can read the [draft spec](https://github.com/nodejs/node-eps/