Skip to content

Instantly share code, notes, and snippets.

xialvjun / cache-react-component.js
Created Aug 9, 2016
Wrap a component class and get the CachedComponent. This CachedComponent will calculate a key from props and use the key to decide whether to construct a new instance and cache the old or recover the old component from cache and update props. We can use it with react-router easily to save up the time of constructing the RouteComponent you alread…
View cache-react-component.js
import React from 'react'
export default function cache(mapPropsToKey, option) {
mapPropsToKey = mapPropsToKey || (() => 'NoCache')
option = option || {}
// 默认最高5层,1000年
const {
xialvjun / react-flyd-binding.js
Created Jul 21, 2016
Inspired by theadam/react-flyd. Allows for flyd streams to be embedded directly into JSX, and to update content when the streams fire events.
View react-flyd-binding.js
import { Component, createElement, cloneElement, isValidElement } from 'react'
import { isStream, on, combine } from 'flyd'
export function reactive(tag='') {
class ReactiveClass extends Component {
constructor(props) {
this.displayName = `ReactiveClass-${typeof tag==='string' ? tag : (tag.displayName || || '')}`;
this.state = {}