Skip to content

Instantly share code, notes, and snippets.

View dbismut's full-sized avatar
🏠
Working from home

David Bismut dbismut

🏠
Working from home
View GitHub Profile
@dbismut
dbismut / serve.js
Last active September 6, 2015 10:21
serve.js updated for automatic server restart on React-Starter-Kit based on https://github.com/kriasoft/react-starter-kit/blob/ebbce5aed8f3efa9315abaec302cd1060d609a95/gulpfile.babel.js#L115-L137
/**
* React Starter Kit (http://www.reactstarterkit.com/)
*
* Copyright © 2014-2015 Kriasoft, LLC. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
import path from 'path';
@dbismut
dbismut / style.import.css
Last active December 2, 2015 09:20
Webpack with postcss-cssnext
@import "./variables.import";
.box {
background: var(--yellow);
}
@dbismut
dbismut / actionTypeBuilder.js
Last active January 25, 2022 09:02
React Redux Meteor middlewares
export function actionTypeBuilder(prefix) {
return {
type: actionType => `${prefix}/${actionType}`,
loading: actionType => `${actionType}/loading`,
ready: actionType => `${actionType}/ready`,
stopped: actionType => `${actionType}/stopped`,
changed: actionType => `${actionType}/changed`,
error: actionType => `${actionType}/error`,
success: actionType => `${actionType}/success`
};
@dbismut
dbismut / webpack.conf.js
Last active March 3, 2016 20:27
Webpack config
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var babelSettings = { presets: ['react', 'es2015', 'stage-0'] };
babelSettings.plugins = ['transform-decorators-legacy'];
if (process.env.NODE_ENV !== 'production' && !process.env.IS_MIRROR) {
babelSettings.plugins.push(['react-transform', {
transforms: [{
transform: 'react-transform-hmr',
@dbismut
dbismut / index.jsx
Last active April 18, 2016 16:19
ReactRouterSSR
// server/index.jsx
import React from 'react';
/* don't pay attention to the 3 lines below */
import { Provider } from 'react-redux';
import { syncHistoryWithStore } from 'react-router-redux';
import { configureStore } from 'common/client/redux/store/';
import {
@dbismut
dbismut / routes.js
Last active April 9, 2018 07:48
Part 1 - Defining routes
import posts from './postData';
export default [
{
name: 'home',
path: '/',
onActivate: () =>
Promise.resolve({
posts: posts.map(({ content, ...rest }) => rest)
})
@dbismut
dbismut / postData.js
Last active April 9, 2018 07:48
Part 1 - Faking the data
export default [
{
id: '1',
image: 'zlatan.jpg',
title: 'Zlatan Ibrahimovic',
content: `Zlatan Ibrahimović is a Swedish professional footballer who plays as a forward for LA Galaxy. He was also a member of the Sweden national team from 2001 to 2016, serving as captain from 2010 until his retirement. Primarily a striker, he is a prolific goalscorer, who is best known for his technique, creativity, strength, ability in the air, and his powerful and accurate striking ability. He is currently the second-most decorated active footballer in the world, having won 32 trophies in his career.`
},
{
id: '2',
image: 'messi.jpg',
@dbismut
dbismut / dataMiddleware.js
Last active April 9, 2018 07:48
Part 1 - The data middleware that will fetch the data
import transitionPath from 'router5-transition-path';
export default routes => router => (toState, fromState) => {
const { toActivate } = transitionPath(toState, fromState);
const onActivateHandlers = toActivate
.map(segment =>
routes.find(r => r.name === segment).onActivate(toState.params)
)
.filter(Boolean);
@dbismut
dbismut / router.js
Last active April 9, 2018 07:49
Part 1 - Creating router5 router
import createRouter from 'router5';
import browserPlugin from 'router5/plugins/browser';
import loggerPlugin from 'router5/plugins/logger';
export default function configureRouter(routes, options = {}) {
const router = createRouter(routes, options)
// Plugins
.usePlugin(browserPlugin({ useHash: false }));
if (process.env.NODE_ENV === 'development') router.usePlugin(loggerPlugin);
@dbismut
dbismut / store.js
Last active April 9, 2018 07:49
Part 1 - Creating the redux store
import { applyMiddleware, compose, createStore } from 'redux';
import { router5Middleware } from 'redux-router5';
import { createLogger } from 'redux-logger';
import rootReducer from './actions';
const enhancers = [];
if (process.env.NODE_ENV === 'development') {
const devToolsExtension = window.devToolsExtension;