Skip to content

Instantly share code, notes, and snippets.

@webpapaya
webpapaya / refucktoring.js
Last active April 1, 2019 10:05
Exercise we did at the FHS.
var PINS = 0
const strike = 10;
class _pins {
constructor(wert) {
this.v = wert
}
}
class BowlingGame {

First level

Filter all names by their first character of the given array.

["Hans", "Mike", "Fabian", "Anna"]
  • "H" returns ["Hans"]
  • "M" returns ["Mike"]
  • "F" returns ["Fabian"]
@webpapaya
webpapaya / prepare_react_props.js
Last active February 21, 2017 17:31
Prepare react props before pushing them to a child
// Executes the given fn with the props and applies the result to the component
const prepareProps = (fn) => (Component) => (props) => {
return <Component { ...fn(props) } />
};
const _Child = ({ test }) => {
return (
<div>
{ test /* rendered as "MY PROPERTY" */ }
</div>
const queue = new PromiseQueue();
const anotherTask = () => { /* do something fancy */ };
const errorTask = () => { /* do something fancy */ };
const myApiCall1 = () => Promise.resolve()
.then(() => { queue.push(anotherTask) })
.catch(() => { queue.push(errorTask) })
queue.resolve().then((results) => {
console.log(results);
import { queue, retry } from 'promise-frites';
const myApiCall1 = () => Promise.resolve()
.then(() => { /* call server */ })
.then(() => { /* notify user */})
.then(() => { /* call server again */ })
.then(() => { /* notify user again */});
const myApiCall2 = () => Promise.resolve()
.then(() => { /* call server */ })
// 75: Promise - basics
// To do: make all tests pass, leave the assert lines unchanged!
function succeedingApiCall() {
return Promise.resolve('200');
}
function failingApiCall() {
return Promise.reject('500');
}
const waitAtLeast1Second = waitAtLeast(1);
const apiCall = Promise.resolve('my api data');
Promise.resolve()
.then(waitAtLeast1Second(apiCall))
.then((data) => data === 'my api data');
import React from 'react';
import ReactDOM from 'react-dom';
import { waitAtLeast } from 'promise-frites';
//...
class SignInScreen extends React.Component {
state = {
isLoading: false,
loadingText: "Please wait",
}
import React from 'react';
import ReactDOM from 'react-dom';
import { waitAtLeast } from 'promise-frites';
//...
class SignInScreen extends React.Component {
state = {
isLoading: false
}
render() {
import React from 'react';
import ReactDOM from 'react-dom';
const createActions = () => {
const signIn = () => new Promise((resolve) => {
setTimeout(resolve, 1000)
});
return { signIn };
};