Skip to content

Instantly share code, notes, and snippets.

View madeinfree's full-sized avatar
🐱
Focusing

Whien_Liou madeinfree

🐱
Focusing
View GitHub Profile
@madeinfree
madeinfree / createStore.js
Last active July 7, 2016 06:22
simple store like redux
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)
#!/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
@madeinfree
madeinfree / babel-plugin-extends-to-stateless-v2.js
Last active October 4, 2016 04:45
for babel-plugin to transform extends to stateless arrow function
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') {
[Compilation](https://github.com/webpack/webpack/blob/master/lib/Compilation.js)
[Compiler](https://github.com/webpack/webpack/blob/master/lib/Compiler.js)
@madeinfree
madeinfree / react-babel-inject-plugin.js
Last active December 9, 2016 10:18
for babel to inject react debug tool
export default function (babel) {
const { types: t } = babel;
function injectMountHistory(cycleType) {
return t.assignmentExpression(
'=',
t.memberExpression(
t.Identifier('history'),
t.UpdateExpression(
'++',
@madeinfree
madeinfree / shallowEqual.js
Created February 17, 2017 09:46
shallowEqual
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) {
@madeinfree
madeinfree / ReactObserver.js
Created March 11, 2017 11:17
Reactjs Reactive with Proxy
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]
}
@madeinfree
madeinfree / youtube-repeat-console-code.js
Last active July 11, 2017 02:15
use console log to fire youtube repeat
let video = document.getElementsByClassName('html5-main-video')[0]
setInterval(
function() {
if ((video.duration - video.currentTime) < 0.1) {
video.play()
}
}, 500)
@madeinfree
madeinfree / IsAuthorization.js
Created September 15, 2017 13:23
Let you easy to manage your component with auth
import * as React from 'react';
import {
Redirect
} from 'react-router-dom';
import {
connect
} from 'react-redux';
import {
compose,
branch,
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', () => {