Skip to content

Instantly share code, notes, and snippets.

Avatar
🎨
Building accessible UIs

Vitaly Kondratiev vitkon

🎨
Building accessible UIs
View GitHub Profile
@vitkon
vitkon / App.jsx
Created Feb 18, 2018
Poi article files
View App.jsx
const App = () => <div>
<h1>My App</h1>
</div>
export default App;
@vitkon
vitkon / poi.config.js
Created Feb 18, 2018
Poi article files
View poi.config.js
module.exports = {
presets: [
require('poi-preset-react')(),
]
}
@vitkon
vitkon / index.js
Last active Feb 18, 2018
Poi article
View index.js
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 Dec 22, 2017 — forked from pranavrajs/travis.yml
Travis Config to deploy Frontend to S3 , Invalidate Cache
View travis.yml
sudo: required
dist: trusty
language: node_js
node_js:
- "6.9.0"
python:
- "3.5"
cache:
- pip
- yarn
View typescript-react.md

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);
View mixin-typescript
import { EventEmitter2 } from 'eventemitter2';
class Core extends EventEmitter2 {
constructor() {
super();
this.init();
}
init() {
console.log('initialised');
@vitkon
vitkon / validation.ts
Created Oct 6, 2017
Validation with TS Generics
View validation.ts
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 Aug 17, 2017
Coding best practices
View best-practices.md

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 Jun 7, 2017
Long polling with web workers
View webWorker.js
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
Simple object to object mapper
View SimpleMapper.js
const _ = require('lodash');
class SimpleMapper {
constructor(data) {
this.data = _.cloneDeep(data);
this.mappings = [];
this.result = {};
}
addMapping(destination, source, transform = v => v) {