Skip to content

Instantly share code, notes, and snippets.

@gaearon
gaearon / prepack-gentle-intro-1.md
Last active March 14, 2026 03:25
A Gentle Introduction to Prepack, Part 1

Note:

When this guide is more complete, the plan is to move it into Prepack documentation.
For now I put it out as a gist to gather initial feedback.

A Gentle Introduction to Prepack (Part 1)

If you're building JavaScript apps, you might already be familiar with some tools that compile JavaScript code to equivalent JavaScript code:

  • Babel lets you use newer JavaScript language features, and outputs equivalent code that targets older JavaScript engines.

Side Effects

A few of the Enzyme examples show using a class method of a component, but instead of using the instance() function to get the class instance and test the method's return value, instead they simulate events, then check the side effects of those events called from the method you want to test.

In the below example, unit test coverage will say the Failure part of the onNameBlur method was covered.

AddUser.js

class AddUserForm extends React.Component {
@stevekinney
stevekinney / web-performance.md
Last active September 6, 2026 08:25
Web Performance Workshop

Web Performance

Requirements

Repositories

@trueadm
trueadm / adopt-syntax.js
Last active November 27, 2021 03:32
Adding a the "adopt" keyword to the JSX syntax
// I'm suggesting we add a new "adopt X from <Y />" syntax to the JSX language
// it would de-sugar to render prop children, but look and read better than
// what we currently have. For example:
// 1.
// this sugar
function MyComponent(props) {
adopt foo from <Bar />;
return <div>{foo}</div>;
}
@kentcdodds
kentcdodds / object.entries.js
Last active November 7, 2020 23:36
Example of using Object.entries
// http://www.dogbreedchart.com
const dogShedding = {
foxhound: 3,
'basset hound': 2,
beagle: 3,
'bernese mountain dog': 1,
poodle: 5,
}
// 🔥🔥
@cklanac
cklanac / challenge-09-many-to-many.md
Last active June 26, 2024 18:32
Challenge 09: KnexJS with Many-to-Many

Noteful Challenge - Many-to-Many

In this challenge you will create a tags and notes_tags table which will setup a many-to-many relationship between notes and tags. You'll also create a new router to perform CRUD operations on the tags, and update the existing notes endpoints to work with tag related data.

Requirements

Add tags and notes_tags table and relationships

To get started, let's update the .sql script from the previous challenges. Create a tags table and define 2 fields in the schema.

class DynamicForm extends React.Component {
constructor(props) {
super(props);
this.state = {
education: [
{ name: '', start: '', end: '' },
]
}
}
@mikaelbr
mikaelbr / hocs.md
Last active January 31, 2018 00:25

Higher Order Components vs Higher Order Functions operating on Components (HoFooC™)

A higher order function would be a function taking a function as input, or returning a function. Such as:

function logger (fn) {
  return function (...args) {
    console.log('Invoking with', ...args);
 return fn(...args);
@ntamvl
ntamvl / install-multiple-jdk-on-macos-high-sierra.md
Last active February 19, 2025 16:29
Install Multiple Java Versions on macOS High Sierra

Install Multiple Java Versions on macOS High Sierra

Install Homebrew Cask

On Mac, Homebrew is the de-facto package manager, and Homebrew Cask is the app manager. I’m going to use Cask to install Java 7 and 8.

Install Homebrew Cask first if you haven’t:

brew update
brew tap caskroom/cask