Skip to content

Instantly share code, notes, and snippets.

View b2whats's full-sized avatar
🎯
Focusing

Akimov Vladimir b2whats

🎯
Focusing
View GitHub Profile
@b2whats
b2whats / pipeline.js
Last active June 13, 2016 17:55
pipeline
const pipeline = [
array => { array.pop(); return array; },
array => array.reverse()
];
pipeline.reduce((xs, f) => f(xs), [1, 2, 3]);
// server/index.js
require('babel-register')
const universalHook = require('./universal-hook').default
const webpackDev = require('../../webpack/webpack.config.dev').default
const config = require('../../webpack/config').default
universalHook(webpackDev, config)
require('./server')
@b2whats
b2whats / webpack.config.js
Created June 3, 2016 23:59
webpack config
const webpack = require('webpack')
const path = require('path')
const HTMLWebpackPlugin = require('html-webpack-plugin')
const config = require('./config')
const vendor = [
'react',
'react-dom',
'react-router',
'redux',
@b2whats
b2whats / protips.js
Created May 6, 2016 21:02 — forked from nolanlawson/protips.js
Promise protips - stuff I wish I had known when I started with Promises
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");
@b2whats
b2whats / js
Created May 2, 2016 13:18
universal
import {readFileSync} from 'fs';
import {hook} from 'node-hook';
import {interpolateName} from 'loader-utils';
import { webpackConfig, webpackStatsFile } from '../config';
function readStats() {
const stats = require(webpackStatsFile);
@b2whats
b2whats / How_Require_Extensions_Work.md
Created April 29, 2016 00:25 — forked from jamestalmage/How_Require_Extensions_Work.md
Breakdown of How Require Extensions Work

Why

Doing require extensions correctly is essential, because:

  1. Users should be able to install multiple extensions in succession, and have them work together.
  2. Coverage tools like nyc need it to reliably supply coverage information that takes into account sourcemaps from upstream transforms.
  3. Because non-standard, un-predictable behavior causes hard to solve bugs, and major headaches for project maintainers.

What is a require extension anyways?

@b2whats
b2whats / React-universal-structure.md
Created April 29, 2016 00:24 — forked from zeakd/React-universal-structure.md
react universal structure with ignore pattern - render for client only components

react universal application - Ignore pattern

In React universal application, there is problem when render client-side only components like Devtools, fetching components and webpack style require (require css) Two solution for this.

dynamic module import isomorphic500

check js is running on browser

server side build

use webpack also on serverside, or if you are using requirejs, you can map client modules to null

But serverside build look like overkill to me, I choose dynamic module import. However in es6, import doesn't support dynamic import. So you should use commonjs require for it.

@b2whats
b2whats / expression-only.md
Created April 13, 2016 23:16 — forked from DmitrySoshnikov/expression-only.md
ES: Expression only

"Everything is an expression"... since ES1?

Many languages support "expression-only" semantics, allowing to use any construct in an expression position.

NOTE: the difference between expressions and statements is that the former produce a value, while the later don't.

For example, Ruby's if-expression:

x = 10
@b2whats
b2whats / recursion.js
Created April 13, 2016 23:13 — forked from bendc/recursion.js
Functional loop
const loop = (() => {
const recur = (callback, count, i=0) => {
if (i == count-1) return callback(i);
callback(i);
return recur(callback, count, i+1);
};
return (callback, count) => {
if (count > 0) return recur(callback, count);
};
})();
/* jshint esnext:true */
// native generators
function* random() {
var i = 0;
while(i++ < 1e5) {
yield Math.random();
}
}