Skip to content

Instantly share code, notes, and snippets.

@StoneCypher
Last active January 3, 2018 18:15
Show Gist options
  • Select an option

  • Save StoneCypher/96e2c147694bddb91c98 to your computer and use it in GitHub Desktop.

Select an option

Save StoneCypher/96e2c147694bddb91c98 to your computer and use it in GitHub Desktop.

Revisions

  1. StoneCypher revised this gist Jan 3, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion headless_app.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    import {Spinner} from './brainless_renderer.js';

    // this is a vanilla js app. it knows nothing of react, other than
    // to call `.render` on line 7 with relevant data and callbacks.
    // to call `.render` on line 9 with relevant data and callbacks.

    var App = function() {

  2. StoneCypher revised this gist Oct 18, 2017. 2 changed files with 14 additions and 14 deletions.
    12 changes: 12 additions & 0 deletions brainless_renderer.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@

    // this is the react app. it knows nothing of the vanilla app, other than that the information
    // will come in in props, and that it should call this hook when this button is pressed, or etc

    var Spinner = (props) =>
    <div>
    {this.props.data}
    <button value="↑" onclick={this.props.hooks.inc}/>
    <button value="↓" onclick={this.props.hooks.dec}/>
    </div>;

    export {Spinner};
    16 changes: 2 additions & 14 deletions foo.jsx → headless_app.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@

    import {Spinner} from './brainless_renderer.js';

    // this is a vanilla js app. it knows nothing of react, other than
    // to call `.render` on line 7 with relevant data and callbacks.

    @@ -18,17 +20,3 @@ var App = function() {
    repaint
    };
    }





    // this is the react app. it knows nothing of the vanilla app, other than that the information
    // will come in in props, and that it should call this hook when this button is pressed, or etc

    var Spinner = (props) =>
    <div>
    {this.props.data}
    <button value="↑" onclick={this.props.hooks.inc}/>
    <button value="↓" onclick={this.props.hooks.dec}/>
    </div>;
  3. StoneCypher revised this gist Oct 1, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions foo.jsx
    Original file line number Diff line number Diff line change
    @@ -29,6 +29,6 @@ var App = function() {
    var Spinner = (props) =>
    <div>
    {this.props.data}
    <button value="^" onclick={this.props.hooks.inc}/>
    <button value="v" onclick={this.props.hooks.dec}/>
    <button value="" onclick={this.props.hooks.inc}/>
    <button value="" onclick={this.props.hooks.dec}/>
    </div>;
  4. StoneCypher revised this gist Oct 1, 2017. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions foo.jsx
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@

    // this is a vanilla js app. it knows nothing of react, other than
    // to call `.render` on line 7 with relevant data and callbacks.

    var App = function() {

    var repaint = () => ReactDOM.render(document.body, <Spinner data={counter} hooks={hooks}/>),
    @@ -18,6 +21,11 @@ var App = function() {





    // this is the react app. it knows nothing of the vanilla app, other than that the information
    // will come in in props, and that it should call this hook when this button is pressed, or etc

    var Spinner = (props) =>
    <div>
    {this.props.data}
  5. StoneCypher revised this gist Oct 1, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion foo.jsx
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ var App = function() {
    hooks = {inc, dec};

    return {
    value: () => counter,
    value: () => counter,
    inc,
    dec,
    repaint
  6. StoneCypher revised this gist Oct 1, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions foo.jsx
    Original file line number Diff line number Diff line change
    @@ -9,9 +9,9 @@ var App = function() {
    hooks = {inc, dec};

    return {
    inc: inc,
    dec: dec,
    value: () => counter,
    inc,
    dec,
    repaint
    };
    }
  7. StoneCypher revised this gist Sep 27, 2017. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions foo.jsx
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,8 @@

    var App = function() {

    var counter = 0,
    var repaint = () => ReactDOM.render(document.body, <Spinner data={counter} hooks={hooks}/>),
    counter = 0,
    inc = () => { ++counter; repaint() },
    dec = () => { --counter; repaint() },

    @@ -11,7 +12,7 @@ var App = function() {
    inc: inc,
    dec: dec,
    value: () => counter,
    repaint: () => ReactDOM.render(document.body, <Spinner data={counter} hooks={hooks}/>)
    repaint
    };
    }

  8. StoneCypher revised this gist Sep 27, 2017. 1 changed file with 6 additions and 13 deletions.
    19 changes: 6 additions & 13 deletions foo.jsx
    Original file line number Diff line number Diff line change
    @@ -17,16 +17,9 @@ var App = function() {



    var Spinner = (props) => ({

    render: function() {

    return <div>
    {this.props.data}
    <button value="^" onclick={this.props.hooks.inc}/>
    <button value="v" onclick={this.props.hooks.dec}/>
    </div>;

    }

    });
    var Spinner = (props) =>
    <div>
    {this.props.data}
    <button value="^" onclick={this.props.hooks.inc}/>
    <button value="v" onclick={this.props.hooks.dec}/>
    </div>;
  9. StoneCypher revised this gist Sep 27, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion foo.jsx
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ var App = function() {
    inc = () => { ++counter; repaint() },
    dec = () => { --counter; repaint() },

    hooks = {inc: inc, dec: dec};
    hooks = {inc, dec};

    return {
    inc: inc,
  10. StoneCypher revised this gist Aug 16, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions foo.jsx
    Original file line number Diff line number Diff line change
    @@ -11,13 +11,13 @@ var App = function() {
    inc: inc,
    dec: dec,
    value: () => counter,
    repaint: () => React.render(document.body, <Spinner data={counter} hooks={hooks}/>)
    repaint: () => ReactDOM.render(document.body, <Spinner data={counter} hooks={hooks}/>)
    };
    }



    var Spinner = React.createClass({
    var Spinner = (props) => ({

    render: function() {

  11. StoneCypher revised this gist Feb 17, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions foo.jsx
    Original file line number Diff line number Diff line change
    @@ -23,8 +23,8 @@ var Spinner = React.createClass({

    return <div>
    {this.props.data}
    <button value="^" onclick={this.props.inc}/>
    <button value="v" onclick={this.props.dec}/>
    <button value="^" onclick={this.props.hooks.inc}/>
    <button value="v" onclick={this.props.hooks.dec}/>
    </div>;

    }
  12. StoneCypher created this gist Feb 17, 2016.
    32 changes: 32 additions & 0 deletions foo.jsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@

    var App = function() {

    var counter = 0,
    inc = () => { ++counter; repaint() },
    dec = () => { --counter; repaint() },

    hooks = {inc: inc, dec: dec};

    return {
    inc: inc,
    dec: dec,
    value: () => counter,
    repaint: () => React.render(document.body, <Spinner data={counter} hooks={hooks}/>)
    };
    }



    var Spinner = React.createClass({

    render: function() {

    return <div>
    {this.props.data}
    <button value="^" onclick={this.props.inc}/>
    <button value="v" onclick={this.props.dec}/>
    </div>;

    }

    });