Testing TPT
Electron 24/01/2022
- login free
- login premium
- remember password
- not remember password
I recently run into a scenario highlighting that await
is not always a drop-in, better replacement for then
. Sometimes with then
it's easier to control the scope of the function that runs after the promise is settled. I have a Redux middleware-inspired example here:
https://codesandbox.io/s/eager-wildflower-1kodv?file=/src/index.js
In example 2, the next call will only happen after the promise resolves.
In example 3, the next will be called immediately.
const haveSameKeys = (objA, objB) => { | |
const keysOfA = Object.keys(objA) | |
const keysOfB = Object.keys(objB) | |
return keysOfA.length === keysOfB.length && | |
keysOfA.every(key => keysOfB.includes(key)) | |
} |
// @ts-check | |
const createRandomInteger = (limit) => Math.floor(Math.random() * limit) | |
const createRandomLetter = () => String.fromCharCode(97 + createRandomInteger(26)); | |
const positionLetter = (element) => { | |
element.style.width = '1vw' | |
element.style.height = '1vw' | |
element.style.lineHeight = '1vw' |
if (typeof handleTrackableClickEvent !== "function") { | |
var handleTrackableClickEvent = function(event) { | |
var trackableSelector = '.trackable'; | |
if (event.target) { | |
// msMatches is for IE | |
var matches = event.target.matches || event.target.msMatches; | |
if (matches && matches.call(event.target, trackableSelector)) { | |
var et = event.target; |
const isPrime = number => { | |
let divisor = 2 | |
while (divisor < number) { | |
if(number % divisor === 0) return false | |
divisor += 1 | |
} | |
return true | |
} | |
const findPrime = (timeLimitMS) => { |
// IDEA: start with an object using a symbol as a marker | |
const create = (obj, changeSet) => Object.assign(Object.create(obj || {[Symbol.for('versionstart')]: true}), changeSet); | |
const getPreviousState = obj => { | |
const maybePrev = Object.getPrototypeOf(obj); | |
if (!maybePrev || maybePrev[Symbol.for('versionstart')]) { | |
return null; | |
} | |
return maybePrev; | |
} |
// Given a list with data containing sequential property such as year of birth, age, size | |
// Create a graph containing elements groupped by that property with ids of next nodes | |
// Output example | |
{ | |
'1': {list: [{size: 1}, {size: 1}], previous: undefined, next: '3'}, | |
'3': {list: [{size: 3}], previous: '1', next: '4'}, | |
'4': {list: [{size: 4}], previous: '3', next: undefined}, | |
} |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
/* these are just to set up environment, you don't need them */ | |
html, body { | |
height: 100%; |
Array(999) | |
.fill(1) | |
.map((n, index) => n + index) | |
.filter(n => n % 3 === 0 || n % 5 === 0) | |
.reduce((a, b) => a + b) |