Skip to content

Instantly share code, notes, and snippets.

View kaw2k's full-sized avatar

Rasa Welcher kaw2k

View GitHub Profile
var onSubmit = function(title, description) {
// Do your ajax here
console.log(title, description);
};
// Here we are opening up a lighbox to edit a title and description
// They will be the intial value of our component
flux.actions.widget.lightbox({
view: ProfileContextEditCreate,
title: 'My awesome title',
{
"parser": "babel-eslint",
"env": {
"browser": true,
"es6": true,
"node": true
},
"plugins": [
"react"
],
.then((details) => {
const newDetails = _.merge(details, {
creditLines: _.map(credit => {
if (!credit.creditTransaction) { return credit; }
const taxCredit = parseFloat(credit.creditTransaction.taxAmount, 10);
const tax = parseFloat(credit.originalTransaction.taxAmount, 10);
const lineTotal = parseFloat(credit.creditTransaction.lineTotal, 10);
return _.merge(credit, {
@kaw2k
kaw2k / implementation.js
Last active October 8, 2015 14:49
A hypothetical tooltip API
import React from 'react';
import mouseTracker from 'decorators/mouseTracker';
// options: {
// followMouse: false,
// positionOrder: ['top', 'bottom', 'left', 'right'],
//
// }
@mouseTracker
import R from 'ramda';
function getValidators(ref) {
var propValidators = R.pathOr([], ['props', 'validators'], ref);
var refValidators = R.pathOr([], ['validators'], ref);
return [].concat(propValidators, refValidators);
}
function Tree(self, children) {
return {
@kaw2k
kaw2k / functors.md
Last active January 23, 2016 01:36

A Map to Success: Functors in Javascript

I wanted to take some time to talk about the humble map function. If you have ever used libraries like underscore, lodash, or ramda, you are sure to encounter more than a few curious functions. The unassuming map function is a good starting point on our journey to functional nirvana.

Making a map

Taking a step back, what is map? Just like normal maps (the paper kind!), map is a guide to get from one place to another.

For example, in your notebook you have a list of numbers: 1 2 3. Next to that list you write 2 3 4. How did this happen? Simply enough, we went over each number in the list and added one to it. In other words, we mapped over the list of numbers and added one to them.

var numbers = [1, 2, 3];
var result = [];
for (var i = 0; i < numbers.length; i++) {
result.push(numbers[i] + 1);
}
function addOne(x) {
return x + 1;
}
var numbers = [1, 2, 3];
var result = [];
for (var i = 0; i < numbers.length; i++) {
result.push(addOne(numbers[i]));
}
[1, 2, 3].map(function(x) {
return x + 1;
});