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
const statusCodes = { | |
success: 200, | |
error: 400, | |
}; | |
function all(promises) { | |
const transformedPromises = promises.map(promise => promise.then((result) => { | |
if (result.payload.statusCode !== statusCodes.success) { | |
throw new Error('PROMISE RESOLVED TO FAILURE! SHOULD FAIL THIS CHAIN TO SHREDS'); |
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
/** | |
* Promise sequence | |
* @description Handles the sequence of Promise. | |
* @param {Array<Function: Promise>} promises Collection of functions which should return instance of Promise. | |
* @return {Promise} | |
*/ | |
function PromiseSeq(promises) { | |
return promises.reduce((promisesPool, promise) => | |
promisesPool.then((result) => { | |
/* Explicitly check if function (returning promise), since you can pass {true} to it |
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
<!-- | |
One-element way of doing this kind of headings: | |
---------------- Text here ---------------- | |
* One HTML tag only | |
* Background-independant | |
* Properly centered horizontally and vertically | |
* Same browsers support as for flexbox |
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
{ | |
"primaryInfo": { | |
"userEmail": "...", | |
"firstName": "...", | |
"lastName": "...", | |
}, | |
"userPassword": "..." | |
} |
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
<Input | |
name="confirmPassword" | |
type="password" | |
required | |
skip /> |
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 from 'react'; | |
import PropTypes from 'prop-types'; | |
import { Helmet } from 'react-helmet'; | |
import { connect } from 'react-redux'; | |
import { addItem, removeItem } from '@state/cart/actions'; | |
import { getTotalPrice } from '@state/cart/selectors'; | |
import { Grid, Box, Button } from '@client/components'; | |
/* Components */ | |
import CartItemsList from './components/CartItemsList'; |
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
// app/index.js | |
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { FormProvider } from 'react-advanced-form'; | |
import rules from './validation-rules'; | |
import messages from './validation-messages'; | |
import Root from './Root'; | |
const renderApp = () => ( | |
<FormProvider rules={rules} messages={messages}> |
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 from 'react'; | |
import { Form } from 'react-advanced-form'; | |
export default class RegistrationForm extends React.Component { | |
validateEmail = ({ value, fieldProps, fields, form }) => { | |
return fetch('https://backend/', { body: value }) | |
.then(res => res.json()) | |
.then((res) => { | |
return { | |
/* Determine if the e-mail is valid based on response */ |
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 from 'react'; | |
import { Form } from 'react-advanced-form'; | |
import { Input } from '...'; | |
export default class RegistrationForm extends React.Component { | |
registerUser = ({ serialized, fields, form }) => { | |
return fetch('https://backend.dev/user', { | |
method: 'POST', | |
body: JSON.stringify(serialized) | |
}); |
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
// src/app/validation-rules.js | |
import isEmail from 'validator/lib/isEmail'; | |
export default { | |
type: { | |
email: ({ value }) => isEmail(value), | |
password: { | |
capitalLetter: ({ value }) => /[A-Z]/.test(value), | |
oneNumber: ({ value }) => /[0-9]/.test(value), | |
minLength: ({ value }) => (value.length > 5) |
OlderNewer