<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>purezen_</title>
 <link href="http://purezen.github.io/atom.xml" rel="self"/>
 <link href="http://purezen.github.io/"/>
 <updated>2025-10-10T08:59:27+00:00</updated>
 <id>http://purezen.github.io</id>
 <author>
   <name>Aaditya Bharadwaj</name>
   <email>me.purezen@gmail.com</email>
 </author>

 
 <entry>
   <title>Removing code smell in a Reactjs app — Part II : Functional HOC to the rescue!</title>
   <link href="http://purezen.github.io/posts/Removing-code-smell-in-a-Reactjs-app-Part-II-Functional-HOC-to-the-rescue!"/>
   <updated>2016-07-30T00:00:00+00:00</updated>
   <id>http://purezen.github.io/posts/Removing-code-smell-in-a-Reactjs-app-Part-II-:-Functional-HOC-to-the-rescue!</id>
   <content type="html">&lt;p&gt;Great to have you back! (Click &lt;a href=&quot;https://medium.com/@purezen_/removing-code-smell-in-a-reactjs-app-6e45c1a76033#.22cbsqvxo&quot;&gt;here&lt;/a&gt; if you want to check the first part)&lt;/p&gt;

&lt;p&gt;While surfing the inter-webs I came across functional Higher-Order Components as a React way of “enriching” components eg. &lt;a href=&quot;https://medium.com/r/?url=http%3A%2F%2Fengineering.blogfoster.com%2Fhigher-order-components-theory-and-practice%2F&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://redux-form.com&quot;&gt;Redux-form&lt;/a&gt; might be one of its most popular form.&lt;/p&gt;

&lt;p&gt;The idea is to wrap a Component in a Higher Order function to produce an &lt;em&gt;enriched&lt;/em&gt; component. Additional arguments can also be passed in just like regular functions to give more context.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Shameless plug: I am using  &lt;a href=&quot;https://github.com/purezen/react-koa-minimal-starter&quot;&gt;react-koa-minimal-starter&lt;/a&gt; as the base for the project since it comes with react-hot-loader v3 which has improved support for Higher-Order components (&lt;a href=&quot;https://github.com/gaearon/react-hot-boilerplate/pull/61#issue-148980319&quot;&gt;ref&lt;/a&gt;).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To use it, it will be called in the container component with the list passed as a reference using the property name of the state. This is how it looks like,&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-javscript&quot;&gt;import {connect} from &apos;react-redux&apos;
import Filter from ‘../enhancers/filter’

const ListContainer = connect(
 (state) =&amp;gt; state
)(Filter(List, {list: ‘listName’}))

And this is how the function looks like,

export default function Filter(EnhancedComponent, sourceRef) {
 return class extends Component {
   constructor(props) {
   super(props)
   this.state = {
   searchTerm: ‘’,
   filteredList: []
  }
 }

componentDidMount() {
 this.setState({ filteredList: this.props[sourceRef.list] })
}

getFilteredList(searchTerm, sourceList) {
 let re = new RegExp(searchTerm,’gi’)
 return sourceList.filter((item) =&amp;gt; item.match(re))
}

handleSearchTerm(e) {
 let filteredList =  this.getFilteredList(e.target.value,this.props[sourceRef.list])

 this.setState({
  searchTerm: e.target.value,
  filteredList: filteredList
 })
}

render() {
 return (
  &amp;lt;div&amp;gt;
   &amp;lt;input
    value={this.state.searchTerm}
    onChange={this.handleSearchTerm.bind(this)}
   /&amp;gt;
   &amp;lt;EnhancedComponent
    {…this.props}
    filteredList={this.state.filteredList}
   /&amp;gt;
  &amp;lt;/div&amp;gt;
 )
}}}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Finally, as can be seen the filtered list is available as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;filteredList&lt;/code&gt; property in the Presentational (wrapped) component.&lt;/p&gt;

&lt;p&gt;You can check out the implementation in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;abstraction-via-hoc&lt;/code&gt; branch of the repo at &lt;a href=&quot;https://github.com/purezen/react-hoc-example&quot;&gt;https://github.com/purezen/react-hoc-example&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Removing code smell in a Reactjs app — Part I : Identifying the smell</title>
   <link href="http://purezen.github.io/posts/removing-code-smell-in-a-Reactjs-app-Part-I-Identifying-the-smell"/>
   <updated>2016-07-29T00:00:00+00:00</updated>
   <id>http://purezen.github.io/posts/removing-code-smell-in-a-Reactjs-app-Part-I-:-Identifying-the-smell</id>
   <content type="html">&lt;p&gt;Lately I have been working on a project made using a React.js stack and came across a task which involved creating a Filter Form. Since the form was going to be used across a number of places it had to be generic.&lt;/p&gt;

&lt;p&gt;Now making a generic form basically means to write an abstraction for the form functionality so that it could be ‘plugged-in’ easily and efficiently reused, which means that the least amount of code is repeated across its usage.&lt;/p&gt;

&lt;p&gt;I pondered over it and the first form of abstraction that I could think of in ‘React-land’ was that of a Component.&lt;/p&gt;

&lt;p&gt;So, I designed a way to create a form ‘utility’, that could be plugged-in by nesting inside a component. Essentially the form would be React component. The form would have the api, getList and setFilteredList.&lt;/p&gt;

&lt;p&gt;The original implementation (as would any other real-world use-case) also involved a map of the various properties that would need to be filtered, but I am just showing the minimal api surface for brevity.&lt;/p&gt;

&lt;p&gt;I then set over it. The final implementation looked something like ..&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;getList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;setFilteredList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;filteredList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;FilterComponent&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;getList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()}&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;setFilteredList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;setFilteredList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)}&lt;/span&gt;
    &lt;span class=&quot;sr&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/div&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This abstracted away the presentational (the filter input(s)) as well as the state (ie. the filtering query) aspects of the filter functionality.&lt;/p&gt;

