Skip to content

Instantly share code, notes, and snippets.

Benny Ogidan benfluleck

Block or report user

Report or block benfluleck

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@benfluleck
benfluleck / what-forces-layout.md
Created Nov 16, 2019 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.
View what-forces-layout.md

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@benfluleck
benfluleck / WhyReact.md
Created Sep 4, 2019 — forked from sebmarkbage/WhyReact.md
Why is React doing this?
View WhyReact.md

I heard some points of criticism to how React deals with reactivity and it's focus on "purity". It's interesting because there are really two approaches evolving. There's a mutable + change tracking approach and there's an immutability + referential equality testing approach. It's difficult to mix and match them when you build new features on top. So that's why React has been pushing a bit harder on immutability lately to be able to build on top of it. Both have various tradeoffs but others are doing good research in other areas, so we've decided to focus on this direction and see where it leads us.

I did want to address a few points that I didn't see get enough consideration around the tradeoffs. So here's a small brain dump.

"Compiled output results in smaller apps" - E.g. Svelte apps start smaller but the compiler output is 3-4x larger per component than the equivalent VDOM approach. This is mostly due to the code that is usually shared in the VDOM "VM" needs to be inlined into each component. The tr

View index.js
import React from 'react'
import Text from '<atoms>/Text/Text'
import { useState } from 'react'
export const useForm = (initialValues) => {
const [values, setValues] = useState(initialValues)
@benfluleck
benfluleck / server.js
Last active May 5, 2019
HTTPS node server
View server.js
var express = require('express');
var app = express();
var fs = require('fs');
var https = require('https');
var key = fs.readFileSync('key.pem');
var cert = fs.readFileSync( 'cert.pem' );
View inventoryRequest.js
// BAD
class InventoryRequester {
constructor() {
this.REQ_METHODS = ['HTTP'];
}
requestItem(item) {
// ...
}
@benfluleck
benfluleck / posts.js
Created Apr 28, 2019
Interface segregation principle
View posts.js
// bad
class Post {
constructor(){
}
editPost(){
console.log('Post edited')
}
createPost(){
@benfluleck
benfluleck / Bird.js
Last active Apr 28, 2019
Liskov Substitution Principle
View Bird.js
// bad
class Bird{
fly(){
console.log('I can fly')
}
}
class Duck extends Bird {
constructor(){
super();
@benfluleck
benfluleck / Bird.js
Last active Apr 28, 2019
Open Closed Principle
View Bird.js
// Bad
class Bird{}
class FlyingBird extends Bird {
constructor(type, name){
super();
this.name = name
}
flightSpeed(){
if(this.name === "parrot" || this.name === "dove"){
return ('I can fly medium-fast')
@benfluleck
benfluleck / singleResponsiblity.js
Last active Apr 28, 2019
Single Responsibility
View singleResponsiblity.js
// Bad Case
class Staff {
constructor(staff) {
this.staff = staff;
}
registerStaff(staff) {
if (this.validateUser(staff)) {
return `${staff} has been created`;
}
@benfluleck
benfluleck / depthFirstSearch.JS
Last active Apr 27, 2019
Depth First Search
View depthFirstSearch.JS
function Node(value){
this.value = value
this.left = null;
this.right = null;
}
Node.prototype.toString = function() {
return this.value;
}
You can’t perform that action at this time.