Skip to content

Instantly share code, notes, and snippets.

View kettanaito's full-sized avatar
🚀
Working on EpicWeb.dev

Artem Zakharchenko kettanaito

🚀
Working on EpicWeb.dev
View GitHub Profile
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');
/**
* 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
@kettanaito
kettanaito / heading-crossed.html
Created January 19, 2018 08:48
HTML: One-element crossed heading
<!--
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
@kettanaito
kettanaito / serialized.json
Created March 26, 2018 09:18
React Advanced Form - Field Group - Serialized
{
"primaryInfo": {
"userEmail": "...",
"firstName": "...",
"lastName": "...",
},
"userPassword": "..."
}
@kettanaito
kettanaito / RegistrationForm.jsx
Created March 26, 2018 09:20
React Advanced Form - Skipping a field
<Input
name="confirmPassword"
type="password"
required
skip />
@kettanaito
kettanaito / Cart.jsx
Last active March 28, 2018 15:12
React motion issue
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';
@kettanaito
kettanaito / index.js
Last active April 3, 2018 13:16
React Advanced Form - App
// 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}>
@kettanaito
kettanaito / RegistrationForm.jsx
Last active April 3, 2018 13:18
React Advanced Form - Async validation
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 */
@kettanaito
kettanaito / RegistrationForm.jsx
Last active April 3, 2018 13:18
React Advanced Form - Submit
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)
});
@kettanaito
kettanaito / validation-rules.js
Last active April 22, 2018 09:33
React Advanced Form - Validation rules
// 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)