&lt;p&gt;This worked fine for us initially since we were in a time-crunch (call it real-world software development!) but whenever I looked back over it, it just didn’t feel right.&lt;/p&gt;

&lt;p&gt;It was because, we were receiving the filteredList from a ‘child’ component.&lt;/p&gt;

&lt;p&gt;Now React emphasises on uni-directional flow of state, which is from parent to child and thus such a scenario is an anti-pattern since the information is flowing in reverse!&lt;/p&gt;

&lt;p&gt;Because of this I had to explicitly set the filtered list in the parent component by calling setFilteredList function whereas in a perfectly ‘React-y’ scenario the filtered list should be available automatically.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;This breaks the React paradigm which emphasises on uni-directional &lt;em&gt;reactive&lt;/em&gt; flow of data.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Later, I found a solution for the same. Can you guess it? You might-have come across it while using Redux-Form.. Woah, I might have spilled the beans already!&lt;/p&gt;

&lt;p&gt;Anyways, I will be discussing it in my next post. Stay tuned!&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Maintaining a Git Differential</title>
   <link href="http://purezen.github.io/posts/maintaining-a-git-differential"/>
   <updated>2015-03-04T00:00:00+00:00</updated>
   <id>http://purezen.github.io/posts/maintaining-a-git-differential</id>
   <content type="html">&lt;p&gt;Lately, while working on some projects, I came across times when I had to inspect and debug the code &lt;em&gt;my way&lt;/em&gt;, which means using some debugging utilities and introducing some config changes and additions. 
So, I have been trying to figure out a way to maintain my own setup for working on projects, so that I can pull in changes from remote, work on them and push the relevant stuff upstream, without those modifications (config changes, debugging utilities etc) coming in the way. Also I would like my changes to be version-controlled.&lt;/p&gt;

&lt;p&gt;What this turns out in my case is the task of maintaining my own git differential. And here’s the way I deal with them.&lt;/p&gt;

&lt;p&gt;Let’s assume a simple setup in which there is a git remote labelled as origin and a branch on the local system labelled as master.&lt;/p&gt;

&lt;p&gt;To begin with, create a new branch from the master branch.&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git checkout &lt;span class=&quot;nt&quot;&gt;-b&lt;/span&gt; dev
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, make any such changes (commits) which you would not like to introduce to remote in this branch.&lt;/p&gt;

&lt;p&gt;To work on the project, you might want to continue with the same branch or create a separate branch altogether. I work on the former in case, I have to 
make a commit or two and/or need to patch the master as soon as I make a commit. In that case, while working on the dev branch, I do&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git checkout master
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git cherry-pick &amp;lt;required-commit-ref&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For the uninitiated, cherry-pick copies a commit from one branch to another, which means the new commits has the same content but a new commit ID.&lt;/p&gt;

&lt;p&gt;In case, I am doing some work where I am only concerned with moving some commits only after doing a brief work, I first checkout a new branch based on dev&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git checkout &lt;span class=&quot;nt&quot;&gt;-b&lt;/span&gt; feature-x
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Let feature-x be the ref of the new branch.
Now when you are done, you would like to do away with those unneeded commits from the dev branch. Worry not. Simply do&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git rebase &lt;span class=&quot;nt&quot;&gt;--onto&lt;/span&gt; master last-non-required-commit-ref feature-x
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Slick. Right?&lt;/p&gt;

&lt;p&gt;What I have done here is provided the branch (master) which has to become the base of the resultant branch as the first argument to the rebase –onto command. The second command is the initial commit reference (non-inclusive) which I want to be included in the resultant branch. The third command is the commit reference for the last commit required in the resultant branch.&lt;/p&gt;

&lt;p&gt;One can see it in action as..&lt;/p&gt;

&lt;p&gt;Here’s the log of the commits from the feature-x branch. I have aliased git log (basically) as gl on my system.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;assets/git-log-feature-x.png&quot; alt=&quot;git log from feature-x&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now, the rebase stuff..&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;assets/git-rebase-onto.png&quot; alt=&quot;git log from feature-x&quot; /&gt;&lt;/p&gt;

&lt;p&gt;And the final git log!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;assets/git-log-feature-x-final.png&quot; alt=&quot;git log from feature-x&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Note: Doing so may also result in merge conflict, which the rebase process will handle gracefully, but you won’t usually encounter them as long as most of your changes are non-intrusive to the regular setup.&lt;/p&gt;

&lt;p&gt;Now, you simply have to checkout the master branch and rebase it against the feature branch.&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git checkout master
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git rebase feature-x
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Also, I do all interactions with the remote only from my master branch. So, in case you want to pull in the latest commits into your dev branches, simply do&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git checkout master
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git pull &lt;span class=&quot;nt&quot;&gt;--rebase&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;then,&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git checkout &amp;lt;working-branch&amp;gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git rebase master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This would apply the latest changes on the code from master branch, and apply the exclusive commits over them. This has worked fine for me yet :)&lt;/p&gt;

&lt;p&gt;This is my personal strategy for maintaining a git differential. If you have something to say or share, please comment below.&lt;/p&gt;

&lt;p&gt;Relevant HN page: &lt;a href=&quot;https://news.ycombinator.com/item?id=9140391&quot;&gt;https://news.ycombinator.com/item?id=9140391&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ref:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://pivotallabs.com/git-rebase-onto/?tag=git&quot;&gt;http://pivotallabs.com/git-rebase-onto/?tag=git&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/27566077/maintaining-a-personal-differential-using-git&quot;&gt;http://stackoverflow.com/questions/27566077/maintaining-a-personal-differential-using-git&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Greetings interweb!</title>
   <link href="http://purezen.github.io/posts/greetings-interweb"/>
   <updated>2015-02-13T00:00:00+00:00</updated>
   <id>http://purezen.github.io/posts/greetings-interweb</id>
   <content type="html">&lt;p&gt;Greetings, fellows of the interweb!&lt;/p&gt;

&lt;p&gt;So, after much procastination and wrestling with blogging frameworks I am making my blog live.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://jekyllrb.com&quot;&gt;Jekyll&lt;/a&gt; is what has helped me arrive here. It is a static site generator and is quite popular among developers.
&lt;a href=&quot;http://lanyon.getpoole.com&quot;&gt;Lanyon&lt;/a&gt; is the theme used.&lt;/p&gt;

&lt;p&gt;So, here’s me looking forward to an awesome blogship :)&lt;/p&gt;

&lt;p&gt;Stay tuned.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;
</content>
 </entry>
 

</feed>
