Skip to content

Instantly share code, notes, and snippets.

View Lucifier129's full-sized avatar
🎯
Focusing

工业聚 Lucifier129

🎯
Focusing
View GitHub Profile
@Lucifier129
Lucifier129 / jsx-with-custom-renderer.js
Created November 8, 2017 01:47
jsx-with-custom-renderer
/** @jsx h */
function h(type, props, ...children) {
let renderer = h.renderer;
renderer.input();
renderer.type(type);
renderer.propsStart();
for (let key in props) {
renderer.propStart();
renderer.prop(key, props[key]);
@Lucifier129
Lucifier129 / jsx-scheme-renderer.js
Created November 10, 2017 14:53
jsx + scheme + renderer
/** @jsx h */
class Scheme {
constructor(type, props, children) {
this.type = type;
this.props = props;
this.children = children;
}
}
import React from 'react'
import { render } from 'react-dom'
import { reactive } from 'rxjs-react'
import { from, of } from 'rxjs'
import { map, delay, scan, concatMap } from 'rxjs/operators'
const App = reactive(() => {
const hello$ = from('hello rxjs-react!').pipe(
concatMap(char => of(char).pipe(delay(300))),
scan((str, char) => str + char, ''),
import React from 'react'
import { render } from 'react-dom'
import { toReactComponent } from 'rxjs-react/operators'
import { from, of } from 'rxjs'
import { delay, scan, concatMap } from 'rxjs/operators'
const App = from('hello rxjs-react!').pipe(
concatMap(char => of(char).pipe(delay(300))),
scan((str, char) => str + char, ''),
toReactComponent(text => {
import React from 'react'
import { render } from 'react-dom'
import { reactive } from 'rxjs-react'
import { interval } from 'rxjs'
const app = reactive(<h1>{interval(10)}</h1>)
render(app, document.getElementById('root'))
import React from 'react'
import { render } from 'react-dom'
import { reactive } from 'rxjs-react'
import { interval } from 'rxjs'
const Count = props => <h1>count {props.count} from reactive props</h1>
const app = reactive(<Count count={interval(10)} />)
render(app, document.getElementById('root'))
import React from 'react'
import { render } from 'react-dom'
import { reactive } from 'rxjs-react'
import { Subject, merge, interval } from 'rxjs'
import { map, mapTo, scan, startWith } from 'rxjs/operators'
@reactive
class App extends React.PureComponent {
incre$ = new Subject()
decre$ = new Subject()
import React from 'react'
import { render } from 'react-dom'
import { reactive } from 'rxjs-react'
import { interval } from 'rxjs'
const App = reactive(props => <h1>count {interval(props.period)}</h1>)
render(<App period={10} />, document.getElementById('root'))
import React from 'react'
import ReactDOM from 'react-dom'
import { reactive } from 'rxjs-react'
import { interval } from 'rxjs'
import { map, startWith, switchMap } from 'rxjs/operators'
const App$ = reactive(() => {
let Type$ = interval(1000).pipe(
startWith(0),
map(value => `h${value % 6 + 1}`)
import React from 'react'
import ReactDOM from 'react-dom'
import { reactive } from 'rxjs-react'
import { from } from 'rxjs'
import { map } from 'rxjs/operators'
@reactive
class App extends React.Component {
data$ = from(fetch(this.props.url).then(res => res.json()))
render() {