Skip to content

Instantly share code, notes, and snippets.

View lanqy's full-sized avatar
🎯
Focusing

Lan Qingyong lanqy

🎯
Focusing
  • Shenzhen,China
View GitHub Profile
@lanqy
lanqy / ReactCanvasDrawing.js
Created August 30, 2016 12:00 — forked from sebmarkbage/ReactCanvasDrawing.js
Canvas Drawing Example
/** @jsx React.DOM */
var Graphic = React.createClass({
componentDidMount: function() {
var context = this.getDOMNode().getContext('2d');
this.paint(context);
},
componentDidUpdate: function() {
@lanqy
lanqy / ReduxMicroBoilerplate.js
Created August 27, 2016 04:12 — forked from gaearon/ReduxMicroBoilerplate.js
Super minimal React + Redux app
import React, { Component } from 'react';
import { createStore, combineReducers, applyMiddleware, bindActionCreators } from 'redux';
import { provide, connect } from 'react-redux';
import thunk from 'redux-thunk';
const AVAILABLE_SUBREDDITS = ['apple', 'pics'];
// ------------
// reducers
// ------------
@lanqy
lanqy / slim-redux.js
Created August 27, 2016 04:11 — forked from gaearon/slim-redux.js
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {
@lanqy
lanqy / index.js
Created August 27, 2016 04:09 — forked from gaearon/index.js
Breaking out of Redux paradigm to isolate apps
import React, { Component } from 'react'
import Subapp from './subapp/Root'
class BigApp extends Component {
render() {
return (
<div>
<Subapp />
<Subapp />
<Subapp />
@lanqy
lanqy / connect.js
Created August 27, 2016 04:02 — forked from gaearon/connect.js
connect.js explained
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (
@lanqy
lanqy / reducers.js
Created August 27, 2016 03:57 — forked from gaearon/reducers.js
How I'd do code splitting in Redux (pseudo code, not tested!)
import { combineReducers } from 'redux';
import users from './reducers/users';
import posts from './reducers/posts';
export default function createReducer(asyncReducers) {
return combineReducers({
users,
posts,
...asyncReducers
});
@lanqy
lanqy / Child.js
Created August 24, 2016 03:14 — forked from eyesofkids/Child.js
Simple React Lifecycle methods test
import React from 'react'
var Child = React.createClass({
getInitialState: function(){
console.log('Child getInitialState');
return { value: 'start'}
},
getDefaultProps: function(){
console.log('Child getDefaultProps');
@lanqy
lanqy / redux-form-tut.js
Created August 22, 2016 02:04 — forked from dmeents/redux-form-tut.js
The source code for the redux form tutorial on davidmeents.com
import React, { Component } from 'react';
import { Field, reduxForm } from 'redux-form';
import { connect } from 'react-redux';
import * as actions from '../../actions';
const form = reduxForm({
form: 'ReduxFormTutorial',
validate
});
@lanqy
lanqy / .babelrc
Created July 24, 2016 04:16 — forked from thaerlabs/.babelrc
React hello world is not hard
{
"presets": ["es2015", "react"]
}
@lanqy
lanqy / gist:8523817
Last active January 3, 2016 21:48
通过索引选中table cell
//select first row of first section
// from http://stackoverflow.com/questions/5918309/how-to-programmatically-tap-a-uitableview-cell
// from http://stackoverflow.com/questions/6118071/how-to-set-row-selected-by-default-in-uitableview
NSIndexPath* selectedCellIndexPath= [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView selectRowAtIndexPath:selectedCellIndexPath animated:false scrollPosition:UITableViewScrollPositionMiddle];