<?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[scripbox-engineering - Medium]]></title>
        <description><![CDATA[Engineering @ Scripbox - Medium]]></description>
        <link>https://medium.com/scripbox-engineering?source=rss----a7e84153c204---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>scripbox-engineering - Medium</title>
            <link>https://medium.com/scripbox-engineering?source=rss----a7e84153c204---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 16:05:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/scripbox-engineering" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to hide a <View> component in React Native]]></title>
            <link>https://medium.com/scripbox-engineering/how-to-hide-a-view-component-in-react-native-8a4994382c0?source=rss----a7e84153c204---4</link>
            <guid isPermaLink="false">https://medium.com/p/8a4994382c0</guid>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Scripbox Technology Blog]]></dc:creator>
            <pubDate>Mon, 26 Feb 2018 10:58:00 GMT</pubDate>
            <atom:updated>2018-02-26T10:57:59.934Z</atom:updated>
            <content:encoded><![CDATA[<p>By <a href="https://medium.com/@arundavid">Arun David</a> and <a href="https://medium.com/@arunbharhath">Arun Bharhath</a></p><p>Our <a href="https://scripbox.com/mobile-app">Scripbox mobile app</a> is completely re-written with React Native to support both Android and iOS. When we started building our app, we had to hand-roll custom wrapper components to overcome React Native limitations. We would like to share some of our learnings in this journey.</p><h3><strong>The Challenge</strong></h3><p>React Native View component does not support hiding or changing visibility option by default. We wrote a custom component MyView with this in mind.</p><p>Our custom component MyView can accept a prop hide that hides the element when the prop is set to true. Otherwise, MyView renders native View component with all of its children.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f99b5c158796cbe5ca996bb14ae303e2/href">https://medium.com/media/f99b5c158796cbe5ca996bb14ae303e2/href</a></iframe><h3>Usage</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*OQtwz3rIqRUwBDKGGv7xcQ.gif" /></figure><p>In the screen, we use the custom MyView component instead of native View component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5205276804607e16ec0ab7553e244d4/href">https://medium.com/media/f5205276804607e16ec0ab7553e244d4/href</a></iframe><h3><strong>Conclusion</strong></h3><p>There are other solutions available in the internet that recommend to set the opacity of the view to zero or setting the height of the view to zero. We prefer to unmount (not render) a component, rather than mounting and mutating the opacity or position. Given a chance, we opt for composition instead of direct state change.</p><p>We will share other such custom wrapper components that we have created to overcome some limitations of React Native in the upcoming posts.</p><p>We are unlocking engineering challenges, the kind that come frequently, and with scale. If you think these are the kind of challenges that you would love to solve, do <a href="https://scripbox.com/pages/careers">check out our open positions</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a4994382c0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/scripbox-engineering/how-to-hide-a-view-component-in-react-native-8a4994382c0">How to hide a &lt;View&gt; component in React Native</a> was originally published in <a href="https://medium.com/scripbox-engineering">scripbox-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Knapsack accelerated our test suite by 50%]]></title>
            <link>https://medium.com/scripbox-engineering/how-knapsack-accelerated-our-test-suite-by-50-42f8cb584c47?source=rss----a7e84153c204---4</link>
            <guid isPermaLink="false">https://medium.com/p/42f8cb584c47</guid>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Scripbox Technology Blog]]></dc:creator>
            <pubDate>Thu, 22 Feb 2018 13:19:51 GMT</pubDate>
            <atom:updated>2018-02-22T13:19:50.999Z</atom:updated>
            <content:encoded><![CDATA[<p>By <a href="https://twitter.com/mschoudhary2000">Mohit Choudhary</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jLLr8Kou2UFPr-nakMIIwA.png" /></figure><p>At Scripbox, we continuously strive to keep our CI pipelines quick. If not for this speed, it would be impossible to ship code to production multiple times a day, with minimal errors.</p><p>Our core application stack is powered by Ruby On Rails and we have setup Gitlab CI for our test infrastructure. Much like any growing project, the more tests we add, the slower the CI pipeline gets.</p><p>Our naive implementation took care of slicing and assigning specs to individual runners.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/41ad497ee90bf2dc838a6c6709d98de1/href">https://medium.com/media/41ad497ee90bf2dc838a6c6709d98de1/href</a></iframe><p>We had 5 different jobs running concurrently and tests were divided in to equal numbers. Some jobs ran faster than the others:</p><pre>rspec-job 0 5   3 mins 25 secs<br>rspec-job 1 5   3 mins 21 secs<br>rspec-job 2 5   3 mins 1 secs<br>rspec-job 3 5   13 mins 5 secs<br>rspec-job 4 5   8 mins 2 secs</pre><p>The pipeline took 13 minutes to complete because one job took as much time. We needed a smarter way to distribute our tests so that they would take more or less the same to be completed, thereby bringing down the average time spent by the pipeline.</p><p>We started looking for ways to speed up our test pipelines and found the following options:</p><h3><a href="https://github.com/grosser/parallel_tests">parallel_tests</a></h3><p>parallel_tests works well when you run your suite in a single host. It runs the tests in parallel on multiple CPU cores. Since our Gitlab runners are small EC2 instances with just a single core, we opted for something that could work in a distributed fashion across the network.</p><h3><a href="https://github.com/ArturT/knapsack">knapsack</a></h3><p>Knapsack splits tests across CI nodes and ensures they complete in more or less the same amount of time.</p><h4>Installation</h4><ol><li>Add Knapsack to Gemfile.</li></ol><p>We grouped it under :ci since it’s not required for development:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26257b068ab15d099f3290af37f13e27/href">https://medium.com/media/26257b068ab15d099f3290af37f13e27/href</a></iframe><p>2. Bind the Knapsack adapter in spec_helper.rb :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87a7b1a7afbeaf14b6cbc43fe068ad1e/href">https://medium.com/media/87a7b1a7afbeaf14b6cbc43fe068ad1e/href</a></iframe><p>CI is a predefined environment variable <a href="https://docs.gitlab.com/ee/ci/variables/#predefined-variables-environment-variables">exposed in Gitlab CI</a>, which ensures this happens only in CI, excluding other environments (eg. dev)</p><p>3. Finally add the following lines toRakefile :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7638382147d70bcbd91ceb0262e075e/href">https://medium.com/media/d7638382147d70bcbd91ceb0262e075e/href</a></iframe><h4>How it works</h4><p>Knapsack maintains a report which logs the time taken by each test. We can create the report by running:</p><pre>KNAPSACK_GENERATE_REPORT=true bundle exec rspec spec</pre><p>This creates knapsack_report.json which we need to cache in the gitlab.</p><p>Now we can run the test in CI as follows:</p><pre>CI_NODE_TOTAL=2 CI_NODE_INDEX=0 bundle exec rake knapsack:rspec</pre><pre># CI_NODE_TOTAL is total number of rspec jobs you intend to have.<br># CI_NODE_INDEX is the current job number</pre><p>Knapsack will refer to knapsack_report.json to split the tests.</p><p>We have an overhead of maintaining knapsack_report.json. When significant changes occur in our test suite, we need to manually generate the report again. Inspired by how <a href="https://gitlab.com/gitlab-org/gitlab-ce/issues/29623">gitlab</a> addresses the same issue, we have now automated the report generation inside Gitlab CI.</p><p>Broadly these are the steps:</p><ol><li>We cache the Knapsack report, so that it is available between runs.</li><li>Prior to the test stage we have a retrieve knapsack stage. We retrieve the report from cache and expose it to other jobs in the same pipeline as artefacts. Here’s the excerpt from our gitlab-ci.yml :</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37e738bd7018fd4a8e4fdcb57425f92e/href">https://medium.com/media/37e738bd7018fd4a8e4fdcb57425f92e/href</a></iframe><p>This is how our rspec job looks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5bf7b6b79da93cc2839a6aab167a04e9/href">https://medium.com/media/5bf7b6b79da93cc2839a6aab167a04e9/href</a></iframe><p>For each node we generate the Knapsack report separately. Since it has cached the main Knapsack report (exposed from previous stage as an artefact), Knapsack is able to divide the test equally among the nodes.</p><p>3. Finally we merge all those separate reports into one and cache it for subsequent runs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/699ecf5bd3104cc72e7a007b4b33987f/href">https://medium.com/media/699ecf5bd3104cc72e7a007b4b33987f/href</a></iframe><p>Here is script/merge-reports :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09c83aa17e5fb4e4d12afacbe1dab941/href">https://medium.com/media/09c83aa17e5fb4e4d12afacbe1dab941/href</a></iframe><p>And the results look promising already:</p><pre>rspec-job 0 5   8 mins 10 secs<br>rspec-job 1 5   8 mins 21 secs<br>rspec-job 2 5   7 mins 30 secs<br>rspec-job 3 5   6 mins 5 secs<br>rspec-job 4 5   8 mins 40 secs</pre><h3>Conclusion</h3><p>Before using Knapsack, it took an average of 16 minutes to complete over 3500 tests for a pipeline consisting of 8 runners working in parallel. This has now dropped to 8 minutes.</p><p>With the use of Knapsack, we already have the power to scale our testing infrastructure horizontally. We now intend to make the test pyramid smarter; say have a faster unit stage before the functional stage as this will improve the turn-around time.</p><p>We are unlocking engineering challenges, the kind that come frequently, and with scale. If you think these are the kind of challenges that you would love to solve, do <a href="https://scripbox.com/pages/careers">check out our open positions</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42f8cb584c47" width="1" height="1" alt=""><hr><p><a href="https://medium.com/scripbox-engineering/how-knapsack-accelerated-our-test-suite-by-50-42f8cb584c47">How Knapsack accelerated our test suite by 50%</a> was originally published in <a href="https://medium.com/scripbox-engineering">scripbox-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Boost your GraphQL/Relay React app with Redux]]></title>
            <link>https://medium.com/scripbox-engineering/boost-your-graphql-relay-react-app-with-redux-f83a33faf871?source=rss----a7e84153c204---4</link>
            <guid isPermaLink="false">https://medium.com/p/f83a33faf871</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[relay]]></category>
            <category><![CDATA[graphql]]></category>
            <dc:creator><![CDATA[Bhupendra Singh]]></dc:creator>
            <pubDate>Tue, 13 Feb 2018 07:48:12 GMT</pubDate>
            <atom:updated>2018-02-13T07:48:11.542Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c391-6gexK2_-UIQjZRIeg.png" /></figure><p>At <a href="https://scripbox.com/">Scripbox</a>, we’ve been experimenting with <a href="http://graphql.org/">GraphQL</a> for internal purposes. We are huge fans of Redux. However, there is not much written about using the awesomeness of Redux alongside GraphQL. We have taken a stab at documenting our experience in marrying the development agility of GraphQL with painless state-management of Redux.</p><p>This post assumes we are fairly familiar with <a href="https://github.com/facebook/react">React</a> and <a href="https://github.com/reactjs/redux">Redux</a>.</p><h4>Why GraphQL?</h4><p>Clients often face the issue of over-fetching or under-fetching data. We need to have backing API endpoints for different representations of the same resource entity. This complexity is what GraphQL aims to solve.</p><p>GraphQL has inverted the equation in that, instead of a server dictating what attributes need to be served, the client gets to ask for information<br>that it needs.</p><p>As of now, Relay and Apollo Client are the prominent JS clients that can converse with a GraphQL backend.</p><p>We decided to go with <a href="https://facebook.github.io/relay/docs/en/prerequisites.html">Relay</a> as the framework API looked quite straight-forward.</p><h4>Relay</h4><p>There are 3 key parts of integrating Relay with React:</p><ol><li>Fetching the schema from server</li><li>Relay Environment</li><li>QueryRenderer</li></ol><h4>Schema</h4><p>GraphQL works on the basis of a shared schema between the server and client. We’re assuming we have the GraphQL server up and running. We need to ensure that we have the schema created as well.</p><p>Let us retrieve schema from the server.</p><pre>$ npm install -g get-graphql-schema<br>$ get-graphql-schema __RELAY_API_ENDPOINT__ &gt; ./schema.graphql</pre><p>Now that we have the schema, let’s setup the Relay environment.</p><h4>Environment</h4><pre><em>// src/createRelayEnvironment.js</em></pre><pre>const {<br>  Environment,<br>  Network,<br>  RecordSource,<br>  Store<br>} = require(&#39;relay-runtime&#39;);</pre><pre>function fetchQuery(operation, variables) {<br>  return fetch(___RELAY_API___, {<br>    method: &#39;POST&#39;,<br>    body: JSON.stringify({<br>      query: operation.text,<br>      variables,<br>    }),<br>  }).then(response =&gt; {<br>    return response.json();<br>  });<br>}<br>const network = Network.create(fetchQuery);<br>const source = new RecordSource();<br>const store = new Store(source);<br>export default new Environment({ network, store });</pre><p>We can observe that Network and Store are parameters used to initialise the environment. The environment orchestrates API requests and manages resource state within the Relay boundary.</p><h4>QueryRenderer</h4><p>The QueryRenderer will be solely responsible for bridging the environment and our views. QueryRenderer is React-aware as it resides in views. It is also schema-aware, in that, the actual attributes to be fetched for a resource is<br>defined in the QueryRenderer.</p><p>Here is the QueryRenderer inside our LikeComponent.</p><pre>import {<br>  QueryRenderer,<br>  GraphQL<br>} from &#39;react-relay&#39;;<br>import environment from &#39;../src/createRelayEnvironment&#39;;</pre><pre>class LikeComponent extends Component {<br>  render() {<br>    return (<br>      &lt;div&gt;<br>        &lt;QueryRenderer<br>          environment={environment}<br>          query={GraphQL`<br>            query LikeQuery() {<br>            user {<br>                  count<br>                  liked<br>                }<br>              }<br>          `}<br>          render={({ error, props }) =&gt; {<br>            if (error) {<br>              return &lt;div&gt;{ error.message }&lt;/div&gt;;<br>            } else if (props) {<br>              JSON.stringify(props.user)<br>              /&gt;;<br>            }<br>            return &lt;div className=&#39;loader&#39;/&gt;;<br>          }}<br>        /&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><p>We are interested in fetching only count and liked for a user. Thanks to GraphQL, we don’t need to make any changes in the server to facilitate this as the schema created in the server already accounts for these attributes.</p><p>We need a way to tell the QueryRenderer what query to fire and how to handle the response. To address the former, we need to use a Query. We can notice the LikeQuery usage inside our QueryRenderer.</p><p>The Query abstraction prepares the attributes to be send across the network as required by GraphQL. This abstraction sits on top of Relay artefacts.</p><p>Relay artefacts are generated stubs that aids Query in preparing and sending the request payload. These artefacts are created by combing through the source files looking for *Query references and the schema.</p><p>Let us compile our Relay artefacts.</p><pre>$ npm install relay-compiler<br>$ relay-compiler — src ./src — schema ./schema.GraphQL</pre><p>At this point, we will find the artefacts under the __generated__ folder along with our QueryRenderer. We can inspect the artifacts to see how the GraphQL query is constructed.</p><h4>State, state, more state!</h4><p>Relay works well when managing client-server interactions; but not all interactions fall in this scope. We need state management for user-client interactions that might involve purely view changes where Relay has no<br>part to play. We can use the vanilla state given by React but that breaks the <a href="http://blog.mgechev.com/2015/05/15/flux-in-depth-overview-components">Flux philosophy</a>.</p><h3>Enter Redux</h3><p>Redux helps us manage state in an immutable fashion and adheres to the Flux philosophy. As immutability is baked in, there are fewer chances of our application ending up in an invalid state. Let us see how we can make Redux play well with GraphQL.</p><pre><em>// src/LikeComponent.js</em></pre><pre><a href="http://twitter.com/connect">@connect</a>(state =&gt; ({<br>  counter: state.SampleReducer.get(&#39;counter&#39;),<br>}))<br>class LikeComponent extends Component {<br>  static propTypes = {<br>    counter: PropTypes.number.isRequired,<br>   // from react-redux connect<br>    dispatch: PropTypes.func.isRequired,<br>  }<br>  render() {<br>    const {<br>    counter,<br>    dispatch,<br>    } = this.props;<br>    return (<br>      &lt;div&gt;<br>        &lt;QueryRenderer<br>          environment={environment}<br>          variables={{ after: (batchSize * (currentPage - 1)), first: batchSize }}<br>          query={GraphQL`<br>            query LikeQuery() {<br>             user {<br>                   userId<br>                   count<br>                   liked<br>                 }<br>              }<br>          `}<br>          render={({ error, props }) =&gt; {<br>            if (error) {<br>              return &lt;div&gt;{ error.message }&lt;/div&gt;;<br>            } else if (props) {<br>              { disptach(SampleAction.updateCounterValueWithServerValue(props.user.count)) }<br>              &lt;div className=&#39;Example&#39;&gt;<br>                &lt;p&gt;Like: { counter }&lt;/p&gt;<br>                &lt;button onClick={ () =&gt; dispatch(SampleActions.handleLikeButtonClick(props.user.liked))}&gt;<br>                   Like<br>                &lt;/button&gt;<br>              &lt;/div&gt;<br>           /&gt;;<br>          }<br>            return &lt;div className=&#39;loader&#39;/&gt;;<br>          }}<br>        /&gt;<br>      &lt;/div&gt;<br>    );<br>  }<br>}</pre><p>When our Component is initialised it invokes QueryRenderer to get state of liked and the count. When we click the Like button the reducers are called via the Actions which mutate the state of the View Component and calls the render function.</p><pre>// src/LikeAction.js</pre><pre>updateCounterValueWithServerValue(count) {<br>  return {<br>    type: UPDATE_COUNTER,<br>    count<br>  }<br>}</pre><pre>handleLikeButtonClick(liked) {<br>  return {<br>    type: UPDATE_LIKE_UNLIKE,<br>    liked<br>  }<br>}</pre><pre>// <em>src/LikeReducer.js </em></pre><pre>const initialState = Map({<br>  counter: 0,<br>  liked: false<br>});</pre><pre>const actionsMap = {<br>  [UPDATE_LIKE_UNLIKE]: (state, action) =&gt; {<br>    const counter = action.liked ? state.get(&#39;counter&#39;) - 1 : state.get(&#39;counter&#39;) + 1;<br>    return state.merge(Map({<br>      counter,<br>    }));<br>  },<br>  [UPDATE_COUNTER]: (state) =&gt; {<br>    const counter = state.get(&#39;count&#39;);<br>    return state.merge(Map({<br>      counter<br>    }));<br>  }<br>};</pre><p>We have omitted the mutation call that updates the value in the server for brevity.</p><h4>Conclusion</h4><p>Our exploration is still in a nascent stage but we are optimistic about this approach. Please do let us know if we can improve this.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f83a33faf871" width="1" height="1" alt=""><hr><p><a href="https://medium.com/scripbox-engineering/boost-your-graphql-relay-react-app-with-redux-f83a33faf871">Boost your GraphQL/Relay React app with Redux</a> was originally published in <a href="https://medium.com/scripbox-engineering">scripbox-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>