Skip to content

Instantly share code, notes, and snippets.

View mistadikay's full-sized avatar

Denis Koltsov mistadikay

View GitHub Profile
import React from 'react';
class Popup extends React.Component {
render() {
return (
<div className={'popup' + (this.props.visible ? ' popup_visible' : '')}>
<div className="popup__overlay"></div>
<div className="popup__content">{this.props.children}</div>
</div>
);
import React, { Component } from 'react';
import DataWatcher from 'components/@data-watcher';
const sortTypes = [ 'asc', 'desc' ];
@DataWatcher
class ProductsList extends Component {
static displayName = 'ProductsList';
static data = (props, state) => ({
// in data dependency besides cursor path
import { Component } from 'react';
// Flux action creators for products
import ProductsActions from 'actions/products';
// global state
import state from 'state';
// main wrapper component
class App extends Component {
@mistadikay
mistadikay / product.es6
Last active August 29, 2015 14:25
Declarative data fetching in React components with Baobab
import { Component } from 'react';
import DataWatcher from 'components/@data-watcher';
// DataWatcher decorator watches data paths described below
// and updates local state whenever global state changes something in these paths
@DataWatcher
class Product extends Component {
static displayName = 'Product';
// data paths can be static or they can contain props and states
@mistadikay
mistadikay / index.js
Created May 13, 2015 09:36
flux in ES7 by @roman01la
function example(){
class Actions {
@Observable
static processSomething
}
class Store {
constructor(name){
this.name = name;
@mistadikay
mistadikay / index.scss
Created May 3, 2015 15:55
Fun with line-height
$lh: 1.4em;
body {
font-size: 1em;
line-height: $lh;
}
h1 {
background: #333;
margin: 0;
let mergeSort = (arr) => {
if (arr.length < 2) return arr;
let middle = parseInt(arr.length / 2),
left = arr.slice(0, middle),
right = arr.slice(middle);
return merge(mergeSort(left), mergeSort(right));
}
var selectionSort = function (a) {
for (let i = -1; ++i < a.length;) {
for (let m = j = i; ++j < a.length;) {
if (a[m] > a[j]) m = j;
}
a[m], a[i] = a[i], a[m];
}
return a;
}
let insertionSort = (arr) => {
for (let i = 0; i < a.length; i++) {
let toCmp = arr[i];
for (let j = i; j > 0 && toCmp < a[j - 1]; j--)
arr[j] = a[j - 1];
arr[j] = toCmp;
}
return arr;
}
let compare = (n1, n2) => n1 - n2;
let bubbleSort = (arr, cmp = compare) => {
for (let i = 0; i < arr.length; i++) {
for (var j = i; j > 0; j--) {
if (cmp(arr[j], arr[j - 1]) < 0) {
arr[j], arr[j - 1] = arr[j - 1], arr[j];
}
}
}