Skip to content

Instantly share code, notes, and snippets.

View client.render.js
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 */
View example
{
foo: "bar",
bar: "baz",
tmp: "test",
}
View example2
{
foo: "bar",
bar: "baz",
tmp: "test"
}
@smashercosmo
smashercosmo / main.js
Created Nov 3, 2015
Server hot reload
View main.js
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 Dec 27, 2015
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…
View index.html
<!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 Nov 27, 2013
Snippet to determine scrollbar width
View gist:7675442
/**
* 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 Apr 22, 2016
css-modules on server
View cssModulesConfig.js
'use strict';
const path = require('path');
const sassAndScssLoader = indentedSyntax => (
(source, filename) => require('node-sass').renderSync({
file: filename,
indentedSyntax
}).css
);
View injectDependecies.js
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
);
}
View store.js
const store = createStore(
reducer,
applyMiddleware(thunk.withExtraArgument({analytics, api}))
)
// later
function fetchUser(id) {
return (dispatch, getState, {analytics, api}) => {
api.fetchUser().then(user => {
analytics.track(...);
View user.actions.js
export function fetchUser(id) {
return (dispatch, getState, {analytics, api}) => {
return api.fetchUser().then(user => {
analytics.track(...);
})
}
}