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 / App.jsx
Last active April 8, 2023 11:13
A draft for "withModal" HOC to allow easy modals in React.
/* App.jsx */
import React from 'react';
import EmailChange from './EmailChange';
import ConfirmationModal from './ConfirmationModal';
export default class App extends React.Component {
render() {
return (
<EmailChange />
<ConfirmationModal />
@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 / RegistrationForm.jsx
Last active April 22, 2018 11:05
React Advanced Form - Registration Form
// src/app/RegistrationForm.jsx
import React from 'react';
import { Form } from 'react-advanced-form';
import { Input } from '...';
export default class RegistrationForm extends React.Component {
render() {
return (
<Form>
<Input
@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)
@kettanaito
kettanaito / validation-messages.js
Last active May 13, 2018 10:16
React Advanced Form - Validation messages
// app/validation-messages.js
export default {
generic: {
missing: 'Please provide the required field',
invalid: 'The value you have provided is invalid'
},
type: {
email: {
missing: 'Please provide the e-mail',
@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 / serialized.json
Created March 26, 2018 09:18
React Advanced Form - Field Group - Serialized
{
"primaryInfo": {
"userEmail": "...",
"firstName": "...",
"lastName": "...",
},
"userPassword": "..."
}
@kettanaito
kettanaito / RegistrationForm.jsx
Last active April 22, 2018 11:06
React Advanced Form - Field group
// src/app/RegistrationForm.jsx
import React from 'react';
import { Form, Field } from 'react-advanced-form';
import { Input } from '...';
export default class RegistrationForm extends React.Component {
render() {
<Form>
<Field.Group name="primaryInfo">
<Input