Skip to content

Instantly share code, notes, and snippets.

View bellentuck's full-sized avatar

Ben Ellentuck bellentuck

  • New York, NY
View GitHub Profile
@bellentuck
bellentuck / isFalsy.js
Created January 26, 2018 17:07 — forked from skoshy/isFalsy.js
Determines if any value is "falsy" in JavaScript
// this function takes in any parameter and can tell if it's "falsy" or not.
// falsy means it's either false, 0, null, undefined, NaN, or an empty string/array/object
// see the test cases at the bottom for a clearer picture
function isFalsy(item) {
try {
if (
!item // handles most, like false, 0, null, etc
|| (
typeof item == "object" && (
@bellentuck
bellentuck / call_all.js
Created February 5, 2018 22:03
calling all args! xoxo, generator
function* cycleThruFnArgs(obj, fnArr) {
while (fnArr.length > 0) {
yield fnArr.shift().call(obj);
}
}
function callAll(obj, args) {
if (arguments.length < 2) throw 'Supply obj and args array';
var gen = cycleThruFnArgs(obj, args);
//run this in your console
for (var i = 0; i <= 3; i++) {
  setTimeout(function(){
    console.log(i); 
  }, 0); 
} 
@bellentuck
bellentuck / pep-revised-draft-5-6-18.md
Last active May 7, 2018 00:25
React-Redux data management: serialization and memoized caching of derived data

React-Redux data management: serialization and memoized caching of derived data

Minimizing lookup times is a central problem in data management, particularly for large applications. Linear lookup time is bad. Sublinear lookup time is better. Constant lookup is ideal.

Client-side, in the context of a Redux-managed application, the problem becomes a matter of defining the shape of app state.

This article explores two avenues for better organizing such front-end state: (1) serializing data from the back end, reducing to fully-indexed state shape via utility reducers, and (2) caching data on the front end, in particular by utilizing the Reselect library in React-Redux mapStateToProps functions to create or look up "memos" of chunks of derivable data.