Skip to content

Instantly share code, notes, and snippets.

View gmmorris's full-sized avatar

Gidi Meir Morris gmmorris

View GitHub Profile
@gmmorris
gmmorris / JSXCompilation.js
Created November 28, 2016 16:26
Snippet for "The magical quest for Componentisation"
// Specifically what might interest you is how the following JSX:
<MyButton color="blue" shadowSize={2}> <Echo value="Click Me" /> </MyButton>
// Compiles to:
React.createElement(
MyButton,
{color: 'blue', shadowSize: 2},
React.createElement( Echo, {value: 'Click Me'} )
@gmmorris
gmmorris / functionalCompositonWithIndependentArguments.js
Created November 28, 2016 16:24
Snippet for "The magical quest for Componentisation"
// We'll label g() and f() as the `parent` and `child` functions
const parent = () => {}
const child = () => {}
// we'll label the arguments for the composition as `props`
const props = [x, y, z]
// we'll add a little flexability by allowing the parent and child
// to have their own arguments, and leaving it up to the parent to decide
// what to do with the child
const childProps = [a, b, c]
@gmmorris
gmmorris / funcitonalComposition.js
Created November 28, 2016 16:20
Snippet for "The magical quest for Componentisation"
const g = () => {}
const f = () => {}
// (g ∘ f )(x) = g(f(x))
const h = (...args) => g(f(...args))
@gmmorris
gmmorris / TheMagicalQuestForComponentisation.md
Created November 28, 2016 16:05
The magical quest for Componentisation

The magical quest for Componentisation

I would like, if I may, to ask you an existential question.

What is the core of our job as developers today?

It probably isn't figuring out the next super cool & complex algorithm.

But rather, what our job probably is, is to take an existing abstraction and compose it with a second abstraction in order to form a third abstraction.

@gmmorris
gmmorris / npm-defaults.sh
Created September 5, 2016 10:18
Set NPM defaults
npm config set init.author.name "Gidi Meir Morris"
npm config set init.author.email gidi@gidi.io
npm config set init.author.url http://www.gidi.io
npm config set init.license MIT
@gmmorris
gmmorris / MyComponent.js
Created August 1, 2016 00:00
An example for a self "rerendering" JSON component which allows you to build JSON objects which could update themselves in the component tree
function compare(left, right){
return left.val === right.val;
}
function render(props){
const objVal = {
...props,
setProps: (newProps) => {
if(!compare(props, newProps)) {
this(newProps);
@gmmorris
gmmorris / WorkingExampleOfSafeFatherNameAccess.js
Last active January 6, 2017 12:01
Example of how to fix the original function using the safe function
const safeDarthVader = safe({
name : 'Anakin',
mother : {
name : 'Shmi'
}
});
function getFatherName(person) {
return person.father.name
@gmmorris
gmmorris / StringBasedAccess.js
Created February 7, 2016 22:03
Example of safe access using a string for the Safe Access Proxy article
const DarthVader = {
name : 'Anakin',
mother : {
name : 'Shmi'
}
};
function deepAccessUsingString(obj, key){
return key.split('.').reduce((nestedObject, key) => {
if(nestedObject && key in nestedObject) {
@gmmorris
gmmorris / SafeDarthVader.js
Last active August 3, 2016 21:29
example of usage for the Safe Access Proxy article
const mySafeObj = safe({
name : 'Anakin',
mother : {
name : 'Shmi'
}
});
console.log(mySafeObj.name); // returns "Anakin"
@gmmorris
gmmorris / SafeAccessFunction.js
Created February 7, 2016 21:35
Implementation for the Safe Access Proxy article
function safe(obj) {
return new Proxy(obj, {
get: function(target, name){
return hasKey(target, name) ?
(isObject(target[name]) ? safe(target[name]) : target[name]) : Undefined;
}
});
}