Skip to content

Instantly share code, notes, and snippets.

View smashercosmo's full-sized avatar

Vladislav Shkodin smashercosmo

View GitHub Profile
import React from 'react';
import Router from 'react-router';
import routes from './routes';
import { createStore, combineReducers } from 'redux';
import { Provider } from 'react-redux';
import intlReducer from './intl/intl.reducer'
const app = document.getElementById('app');
/** initalState contains very complicated object with all translations */
@smashercosmo
smashercosmo / example
Last active September 10, 2015 14:28
{
foo: "bar",
bar: "baz",
tmp: "test",
}
{
foo: "bar",
bar: "baz",
tmp: "test"
}
@smashercosmo
smashercosmo / main.js
Created November 3, 2015 22:32
Server hot reload
import imports from './imports'; // <-- all your imports
import express from 'express';
const app = express();
if (__DEVELOPMENT__) require('./serverHotReload')(app, () => {
try {
imports = require('./imports');
} catch (error) {
console.log(error.stack)
@smashercosmo
smashercosmo / index.html
Last active December 27, 2015 04:09
Quick implementation of angular's $route.reload() with ui-router. Ui-router has it's own $state.reload function, but it's behaviour differs from angular's. For example it can't reload a route (state) if it wasn't actually loaded. In this gist I use $locationChangeStart event to prevent route from being loaded, but then I reload it after 2 sec de…
<!DOCTYPE html>
<html ng-app="app">
<head>
<script src="http://code.angularjs.org/1.2.0-rc.2/angular.js"></script>
<script src="http://angular-ui.github.io/ui-router/release/angular-ui-router.min.js"></script>
</head>
<body>
<div ui-view></div>
@smashercosmo
smashercosmo / gist:7675442
Created November 27, 2013 13:15
Snippet to determine scrollbar width
/**
* Simple function to determine scrollbar width.
* Extracted from JqueryUI source and changed to get rid
* of jQuery dependency.
*/
function getScrollBarWidth() {
var w1, w2,
div = document.createElement('div'),
inner = document.createElement('div');
@smashercosmo
smashercosmo / cssModulesConfig.js
Last active April 22, 2016 12:21
css-modules on server
'use strict';
const path = require('path');
const sassAndScssLoader = indentedSyntax => (
(source, filename) => require('node-sass').renderSync({
file: filename,
indentedSyntax
}).css
);
const injectMiddleware = (staticDeps, dynamicDeps) => ({ dispatch, getState }) => next => action => {
const deps = {...staticDeps};
Object.keys(dynamicDeps).forEach(key => {
deps[key] = dynamicDeps[key]();
});
return next(typeof action === 'function'
? action({ ...deps, dispatch, getState })
: action
);
}
const store = createStore(
reducer,
applyMiddleware(thunk.withExtraArgument({analytics, api}))
)
// later
function fetchUser(id) {
return (dispatch, getState, {analytics, api}) => {
api.fetchUser().then(user => {
analytics.track(...);
export function fetchUser(id) {
return (dispatch, getState, {analytics, api}) => {
return api.fetchUser().then(user => {
analytics.track(...);
})
}
}