Skip to content

Instantly share code, notes, and snippets.

View reneviering's full-sized avatar

René Viering reneviering

View GitHub Profile
import React, { useEffect, useRef } from 'react';
import { useBooleanState } from './useBooleanState';
import { PopoverTrigger } from './PopoverTrigger';
import { PopoverContent } from './PopoverContent';
import { PopoverContext } from './PopoverContext';
const ESC_KEY = 27;
const Popover = ({ children }) => {
const [isOpen, closePopover, togglePopover] = useBooleanState(false);
@reneviering
reneviering / app.js
Last active May 16, 2018 10:15
Simple node app for a simple address management example app. Simple CRUD routes, addresses are stored in-memory. It also uses faker to fake an amount of addresses definable via query parameter.
'use strict';
const http = require('http');
const express = require('express'),
bodyParser = require('body-parser'),
uuid = require('uuidv4'),
cors = require('cors');
const faker = require('faker');
@reneviering
reneviering / react-hoc-domain.js
Last active October 22, 2017 08:34
Simple Domain Object to hold simple application state in react.
// Higher order component to connect the Domain to the component
const connectDomainToComponent = (WrappedComponent, Domain) => {
return class extends React.Component {
constructor() {
super();
this.domain = new Domain();
if (typeof(this.domain.getState) !== 'function') throw new Error('There is no function getState(…)')
const initialState = this.domain.getState();
if (typeof(initialState) !== 'object') throw new Error('The domain state has to be an object');
// 79: Promise - catch
// To do: make all tests pass, leave the assert lines unchanged!
// Here we use promises to trigger, don't modify the block with the
// returning promise!
describe('`catch()` returns a Promise and deals with rejected cases only', () => {
describe('prerequisites for understanding', () => {
it('*return* a fulfilled promise, to pass a test', () => {
// 78: Promise - API overview
// To do: make all tests pass, leave the assert lines unchanged!
describe('`Promise` API overview', function() {
it('`new Promise()` requires a function as param', () => {
const param = () => {};
assert.doesNotThrow(() => { new Promise(param); });
});
// 77: Promise - chaining
// To do: make all tests pass, leave the assert lines unchanged!
describe('chaining multiple promises can enhance readability', () => {
describe('prerequisites for understanding', function() {
it('reminder: the test passes when a fulfilled promise is returned', function() {
return Promise.resolve('I should fulfill.');
});
// 76: Promise - creation
// To do: make all tests pass, leave the assert lines unchanged!
describe('a promise can be created in multiple ways', function() {
describe('creating a promise fails when', function() {
it('using `Promise` as a function', function() {
function callPromiseAsFunction() {
Promise();
// 75: Promise - basics
// To do: make all tests pass, leave the assert lines unchanged!
describe('a Promise represents an operation that hasn`t completed yet, but is expected in the future', function() {
it('`Promise` is a global function', function() {
const expectedType = 'function';
assert.equal(typeof Promise, expectedType);
});
// 74: String - `endsWith()`
// To do: make all tests pass, leave the assert lines unchanged!
describe('`str.endsWith(searchString)` determines whether `str` ends with `searchString`.', function() {
const s = 'el fin';
describe('1st parameter, the string to search for', function() {
it('works with just a character', function() {
const doesEndWith = s.endsWith('n');