Skip to content

Instantly share code, notes, and snippets.

View maximgatilin's full-sized avatar

Maxim Gatilin maximgatilin

  • @hh.ru
View GitHub Profile
@maximgatilin
maximgatilin / serega.js
Created November 25, 2022 14:01
public_serega
const collections = [
{name: 'Favorite', id:1},
{name: 'Trillers', id:2},
{name: 'Horrors', id:3},
{name: 'Comedies', id:4},
]
const mapping = [
{ collectionId: 1, filmId: 'aaa'},
{ collectionId: 3, filmId: 'asasas'},
@maximgatilin
maximgatilin / docFrag.js
Last active August 20, 2020 02:12
Document fragment with jQuery
var documentFragment = $(document.createDocumentFragment());
for (var i = 0; i < 5; ++i) {
var span = $('<span>' + i + '</span>');
documentFragment.append(span);
}
console.info(documentFragment);
$('#result').append(documentFragment);
// Более легкий способ
var htmlStr = '';
@maximgatilin
maximgatilin / middleware.js
Created July 4, 2019 10:55
react router v4 middleware
import { push, replace } from 'connected-react-router';
export default store => next => action => {
if (action.pushToUrl) {
const state = store.getState();
const currentQueries = new URLSearchParams(state.router.location.search);
Object.entries(action.pushToUrl).forEach(([key, value]) => {
currentQueries.set(key, value);
});
@maximgatilin
maximgatilin / pomnu.gulp
Created August 26, 2018 10:19
Я помню первый галп-конфиг...
Я помню первый галп-конфиг,
То бы не просто инструмент.
Как будто что-то я постиг,
Ворвался во всеобщий тренд.
Прощай консольный компилятор sass,
Прощай рутинный спрайто-генератор,
Прощай дублированный html-каркас,
Ведь есть теперь шаблонизатор.
import {
CHANGE_USERS_AGE_FILTER,
} from '../actions/actionTypes';
import users from '../../mockData/users';
import {getMaxVal, getMinVal, getValueFromUrl} from '../../utils/functions';
const minAge = getMinVal(users, 'age');
const maxAge = getMaxVal(users, 'age');
const minAgeFilter = getValueFromUrl('users.minAge');
const minAgeFilter = getValueFromUrl('users.minAge');
import {browserHistory} from 'react-router';
export function getValueFromUrl(input) {
const [pathname, prop] = input.split('.');
const currentLocation = browserHistory.getCurrentLocation();
if (currentLocation.pathname !== `/${pathname}`) {
return null;
}
import {replace} from 'react-router-redux';
export default store => next => action => {
if (action.pushToUrl) {
const state = store.getState();
store.dispatch(replace({
pathname: state.routing.locationBeforeTransitions.pathname,
query: {
...state.routing.locationBeforeTransitions.query,
case LOCATION_CHANGE:
if (action.payload.pathname === '/products') {
return {
...state,
productsPage: action.payload.query.page || state.productsPage
}
} else if (action.payload.pathname === '/users') {
return {
...state,
usersPage: action.payload.query.page || state.usersPage
@maximgatilin
maximgatilin / reducer.js
Last active August 8, 2018 05:39
Bad reducer
import {LOCATION_CHANGE} from 'react-router-redux';
const initialState = {
timeFilter: '1M'
};
export const exampleReducer = (state = initialState, action) => {
switch (action.type) {
case LOCATION_CHANGE:
return {