Skip to content

Instantly share code, notes, and snippets.

View vitkon's full-sized avatar
🎨
Building accessible UIs

Vitaly Kondratiev vitkon

🎨
Building accessible UIs
View GitHub Profile
@vitkon
vitkon / App.jsx
Created February 18, 2018 21:59
Poi article files
const App = () => <div>
<h1>My App</h1>
</div>
export default App;
@vitkon
vitkon / poi.config.js
Created February 18, 2018 21:54
Poi article files
module.exports = {
presets: [
require('poi-preset-react')(),
]
}
@vitkon
vitkon / index.js
Last active February 18, 2018 21:58
Poi article
import React from 'react';
import { render } from 'react-dom';
import App from './App.jsx';
render(<App />, document.getElementById('app'));
@vitkon
vitkon / travis.yml
Last active December 22, 2017 18:59 — forked from pranavrajs/travis.yml
Travis Config to deploy Frontend to S3 , Invalidate Cache
sudo: required
dist: trusty
language: node_js
node_js:
- "6.9.0"
python:
- "3.5"
cache:
- pip
- yarn
@vitkon
vitkon / typescript-react.md
Created November 15, 2017 10:49
Typescript React

Component as an argument in a function

new () => React.Component<any, any>

// example
export const addValidatedFormContainer = (validators: any[] = []) =>
    (component: new () => React.Component<any, any>) => flow(
        validate(validators),
        makeWrapper()
 )(component);
@vitkon
vitkon / mixin-typescript
Created November 6, 2017 22:48
Typescript mixin
import { EventEmitter2 } from 'eventemitter2';
class Core extends EventEmitter2 {
constructor() {
super();
this.init();
}
init() {
console.log('initialised');
@vitkon
vitkon / validation.ts
Created October 6, 2017 22:00
Validation with TS Generics
function isRequired<T extends string> (prop: T, message: string = `${prop} is a required field`) {
return [
(model: { [name in T]: any }) => !!model[prop],
{ [prop as string]: message }
];
}
interface Foo {
price: 123;
desc: 'foo';
@vitkon
vitkon / best-practices.md
Created August 17, 2017 10:29
Coding best practices

Don't test private methods

You generally don't unit test private methods directly. Since they are private, consider them an implementation detail. Nobody is ever going to call one of them and expect it to work a particular way. You should instead test your public interface. If the methods that call your private methods are working as you expect, you then assume by extension that your private methods are working correctly.

@vitkon
vitkon / webWorker.js
Created June 7, 2017 22:58
Long polling with web workers
function workerFunction() {
this.addEventListener('message', (e) => {
console.log('log2: ', e);
fetchUrl(e.data);
})
const fetchUrl = (url) => {
fetch(url)
.then((response) => {
console.log(response);
@vitkon
vitkon / SimpleMapper.js
Created May 10, 2017 23:41
Simple object to object mapper
const _ = require('lodash');
class SimpleMapper {
constructor(data) {
this.data = _.cloneDeep(data);
this.mappings = [];
this.result = {};
}
addMapping(destination, source, transform = v => v) {