Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View dfoverdx's full-sized avatar

Beth Hitch dfoverdx

View GitHub Profile
@dfoverdx
dfoverdx / async-database-client.js
Last active August 17, 2023 18:04
JavaScript/TypeScript Data Access Layer that automatically asserts the connection is ready, or waits for the connection to become ready
import Client from 'some-database-api';
import { connectionInfo } from './config';
class AsyncDatabaseClient {
constructor() {
this._connection = null;
this._initialized = Client.connect(connectionInfo).then(c => this.connection = c);
return new Proxy(this, {
get(target, prop, receiver) {
@dfoverdx
dfoverdx / touched-input.jsx
Created November 13, 2018 01:53
Reactstrap Input that doesn't validate or invalidate until the element has been touched
import React, { PureComponent } from 'react';
import { Input } from 'reactstrap';
/**
* A wrapper for reactstrap's Input which prevents the `invalid` and `valid` props from being displayed until the user
* has touched the input (via `onBlur`). Also handles setting `invalid` if it is not defined as a property, but
* other HTML5 input validation properties are (`pattern`, `required`, `min`, etc).
*/
export default class TouchedInput extends PureComponent {
constructor(props) {
@dfoverdx
dfoverdx / JavaScript Members Not Bound to Instances.md
Last active June 12, 2023 08:38
Why JavaScript class members are not automatically bound to the instance of the class

It took a few years, but I finally understand why member functions of classes in JavaScript aren't automatically bound to their objects, in particular when used in callback arguments.

In most object-oriented languages, functions are members of a class--they exist in memory only once, and when they are called, this is simply a hidden argument of the function which is assigned to the object that's calling it. Python makes this explicit by requiring that the first argument of a class's member function be self (Python's equivalent of this--you can name self whatever you want, but self is the convention).

class MyClass: