<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by eacaps on Medium]]></title>
        <description><![CDATA[Stories by eacaps on Medium]]></description>
        <link>https://medium.com/@eacaps?source=rss-d102e3584e04------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*c27vOwcnnD-7SChN1Cycew.jpeg</url>
            <title>Stories by eacaps on Medium</title>
            <link>https://medium.com/@eacaps?source=rss-d102e3584e04------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 03:54:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@eacaps/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Higher Order and Pure Components in Ember]]></title>
            <link>https://medium.com/@eacaps/higher-order-and-pure-components-in-ember-e945097558b9?source=rss-d102e3584e04------2</link>
            <guid isPermaLink="false">https://medium.com/p/e945097558b9</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[emberjs]]></category>
            <dc:creator><![CDATA[eacaps]]></dc:creator>
            <pubDate>Fri, 01 Feb 2019 03:44:06 GMT</pubDate>
            <atom:updated>2019-03-01T03:35:06.857Z</atom:updated>
            <content:encoded><![CDATA[<p>(Update: example repo is available at <a href="https://github.com/eacaps/ember-clock-example">https://github.com/eacaps/ember-clock-example</a>)</p><p>At my current job we use Ember(Press F to pay respects). Now I actually jumped on board the Ember train back in 2014 when it was fresh and new. It was okay back then, a little too strict on the MVC stuff, but the observer pattern was cool so I used it lightly at my work in the lab. Then React became a thing and I jumped on that train pretty hard in 2015 and left Ember in the dust. 2015–2017 was all React all the time(with some random Ruby on Rails in there when necessary). I started to get the hang of React and functional programming with Higher Order Components and Pure Components. Then our start-up petered out and I was looking for a new job. The small company I now work for is dedicated to sticking with Ember so I decided to make the best of it and try to implement some of the functional programming patterns in Ember. This article is dedicated to explaining and exploring how we’ve implemented the functional programming concepts of Higher Order Components and Pure Components in Ember.</p><p>The first thing I did was get our stuff up to ES6 and in the Ember eco-system that also meant using decorators — something I had never used but now think they are super keen. Also since I was coming from React land, I like to have my templates in the same file as my js code, so you’ll see me using the precompile hbs for that. Once all that was sorted out I started writing components and eventually settled on a pattern for pure components that looks something like this:</p><pre>import Component from &#39;<a href="http://twitter.com/ember/component">@ember/component</a>&#39;;<br>import hbs from &#39;htmlbars-inline-precompile&#39;;<br>import { action, computed } from &#39;<a href="http://twitter.com/ember">@ember</a>-decorators/object&#39;;</pre><pre>/**<br>  * This class displays a clock.<br>  * <a href="http://twitter.com/prop">@prop</a> {Function} toggleDisplay action to toggle 12/24 hour display<br>  * <a href="http://twitter.com/prop">@prop</a> {Date} theTime the time the clock shows<br>  * <a href="http://twitter.com/prop">@prop</a> {boolean} militaryFormat whether to display in 12/24 hour format<br>  */</pre><pre>export default class SimpleClock extends Component {<br>    <a href="http://twitter.com/action">@action</a><br>    _clickToggle(evt) {<br>        this.get(&#39;toggleDisplay&#39;)();<br>    }</pre><pre>    get elementId() {<br>        return &#39;the-clock&#39;;<br>    }</pre><pre>    /*<br>     * Private method to call the closure action<br>     */<br>    <a href="http://twitter.com/computed">@computed</a>(&#39;theTime&#39;, &#39;militaryFormat&#39;)<br>    get timeDisplay() {<br>        const format24 = this.get(&#39;militaryFormat&#39;);<br>        const the_time = this.get(&#39;theTime&#39;);<br>        if (format24) {<br>            return the_time.toString();<br>        } else {<br>            return the_time.toLocaleString();<br>        }<br>        return &#39;time&#39;;<br>    }</pre><pre>    get layout() {<br>        return hbs`<br>           &lt;div id=&#39;the-time&#39;&gt;<br>               {{timeDisplay}}<br>           &lt;/div&gt;<br>          &lt;a onClick={{action &#39;_clickToggle&#39;}}&gt;Change Format&lt;/a&gt;<br>        `;<br>    }<br>}</pre><p>I like to list the passed in properties at the top of the file in the class description(toggleDisplay, theTime and militaryFormat. Other than that its a pretty basic component. Things get more interesting when setting up the Higher Order Component(container) component:</p><pre>import Component from &#39;<a href="http://twitter.com/ember/component">@ember/component</a>&#39;;<br>import hbs from &#39;htmlbars-inline-precompile&#39;;<br>import { action, computed } from &#39;<a href="http://twitter.com/ember">@ember</a>-decorators/object&#39;;</pre><pre>/**<br>  * This is a container component that contains functionality for settings<br>  */<br>export default class TimeContainer extends Component {</pre><pre>    constructor(props) {<br>        super(props);<br>        this.set(&#39;now&#39;, new Date());<br>        setInterval(() =&gt; {<br>            this.set(&#39;now&#39;, new Date());<br>        }, 1000);<br>    }</pre><pre>   /**<br>     * The method <br>     * <a href="http://twitter.com/param">@param</a>  {String} setting_name [description]<br>     * <a href="http://twitter.com/param">@param</a>  {String} value        [description]<br>     */<br>    <a href="http://twitter.com/action">@action</a><br>    toggleDisplay() {<br>        this.set(&#39;militaryFormat&#39;, !this.get(&#39;militaryFormat&#39;));<br>    }</pre><pre>    get layout() {<br>        return hbs`<br>            {{yield<br>                (hash<br>                    theTime=now<br>                    militaryFormat=militaryFormat<br>                    toggleDisplay=(action &#39;toggleDisplay&#39;)<br>                 )<br>            }}<br>        `;<br>    }<br>}</pre><p>I thought about how to write a Higher Order Component for quite some time and this was the best I could come up with (for now). This component is basically just a yield with a hash so it can be used as a contextual component:</p><pre>{{#containers/time-container as |t|}}<br>  {{time-clock<br>    theTime=t.theTime<br>    militaryFormat=t.militaryFormat<br>    toggleDisplay=(action t.toggleDisplay)<br>  }}<br>{{/containers/time-container}}</pre><p>I’m not exactly thrilled with having to write out each property of the contextual component I’m interested in(I would prefer the common pattern in React of using …props to pass things along, but I couldn’t figure out a good way to do that yet.</p><p>That’s all for this article, for now anyway. I’ve got a working sample up on github at <a href="https://github.com/eacaps/ember-clock-example">https://github.com/eacaps/ember-clock-example</a>. Feel free to check it out and good luck and let me know what your functional programming patterns in Ember look like!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e945097558b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple Components: React vs AngularJS vs Ember]]></title>
            <link>https://medium.com/@eacaps/simple-components-react-vs-angularjs-vs-ember-f82dbf40748e?source=rss-d102e3584e04------2</link>
            <guid isPermaLink="false">https://medium.com/p/f82dbf40748e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[ember]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[leaflet]]></category>
            <dc:creator><![CDATA[eacaps]]></dc:creator>
            <pubDate>Sun, 04 Feb 2018 21:31:01 GMT</pubDate>
            <atom:updated>2018-02-04T21:57:39.686Z</atom:updated>
            <cc:license>https://creativecommons.org/publicdomain/mark/1.0/</cc:license>
            <content:encoded><![CDATA[<p>As a software developer, it’s good every once in a while to brush up on the latest and greatest in technologies and frameworks. It’s also good every now and then to brush up on things you were once familiar with and have fallen by the wayside. I’ve had a little more free time to tinker recently and I decided I wanted to play around with some mapping data. I had a ready source of data from Garmin Connect where I’ve uploaded a lot of my runs over the lifespan of my GPS watch. They’ve already got some cool displays going in their app but like I said, I wanted to tinker. I found that on Garmin Connect you can export raw TCX files for each run and after digging into the data a little bit I thought I would be a fun experiment to create a color coded pace map based on my speed on various segments.</p><p>I started by diving back into Leaflet, the web mapping tool of choice nowadays. I threw together a map using tiles from mapbox and a simple tcx parsing library. Then I used the segment data to calculate speed based on geoid distance vs time and colored each segment based on the pace. For cool runs it will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*2vz92haxDzcPdkANSpao4A.png" /><figcaption>Runspeed map of Charleston Distance Run(2015 relay)</figcaption></figure><p>So at this point you’re probably saying, that’s nice and all, but the title of this is ‘Simple Components: React vs AngularJS vs Ember’ and you haven’t talked about any of them yet! Okay, fair point. Once I got the map and pacing data working to my liking, I needed some sort of legend. Maybe like a small legend component! Like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/244/1*C4OsaPt0cBmImAvfZT8Few.png" /><figcaption>ScaleComponent</figcaption></figure><p>Alright, a simple ScaleComponent(styled with Material) that is simple and mostly makes sense! Put it together with the map and now you can (hopefully) understand the context of the coloring. Let’s see how we can implement this ScaleComponent.</p><p>Since I’ve been using React in my latest job, I stuck with React for the initial implementation. Here’s what it looks like:</p><pre>// scalecomponent.js<br>import React, { PureComponent } from &#39;react&#39;;<br><br>export default class ScaleComponent extends PureComponent {<br>  constructor() {<br>    super();<br>  }<br>  render() {<br>    const scale = this.props.scale;<br>    const gradient = [];<br>    for(const color of scale) {<br>      const style = {<br>        backgroundColor: color,<br>        width: &#39;10px&#39;,<br>        height: &#39;10px&#39;,<br>        display: &#39;inline-block&#39;<br>      };<br>      gradient.push(<br>        &lt;div key={color} style={style} /&gt;<br>      )<br>    }<br>    return (<br>      &lt;div&gt;<br>        &lt;span&gt;{this.props.range.min} &lt;/span&gt;<br>        {gradient}<br>        &lt;span&gt; {this.props.range.max}&lt;/span&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><p>Nothing too crazy here (other than using ES6 syntax, which everyone should be doing by now,) a couple properties, a loop to make the gradient boxes and that’s it. We render it in our html page using ReactDOM:</p><pre>//index.html<br>&lt;html&gt;<br>...<br>&lt;div id=&#39;scale&#39; /&gt;<br>...<br>&lt;/html&gt;</pre><pre>//app.js<br>const scale_element = document.getElementById(&#39;scale&#39;);<br>ReactDOM.render(&lt;ScaleComponent range={Utils.getSpeedRange()} scale={Utils.getColorScale()} /&gt;, scale_element);</pre><p>Since we’re using React and some other libraries, we need to bundle up our javascript and in this example I went with browserify since I didn’t need any fancy webpack configurations.</p><pre>//package.json<br>&quot;scripts&quot;: {<br>    ...<br>    &quot;bundle&quot;: &quot;browserify src/app.js -o dist/bundle.js -t babelify&quot;,<br>    ...<br>  },</pre><p>From there, include your bundle in your html file and you should be set. You can check out this example at: <a href="https://github.com/eacaps/runspeed-map">https://github.com/eacaps/runspeed-map</a>.</p><p>Now most people would probably stop there. But I decided I wanted to experiment. I had some prior experience with AngularJS(pre-2.0 days) so I decided to try my hand at implementing the same component in Angular. Now I haven’t kept up with all this crazy Angular 1 vs Angular 2,4,5(I don’t know what happened to 3), so I decided to stick with Angular 1(for now) and set to work re-implementing the component. After digging through some tutorials here’s what I came up with:</p><pre>//scalecomponent.js<br>import Utils from &#39;./utils&#39;;</pre><pre>class ScaleCtrl {<br>  constructor() {<br>    this.scale = Utils.getColorScale();<br>    this.range = Utils.getSpeedRange();<br>  }<br>}</pre><pre>export default class ScaleComponent {<br>  constructor() {<br>    this.controller = new ScaleCtrl();<br>  }<br>  component() {<br>    return () =&gt; {<br>      return {<br>        template: `<br>          &lt;div&gt;<br>            &lt;span&gt;{{ctrl.range.min}} &lt;/span&gt;<br>            &lt;span ng-repeat=&quot;color in ctrl.scale&quot;&gt;&lt;div ng-style=&quot;{backgroundColor: color, height: &#39;10px&#39;, width: &#39;10px&#39;, display: &#39;inline-block&#39;}&quot;/&gt;&lt;/div&gt;&lt;/span&gt;<br>            &lt;span&gt;{{ctrl.range.max}} &lt;/span&gt;<br>          &lt;/div&gt;<br>        `,<br>        controller: &#39;ScaleCtrl&#39;,<br>        controllerAs: &#39;ctrl&#39;<br>      };<br>    }<br>  }<br>  ctrl() {<br>    return ScaleCtrl;<br>  }<br>}</pre><p>AngularJS 1.5 is still very MVC. As you can see there’s a little tiny controller providing our data to our ScaleComponent that serves as the view. Again, pretty simple stuff other than that. We hook this into our html like so:</p><pre>//index.html<br>&lt;html&gt;<br>...<br>&lt;scale&gt;&lt;/scale&gt;<br>...<br>&lt;/html&gt;</pre><pre>//app.js<br>...<br>const MODULE_NAME = &#39;app&#39;;<br>const component = new ScaleComponent();</pre><pre>angular.module(MODULE_NAME, [])<br>  .directive(&#39;scale&#39;, component.component())<br>  .controller(&#39;ScaleCtrl&#39;, component.ctrl());</pre><pre>export default MODULE_NAME;</pre><p>In this case, to show some more breadth, I used webpack to package up our project:</p><pre>//package.json<br>&quot;scripts&quot;: {<br>    ...<br>    &quot;bundle&quot;: &quot;webpack src/app.js dist/bundle.js&quot;,<br>    ...<br>  },</pre><p>So the main difference in using AngularJS(1.5) seems to be that we’re pretty tightly bound to classic MVC, but we can still make simple components pretty easily. You can find the AngularJS project here: <a href="https://github.com/eacaps/runspeed-map-angularjs">https://github.com/eacaps/runspeed-map-angularjs</a></p><p>As if that wasn’t enough, I had some prior experience with Ember basically right before React became a thing. I decided to check in on Ember and see how it was doing. Its still out there and being used and updated so I figured why not catch up on Ember and implement the ScaleComponent again? It ended up looking something like this:</p><pre>//index.html<br>&lt;script type=&quot;text/x-handlebars&quot; data-template-name=&quot;components/run-scale&quot;&gt;<br>    &lt;div&gt;<br>      &lt;span&gt;{{min}} &lt;/span&gt;<br>      &lt;span&gt;<br>        {{#each colors as |color|}}<br>          &lt;div style=&quot;background-color: {{color}}; height: 10px; width: 10px; display: inline-block;&quot;&gt;&lt;/div&gt;<br>        {{/each}}<br>      &lt;/span&gt;<br>      &lt;span&gt; {{max}}&lt;/span&gt;<br>    &lt;/div&gt;<br>  &lt;/script&gt;<br>...<br>&lt;script&gt;<br>App.RunScaleComponent = Ember.Component.extend({<br>      min: 6,<br>      max: 9,<br>      colors: [<br>        &#39;#00FF00&#39;,<br>        &#39;#11EE00&#39;,<br>        &#39;#22DD00&#39;,<br>        &#39;#33CC00&#39;,<br>        &#39;#44BB00&#39;,<br>        &#39;#55AA00&#39;,<br>        &#39;#669900&#39;,<br>        &#39;#778800&#39;,<br>        &#39;#887700&#39;,<br>        &#39;#996600&#39;,<br>        &#39;#AA5500&#39;,<br>        &#39;#BB4400&#39;,<br>        &#39;#CC3300&#39;,<br>        &#39;#DD2200&#39;,<br>        &#39;#EE1100&#39;,<br>        &#39;#FF0000&#39;,<br>      ],<br>    });<br>&lt;/script&gt;</pre><p>Okay, so that’s pretty different. We’re defining the rendering template completely separately from the properties but still, not too difficult to follow along. I haven’t spent a lot of time on the ember one yet so you’ll notice that it is not integrated into the app with webpack or browserify. It is directly coded into the html page:</p><pre>//index.html<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;script src=&quot;<a href="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js</a>&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;<a href="http://builds.emberjs.com/tags/v2.5.0/ember.debug.js">http://builds.emberjs.com/tags/v2.5.0/ember.debug.js</a>&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;<a href="http://builds.emberjs.com/tags/v2.5.0/ember-template-compiler.js">http://builds.emberjs.com/tags/v2.5.0/ember-template-compiler.js</a>&quot;&gt;&lt;/script&gt;<br>&lt;/head&gt;<br>...<br>&lt;body&gt;<br>...<br>&lt;div id=&#39;app&#39;&gt;&lt;/div&gt;<br>...<br>&lt;/body&gt;<br>  &lt;script type=&quot;text/x-handlebars&quot;&gt;<br>    {{run-scale}}<br>  &lt;/script&gt;<br>&lt;script&gt;<br>  var App = Ember.Application.create({<br>      rootElement: &#39;#app&#39;,<br>      LOG_RESOLVER: true<br>    });</pre><pre>  App.Router.map(() =&gt; {<br>    });</pre><pre>  App.ApplicationRoute = Ember.Route.extend({<br>    });<br>&lt;/script&gt;<br>...<br>&lt;/html&gt;</pre><p>Unfortunately the simple approach to integrating(throw it together an hope it works) didn’t quite workout so I’ll hopefully have a little time in the future to play around and get it integrated with webpack or browserify so we can reuse utils.js to pass around the min, max and scale and keep things simple. The ember example can be found here: <a href="https://github.com/eacaps/runspeed-map-ember">https://github.com/eacaps/runspeed-map-ember</a>.</p><p>So, what did I learn from this wacky little experiment? Well, it isn’t really that hard to write basic components in any of these three frameworks. And it probably isn’t so bad for some of the other ones out there either (Vue, newer Angular, Polymer, whatever else floats your boat). There will always be arguments about which framework is the best, so while you may be shoehorned into one right now, keep the others in mind and occasionally try out something new.</p><p>From here I’ll hopefully at some point in the future try out the three I listed above(Vue, Angular5, Polymer) soon and I’ll probably repackage everything into a single repository(if I can do that without breaking them all). In the meantime, feel free to play around with my runspeed map(<a href="http://runspeedmap.herokuapp.com/">http://runspeedmap.herokuapp.com/</a>) and let me know what you think.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f82dbf40748e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jesting with React Higher Order Components]]></title>
            <link>https://medium.com/@eacaps/jesting-with-react-higher-order-components-7a1bc4e35630?source=rss-d102e3584e04------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a1bc4e35630</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[higher-order-components]]></category>
            <dc:creator><![CDATA[eacaps]]></dc:creator>
            <pubDate>Thu, 06 Apr 2017 19:53:49 GMT</pubDate>
            <atom:updated>2018-02-04T21:31:26.716Z</atom:updated>
            <cc:license>https://creativecommons.org/publicdomain/mark/1.0/</cc:license>
            <content:encoded><![CDATA[<p>In our project we’ve started using Higher Order Components to extract some of the businessy™® logic that some components share. We’re still going with pure Flux for now(redux wasn’t fully developed when we started) so I was having a hard time figuring out how to write jest specs for wrapper components such as this:</p><pre>// TutorialWrapperHoc.js<br>// <a href="http://twitter.com/flow">@flow</a><br>import React from &#39;react&#39;;<br>import UserStore from &#39;../../core/stores/userstore&#39;;</pre><pre>export default function (Element) {<br>  return class extends React.Component </pre><pre>    constructor(props) {<br>      super(props);<br>      this.state = this.processState();<br>      this._onChange = this.onChange.bind(this);<br>    }</pre><pre>    componentWillMount() {<br>      UserStore.addChangeListener(this._onChange);<br>    }</pre><pre>    componentWillUnmount() {<br>      UserStore.removeChangeListener(this._onChange);<br>    }</pre><pre>    processState() {<br>      let hasCompletedTutorials = true;<br>      let userstate = UserStore.getState();<br>      if (userstate.settings) {<br>        let settings = userstate.settings;</pre><pre>      let tutorials = settings.tutorials;<br>        if(tutorials !== undefined) {<br>          hasCompletedTutorials = tutorials.buzz &amp;&amp; tutorials.home &amp;&amp; tutorials.pagechat &amp;&amp; tutorials.profile;<br>        }<br>      }<br>      return {<br>        hasCompletedTutorials<br>      };<br>    }</pre><pre>    onChange() {<br>      const state = this.processState();<br>      this.setState(state);<br>    }</pre><pre>    render() {<br>      return &lt;Element {...this.state} {...this.props}/&gt;;<br>    }<br>  }<br>}</pre><p>Since we’re exporting a function that creates a React component, Jest was none too pleased when trying to ShallowRender this with a wrapped div:</p><pre>// __tests__/TutorialWrapperHoc-spec.js</pre><pre>import TestUtils from &#39;react-addons-test-utils&#39;;import TutorialWrapperHoc from &#39;../TutorialWrapperHoc&#39;;</pre><pre>describe(&#39;TutorialWrapperHoc&#39;, () =&gt; {<br>  context(&#39;testing&#39;, () =&gt; {<br>    it(&#39;simple test&#39;, () =&gt; {<br>      let component = TutorialWrapperHoc(&lt;div/&gt;);<br>      let renderer = TestUtils.createRenderer();<br>      renderer.render(obj);<br>      let output = renderer.getRenderOutput();<br>    })<br>  });<br>});</pre><p>Doing this led to awesome things like: <strong>Invariant Violation: ReactShallowRenderer render(): Invalid component element. Instead of passing a component class, make sure to instantiate it by passing it to React.createElement. </strong>I gave up for a while but I really wanted to write actual specs for these things to make sure we’re properly testing our businessy™® logic. I tried all sorts of wacky things in both the spec file and the HOC itself. None of them worked out so well until I tried this one neat(dumb) trick. Rather than create the component as an inner class belonging to the exported function, lets move the class definition out of the function and make it a proper export as well. This doesn’t quite work since we’re passing the Element to be wrapped into the function:</p><pre>export class TutorialWrapper extends React.Component {<br>.<br>.<br>.<br>  render() {<br>    return &lt;Element {...this.state} {...this.props}/&gt;;<br>  }<br>}</pre><p>However we could just make this a real component by using a div instead:</p><pre>export class TutorialWrapper extends React.Component {<br>.<br>.<br>.<br>  render() {<br>    return &lt;div {...this.state} {...this.props}/&gt;;<br>  }<br>}</pre><p>Now this isn’t quite what we want to export in our HOC function so lets make that part work by using inheritance and overriding the render method.</p><pre>export default function (Element) {<br>  return class extends TutorialWrapper {<br>    render() {<br>      return &lt;Element {...this.state} {...this.props}/&gt;<br>    }<br>  };<br>};</pre><p>Putting it all together we get this:</p><pre>// TutorialWrapperHoc.js<br>// <a href="http://twitter.com/flow">@flow</a><br>import React from &#39;react&#39;;<br>import UserStore from &#39;../../core/stores/userstore&#39;;</pre><pre>export class TutorialWrapper extends React.Component {<br>  constructor(props: Object) {<br>    super(props);<br>    this.state = this.processState();<br>    this._onChange = this.onChange.bind(this);<br>  }<br>  componentWillMount() {<br>    UserStore.addChangeListener(this._onChange);<br>  }<br>  componentWillUnmount() {<br>    UserStore.removeChangeListener(this._onChange);<br>  }<br>  processState() {<br>    let hasCompletedTutorials = true;<br>    let userstate = UserStore.getState();<br>    if (userstate.settings) {<br>      let settings = userstate.settings;<br>    let tutorials = settings.tutorials;<br>      if(tutorials !== undefined) {<br>        hasCompletedTutorials = tutorials.buzz &amp;&amp; tutorials.home &amp;&amp; tutorials.pagechat &amp;&amp; tutorials.profile;<br>      }<br>    }<br>    return {<br>      hasCompletedTutorials<br>    };<br>  }<br>  onChange() {<br>    const state = this.processState();<br>    this.setState(state);<br>  }<br>  render() {<br>    return &lt;div {...this.state} {...this.props}/&gt;;<br>  }<br>}</pre><pre>export default function (Element) {<br>  return class extends TutorialWrapper {<br>    render() {<br>      return &lt;Element {...this.state} {...this.props}/&gt;<br>    }<br>  };<br>};</pre><p>Now we can write our JEST specs using the regular old div wrapped component.</p><pre>// __tests__/TutorialWrapperHoc-spec.js</pre><pre>import TestUtils from &#39;react-addons-test-utils&#39;;<br>import {TutorialWrapper} from &#39;../TutorialWrapperHoc&#39;;</pre><pre>describe(&#39;TutorialWrapper&#39;, () =&gt; {<br>  context(&#39;testing&#39;, () =&gt; {<br>    it(&#39;simple test&#39;, () =&gt; {<br>      let component = TutorialWrapperHoc(&lt;div/&gt;);<br>      let renderer = TestUtils.createRenderer();<br>      renderer.render(obj);<br>      let output = renderer.getRenderOutput();<br>    })<br>  });<br>});</pre><p>Now this is not the most elegant solution in the world, but I’ve already wasted too much time googling and hacking about trying to do this, so it’ll have to do for now. If anyone out there in internet land has suggestions or alternatives let me know. Good luck Reacting!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a1bc4e35630" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>