Skip to content

Instantly share code, notes, and snippets.

@selvagsz
selvagsz / promise_and_deferred.js
Created November 3, 2016 19:58
Diff between native promise & $.Deferred promise chain
// Check the console logs by uncommenting the error throwing scenario also
function one() {
console.log('one')
throw new Error('error1')
}
function two() {
console.log('two')
}
@selvagsz
selvagsz / webpack-notes.js
Last active October 24, 2016 08:22
Webpack Notes
// Entire default options
{
devtool: false,
cache: true,
context: process.cwd(),
target: 'web',
module: {
unknownContextRequest: '.',
let a = {
name: 'selva'
}
let zfoo = {
foo: {
name: 'a',
ofo: {
bar: a
}
@selvagsz
selvagsz / index.md
Last active May 24, 2017 15:15
Immutable <==> JS

Object <==> Map

Creation

// js
let foo = {}

// Immutablejs
let bar = Map()
@selvagsz
selvagsz / controllers.application.js
Created September 19, 2016 04:17
model-proxy-removal
import Ember from 'ember';
Ember.ObjectController.reopen({
unknownProperty(prop) {
console.log(prop, this._debugContainerKey);
// log the info to your server
return this._super(prop);
},
  • If you have some unwanted properties in your props, do not drop all of them using {...props} to the child component. Pass the props that are needed by the component. (facebook/react#7157 (comment))
// BAD (if there are unwanted props)
render() {
  return (
    <Foo {...this.props} />
  );
}

Its been a month since I dove into react. Its an incredible journey, where I just concentrated in learning more things.

Stepping into second month of my react journey,

I'm often tempted to jump into the source code of the framework/libraries that I consume. In react, the source code lies inside the /src folder https://github.com/facebook/react/tree/master/src

To start with, the best way is to go through the modules with no or less dependencies. Usually, the utils will have less dependencies but they would be consumed a lot throughout. So, I feel its good to start with them.

React shares some utilities from https://github.com/facebook/fbjs

  1. invariant
  2. keyMirror
  3. keyOf
  4. emptyFunction
@selvagsz
selvagsz / slim-redux.js
Created June 9, 2016 14:51 — forked from gaearon/slim-redux.js
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {