Last active
April 3, 2021 22:20
-
-
Save samwgoldman/79d0da4bda25738c20c1 to your computer and use it in GitHub Desktop.
Revisions
-
samwgoldman revised this gist
Apr 19, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ type Element = ReactElement<any, any, any> function component<P>(render: (props: P) => Element): Component<P> { return (React.createClass({ shouldComponentUpdate(props) { return !Immutable.is(this.props.data, props.data) }, render() { return render((this.props.data : any)) -
samwgoldman revised this gist
Apr 19, 2015 . 1 changed file with 13 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,24 +3,29 @@ var React = require("react") var Immutable = require("immutable") // In order to use any type as props, including Immutable objects, we // wrap our prop type as the sole "data" key passed as props. type Component<P> = ReactClass<{},{ data: P },{}> type Element = ReactElement<any, any, any> // Our componenets are truly a function of props, and immutability is // assumed. This discipline is a feature, not a bug. function component<P>(render: (props: P) => Element): Component<P> { return (React.createClass({ shouldComponentUpdate(props) { return Immutable.is(this.props.data, props.data) }, render() { return render((this.props.data : any)) } }) : any) } // Defining components couldn't be simpler. var Example: Component<string> = component((foo) => { return <span>{foo}</span> }) // In order to use JSX, we need to pass our props as `data`, but flow // will still type check this for us. var foo = <Example data={"bar"} /> -
samwgoldman revised this gist
Apr 19, 2015 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,9 +3,11 @@ var React = require("react") var Immutable = require("immutable") // Flow has complex built-in types for React, but purity affords us a simpler API. type Element = ReactElement<any, any, any> type Component<P> = ReactClass<{},P,{}> // We need a small `any` escape hatch to convince Flow to use our types function component<P>(render: (props: P) => Element): Component<P> { return (React.createClass({ shouldComponentUpdate(props) { -
samwgoldman created this gist
Apr 19, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ /* @flow */ var React = require("react") var Immutable = require("immutable") type Element = ReactElement<any, any, any> type Component<P> = ReactClass<{},P,{}> function component<P>(render: (props: P) => Element): Component<P> { return (React.createClass({ shouldComponentUpdate(props) { return Immutable.is(this.props, props) }, render() { return render((this.props : any)) } }) : any) } var Example: Component<{ foo: string }> = component((props) => { return <span>{props.foo}</span> }) var foo = <Example foo="bar" />