Skip to content

Instantly share code, notes, and snippets.

View elliotlarson's full-sized avatar

Elliot Larson elliotlarson

View GitHub Profile
const characters = ["Walter", "Jeffrey", "Donald"];
const maude = "Maude";
const newCharacters = [...characters, "Maude"];
stateChanges.push(newCharacters);
// stateChanges:
// [
// ["Walter", "Jeffrey", "Donald"],
// ["Walter", "Jeffrey", "Donald", "Maude"],
// ]
characters.push("Maude");
stateChanges.push(characters);
// stateChanges:
// [
// ["Walter", "Jeffrey", "Donald", "Maude"],
// ["Walter", "Jeffrey", "Donald", "Maude"],
// ]
const stateChanges = [characters]; // start with the initial state
let characters = ["Walter", "Jeffrey", "Donald"];
@elliotlarson
elliotlarson / characters.spec.js
Created July 22, 2018 03:41
testing Redux characters file
import { reducer, actions } from "./characters";
it("creates a character", () => {
const newCharacter = { id: 42, firstName: "Jeffrey", lastName: "Lebowski" };
const action = actions.create(newCharacter);
const state = reducer(undefined, action);
expect(state.byId[42]).toEqual(newCharacter);
expect(state.allIds).toEqual([42]);
});
@elliotlarson
elliotlarson / immutable-operations.spec.js
Last active February 10, 2024 07:08
JavaScript Immutable Operations on Arrays and Objects
// This is a Jest spec that explores some of the different ways to alter
// arrays and objects without mutating state. I'm trying different approaches
// available using:
//
// * Vanilla JS
// * Immutable.js
// * Lodash
// * Rambda
//
// The motivation for this is largely to work with a Redux store.
require 'capybara'
require 'pry'
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end
Capybara.default_driver = :selenium
browser = Capybara.current_session
require('fileutils')
require('tempfile')
class AddRspec
def self.call
new.call
end
def call
spec_filepaths.each { |spec_filepath| process_file(spec_filepath) }
@elliotlarson
elliotlarson / class-vs-hash-bench.rb
Created August 14, 2017 20:43
Benchmarking class creation vs hash
require 'benchmark/ips'
class FooBar
attr_accessor :foo, :bar
def initialize(foo:, bar:)
self.foo = foo
self.bar = bar
end
end