This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class createStore { | |
constructor(state, actions) { | |
this._currentState = state | |
this._currentActions = actions | |
this._currentListener = null | |
return { | |
getState: this.getState.bind(this), | |
dispatch: this.dispatch.bind(this), | |
subscribe: this.subscribe.bind(this) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Your babelrc configuration | |
BABEL='{"parsets": ["react", "es2015", "stage-0"]}' | |
# Your github remote url | |
GIT_REMOTE='Your git url' | |
npm install --save-dev react react-dom babel babel-core babel-loader babel-plugin-transform-decorators-legacy babel-preset-es2015 babel-preset-react babel-preset-stage-0 webpack webpack-dev-server | |
# .babelrc file | |
echo ${BABEL} >> .babelrc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function ({types: t}) { | |
return { | |
visitor: { | |
ClassDeclaration(path) { | |
const { node } = path | |
const renderMethod = node.body.body.filter((method) => method.key.name === 'render') | |
const returnStatement = t.returnStatement(renderMethod[0].body.body[0].argument) | |
let jsxChildren = renderMethod[0].body.body[0].argument.children | |
jsxChildren = jsxChildren.map((children) => { | |
if(children.type === 'JSXExpressionContainer') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Compilation](https://github.com/webpack/webpack/blob/master/lib/Compilation.js) | |
[Compiler](https://github.com/webpack/webpack/blob/master/lib/Compiler.js) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function (babel) { | |
const { types: t } = babel; | |
function injectMountHistory(cycleType) { | |
return t.assignmentExpression( | |
'=', | |
t.memberExpression( | |
t.Identifier('history'), | |
t.UpdateExpression( | |
'++', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hasOwn = Object.prototype.hasOwnProperty | |
export default function shallowEqual(a, b) { | |
if (a === b) return true | |
let countA = 0 | |
let countB = 0 | |
for (let key in a) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { render } from 'react-dom' | |
const Observer = (obj, update) => { | |
let $$lastState = obj | |
const skipUpdate = (key, value) => { | |
return value === $$lastState[key] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let video = document.getElementsByClassName('html5-main-video')[0] | |
setInterval( | |
function() { | |
if ((video.duration - video.currentTime) < 0.1) { | |
video.play() | |
} | |
}, 500) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const app = express(); | |
app.post('/image-upload', (req, res) => { | |
let body = ''; | |
let len = parseInt(req.get('content-length'), 10); | |
req.on('data', chunk => { | |
body += chunk; | |
}); | |
req.on('end', () => { |