This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const http = require('http'); | |
const express = require('express'), | |
bodyParser = require('body-parser'), | |
uuid = require('uuidv4'), | |
cors = require('cors'); | |
const faker = require('faker'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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', () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); }); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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.'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); |
NewerOlder