Skip to content

Instantly share code, notes, and snippets.

View russellf9's full-sized avatar
🏠
Working from home

Russell Wenban russellf9

🏠
Working from home
  • Factornine Limited
  • London, UK
View GitHub Profile

Original was from Reduce Advanced of funfunfunction. It was a great example, but I thought it could use a bit more of the ES6 goodness like template literals, destructuring, and the spread operators.

Also the reduced form is a more "pure" functional implementation since it doesn't mutate the original object with evil functions like push, but instead returns new data every time. A JS Bin is available to run and play with the modified version.

@markerikson
markerikson / redux-thunk-examples.js
Last active June 28, 2024 05:30
Redux-Thunk examples
// The classic AJAX call - dispatch before the request, and after it comes back
function myThunkActionCreator(someValue) {
return (dispatch, getState) => {
dispatch({type : "REQUEST_STARTED"});
myAjaxLib.post("/someEndpoint", {data : someValue})
.then(
response => dispatch({type : "REQUEST_SUCCEEDED", payload : response}),
error => dispatch({type : "REQUEST_FAILED", error : error})
);
"use strict";
// simple fisher yates implementation
const shuffle = (deck) => {
let randomizedDeck = [];
let array = deck;
while ( array.length !== 0) {
let rIndex = Math.floor(array.length * Math.random());
randomizedDeck.push(array[rIndex]);
array.splice(rIndex, 1)
}
@traviskaufman
traviskaufman / jasmine-this-vars.md
Last active September 19, 2022 14:35
Better Jasmine Tests With `this`

Better Jasmine Tests With this

On the Refinery29 Mobile Web Team, codenamed "Bicycle", all of our unit tests are written using Jasmine, an awesome BDD library written by Pivotal Labs. We recently switched how we set up data for tests from declaring and assigning to closures, to assigning properties to each test case's this object, and we've seen some awesome benefits from doing such.

The old way

Up until recently, a typical unit test for us looked something like this:

describe('views.Card', function() {