In JavaScript, functions have arguments. We can name those arguments so that we can access the values we pass to those functions
function add(a, b) {
return a + b;
}
We can call these functions normally:
type ExtractValuesRecusrively<T> = T extends FormState<infer U> | |
? { [K in keyof U]: ExtractValuesRecusrively<U[K]> } | |
: T extends FieldState<infer V> | |
? V | |
: never; | |
// vs | |
type ExtractValuesRecusrively<State> = State extends FormState<infer InnerForm> | |
? { [FieldKey in keyof InnerForm]: ExtractValuesRecusrively<InnerForm[FieldKey]> } |
let types = ../types.dhall sha256:e48e21b807dad217a6c3e631fcaf3e950062310bfb4a8bbcecc330eb7b2f60ed | |
let defaults = ../defaults.dhall sha256:4450e23dc81975d111650e06c0238862944bf699537af6cbacac9c7e471dfabe | |
let deployment : types.Deployment = defaults.Deployment // { | |
metadata = defaults.ObjectMeta // { name = "nginx" }, | |
spec = Some ( defaults.DeploymentSpec // { | |
replicas = Some 2, | |
template = defaults.PodTemplateSpec // { | |
metadata = defaults.ObjectMeta // { |
import * as Lint from 'tslint'; | |
import * as ts from 'typescript'; | |
import { inspect } from 'util'; | |
/** | |
* This rule will ensure that methods marked with the "@expose" decorator must be declared in at | |
* least one interface implemented by the class. It will also ensure that the return type of this | |
* method has no excess properties compared to those specified in the interface | |
*/ |
type PromiseState<T> = { | |
state: 'fulfilled', value: T | |
} | {state: 'pending'} | {state: 'rejected', error: Error}; | |
let wm = new WeakMap<Promise<any>, PromiseState<any>>() | |
export function asyncCase<T, U>(promise: Promise<T>, handlers: { | |
pending?: () => U; | |
fulfilled?: (t: T) => U; |
/** | |
* Implementation of promise dialogs | |
*/ | |
import { observable, action } from 'mobx'; | |
import * as React from 'react'; | |
import { AppSingleton } from '@h4bff/core'; | |
import { AppContext } from '../router'; | |
import { observer } from 'mobx-react'; | |
interface Resolver<T> { |
/** | |
* Allocate a callback based resource, safely | |
* | |
* Example: | |
* function connectionResource(url) { | |
* return { acquire: async () => pg.connect(url), dispose: async conn => conn.dispose() } | |
* } | |
* usingPromise(connectionResource(process.env.DATABASE_URL), async conn => { | |
* await conn.query(...); | |
* do other things |
In JavaScript, functions have arguments. We can name those arguments so that we can access the values we pass to those functions
function add(a, b) {
return a + b;
}
We can call these functions normally:
{"output":{"equalizer":{"state":"true","num-bands":"6","input-gain":"-2","output-gain":"0","split-channels":"false","left":{"band0":{"type":"Bell","mode":"RLC (BT)","slope":"x1","solo":"false","mute":"false","gain":"-7.4","frequency":"222.0","q":"0.230"},"band1":{"type":"Bell","mode":"RLC (BT)","slope":"x1","solo":"false","mute":"false","gain":"4.0","frequency":"30.0","q":"0.470"},"band2":{"type":"Bell","mode":"RLC (BT)","slope":"x1","solo":"false","mute":"false","gain":"-2.2","frequency":"1686.0","q":"1.520"},"band3":{"type":"Bell","mode":"RLC (BT)","slope":"x1","solo":"false","mute":"false","gain":"2.0","frequency":"3090.0","q":"2.080"},"band4":{"type":"Bell","mode":"RLC (BT)","slope":"x1","solo":"false","mute":"false","gain":"-3.1","frequency":"6888.0","q":"1.000"},"band5":{"type":"Bell","mode":"RLC (BT)","slope":"x1","solo":"false","mute":"false","gain":"-1.1","frequency":"10550.0","q":"3.470"}},"right":{"band0":{"type":"Bell","mode":"RLC (BT)","slope":"x1","solo":"false","mute":"false","gain":"-7.4","fre |
import React, { useState, useEffect } from 'react'; | |
function useFriendStatus(friendID) { | |
const [isOnline, setIsOnline] = useState(null); | |
useEffect(() => { | |
function handleStatusChange(status) { | |
setIsOnline(status.isOnline); | |
} |
Testing database code is tricky. There seems to be a lack of resources on this topic (or I'm not looking at the right places). The resources I found so far focus on mocking the data access layer. This however is insufficient, as there are scenarios where it doesn't do what we want.
Most of the resources suggest mocking techniques. Mocking is a technique where we program an object to behave as if it were another object, without implementing the underlying mechanisms necessary to re-create the whole thing. For example, this is how we would mock a database access layer based on SQL queries.
We have the function createFriends which we want to test: