<?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 Yong Su on Medium]]></title>
        <description><![CDATA[Stories by Yong Su on Medium]]></description>
        <link>https://medium.com/@jeantimex?source=rss-ce35f09414c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*73YZ82Vj1pTaz0l-LJlpyA@2x.jpeg</url>
            <title>Stories by Yong Su on Medium</title>
            <link>https://medium.com/@jeantimex?source=rss-ce35f09414c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 20:17:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jeantimex/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[Create a JavaScript library and fully automate the releases]]></title>
            <link>https://medium.com/@jeantimex/create-a-javascript-library-and-fully-automate-the-releases-ccce93153dbb?source=rss-ce35f09414c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccce93153dbb</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[javascript-library]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[semantic-release]]></category>
            <dc:creator><![CDATA[Yong Su]]></dc:creator>
            <pubDate>Tue, 12 May 2020 07:23:40 GMT</pubDate>
            <atom:updated>2020-05-12T07:23:40.270Z</atom:updated>
            <content:encoded><![CDATA[<h3>Create a JavaScript library and fully automate the releases in 2020</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BHsfvIAgzInb1WEkndr3aw.jpeg" /></figure><h3>0. Introduction</h3><p>In this tutorial, I am going to share my experiences in creating a UMD JavaScript library that can be used everywhere, the library is compatible with AMD (Asynchronous Module Definition) and CommonJS ecosystems, and can also be loaded in &lt;script&gt; tag.</p><p>For more information about AMD, CommonJS and UMD, <a href="https://www.davidbcalhoun.com/2014/what-is-amd-commonjs-and-umd/">David Calhoun</a> wrote a great blog that compared them, it’s highly recommended for a read.</p><p>Ok, let’s get started!</p><h3>1. Create a JavaScript library</h3><p>We are going to create a super simple calculator :)</p><h4>Create a new repository</h4><p>Go to <a href="https://github.com/">Github</a> and create a new project called calculator, initialize the repository with a README, .gitignore, and choose a license.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iWRF_3Dpj05_K4Pp-iDK8Q.png" /></figure><p>Clone the newly created repository and enter into the folder:</p><pre>&gt; git clone <a href="/service/mailto:git@github.com">git@github.com</a>:&lt;GH_USERNAME&gt;/calculator.git &amp;&amp; \<br>  cd calculator</pre><h4>Initialize NPM package and install Node.js dependencies</h4><p>We will use Webpack to bundle the library for distribution, and use babel to help transpile ES6 syntax so that our library works on most browsers.</p><pre>&gt; npm init -y<br>&gt; npm i -D webpack webpack-cli babel-loader @babel/core \<br>  @babel/preset-env</pre><h4>Scaffold the library</h4><p>Webpack has a great tutorial about <a href="https://webpack.js.org/guides/author-libraries/">authoring libraries</a>, let’s borrow its folder structure.</p><pre>&gt; mkdir -p {src,dist,examples/browser,examples/node}<br>&gt; touch src/index.js examples/browser/index.html \<br>  examples/node/example.js</pre><p>Now the folder structure should look like this:</p><pre>.<br>├── dist<br>├── examples<br>│   ├── browser<br>│   │   └── index.html<br>│   └── node<br>│       └── example.js<br>└── src<br>    └── index.js</pre><h4>Implement the library</h4><p>It’s time to implement the library!</p><p><strong><em>src/index.js</em></strong></p><pre>module.exports = {<br>  add: (num1, num2) =&gt; num1 + num2,<br>  sub: (num1, num2) =&gt; num1 - num2,<br>};</pre><p>As you can see, our calculator is super simple.</p><p><strong><em>examples/node/example.js</em></strong></p><pre>const {add, sub} = require(&#39;./calculator.js&#39;);<br>console.log(&#39;1 + 2 = &#39; + add(1, 2));<br>console.log(&#39;2 - 1 = &#39; + sub(2, 1));</pre><p><strong><em>examples/browser/index.html</em></strong></p><pre>&lt;html&gt;<br>&lt;head&gt;<br>  &lt;title&gt;Test Calculator&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;script src=&#39;./calculator.js&#39;&gt;&lt;/script&gt;<br>  &lt;script&gt;<br>    const {add, sub} = calculator;<br>    console.log(&#39;1 + 2 = &#39; + add(1, 2));<br>    console.log(&#39;2 - 1 = &#39; + sub(2, 1));<br>  &lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>The above two files are mainly used for local testing.</p><h4>Bundle the library</h4><p>We need to configure Webpack and Babel in order to make them work for us.</p><pre>&gt; touch webpack.config.js .babelrc</pre><p><strong><em>webpack.config.js</em></strong></p><pre>const path = require(&#39;path&#39;);</pre><pre>module.exports = {<br>  mode: &#39;production&#39;,<br>  entry: &#39;./src/index.js&#39;,<br>  output: {<br>    path: path.resolve(__dirname, &#39;./dist&#39;),<br>    filename: &#39;calculator.js&#39;,<br>    library: &#39;calculator&#39;,<br>    libraryTarget: &#39;umd&#39;,<br>    globalObject: &#39;this&#39;,<br>  },<br>  module: {<br>    rules: [{<br>      test: /\.js$/,<br>      exclude: /(node_modules)/,<br>      use: &#39;babel-loader&#39;,<br>    }],<br>  },<br>};</pre><p><strong><em>.babelrc</em></strong></p><pre>{<br>  &quot;presets&quot;: [&quot;@babel/preset-env&quot;]<br>}</pre><p>And we need to update the package.json. The most important part here is to change the main property to let it point to dist/calculator.js.</p><p><strong><em>package.json</em></strong></p><pre>&quot;main&quot;: &quot;dist/calculator.js&quot;,<br>&quot;scripts&quot;: {<br>  &quot;build:browser&quot;: &quot;webpack &amp;&amp; cp dist/calculator.js examples/browser&quot;,<br>  &quot;build:node&quot;: &quot;webpack &amp;&amp; cp dist/calculator.js examples/node/ &amp;&amp; node examples/node/example.js&quot;,<br>  &quot;build&quot;: &quot;webpack&quot;<br>}</pre><p>Oh, make sure the dist folder is included in the final distribution, just uncomment the dist line if you see one.</p><p><strong><em>.gitignore</em></strong></p><pre><em>...<br># Nuxt.js build / generate output<br>.nuxt<br># dist</em></pre><h4>Test the library</h4><p>Let’s do some quick local testing manually to make sure the library can work with Node.js and browser.</p><pre>&gt; npm run build:node</pre><pre>1 + 2 = 3<br>2 - 1 = 1</pre><pre>&gt; npm run build:browser</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bh62kEBEFrGAq3i0kKA51A.png" /></figure><p>Excellent! We just complete our first milestone, it’s time to do the release!</p><h3>2. Automate the releases</h3><p>I used to use <a href="https://github.com/release-it/release-it">release-it</a> to manually release a library, and I need to decide whether it’s a patch, minor or major release.</p><p><a href="https://github.com/semantic-release/semantic-release">semantic-release</a> uses commit messages to decide the release type as long as the commit messages follow the <a href="https://www.conventionalcommits.org/en/v1.0.0/">conventional commits</a> style. And semantic-release has several plugins to generate changelog, publish to Github and NPM with release note, so let’s use it.</p><h4>Install Node.js dependencies</h4><pre>&gt; npm i -D husky @semantic-release/{changelog,git,github,npm,commit-analyzer,release-notes-generator} @commitlint/{cli,config-conventional}</pre><p>We use husky to hook with git commands, basically we need to make sure the commit messages follow the conventional commits style, you will see how it’s configured later on.</p><h4>Local configurations</h4><p>There are several things we need to configure.</p><pre>&gt; touch commitlint.config.js .releaserc</pre><p><strong><em>commitlint.config.js</em></strong></p><pre>module.exports = {<br>  extends: [<br>    &#39;@commitlint/config-conventional&#39;<br>  ]<br>};</pre><p>This is used to lint our commit messages.</p><p><strong><em>.releaserc</em></strong></p><pre>{<br>  &quot;plugins&quot;: [<br>    &quot;@semantic-release/commit-analyzer&quot;,<br>    &quot;@semantic-release/release-notes-generator&quot;,<br>    [&quot;@semantic-release/changelog&quot;, {<br>      &quot;changelogFile&quot;: &quot;docs/CHANGELOG.md&quot;,<br>    }],<br>    &quot;@semantic-release/npm&quot;,<br>    [&quot;@semantic-release/git&quot;, {<br>      &quot;assets&quot;: [&quot;dist/**/*.{js,css}&quot;, &quot;docs&quot;, &quot;package.json&quot;],<br>      &quot;message&quot;: &quot;chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}&quot;<br>    }],<br>    &quot;@semantic-release/github&quot;<br>  ]<br>}</pre><p>This is configuration of semantic-release. There is a very important thing to know that all the plugins are executed in order as defined!</p><p>Update package.json, we are going to name our package by following <a href="https://docs.npmjs.com/using-npm/scope.html">NPM’s scoped packages naming style</a>. Reset the version number to 0.0.0, configure the husky, added a script to do the semantic release later on.</p><p>Noticed that we also have a publishConfig and set the access property to “public”, this is used because we adopt scope package name.</p><pre>&quot;name&quot;: &quot;@jeantimex/calculator&quot;,<br>&quot;version&quot;: &quot;0.0.0&quot;,<br>&quot;husky&quot;: {<br>  &quot;hooks&quot;: {<br>    &quot;commit-msg&quot;: &quot;commitlint -E HUSKY_GIT_PARAMS&quot;<br>  }<br>},<br>&quot;publishConfig&quot;: {<br>  &quot;access&quot;: &quot;public&quot;<br>},<br>&quot;scripts&quot;: {<br>  ...<br>  &quot;semantic-release&quot;: &quot;semantic-release&quot;<br>}</pre><p>Ok, local configuration is complete, let’s move on to the remote side.</p><p>We are going to use <a href="https://travis-ci.org/">Travis CI</a> to help automate the release.</p><h4>Remote configurations: set up Travis</h4><p>First, activate the repository, click on the Sync account button to let Travis pick up the newly created repository from Github.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*scEyeW4Oe7DNhwLdSEKEGg.png" /></figure><p>Click on the “Settings” button next to the green activation button. We are going to create two environment variables.</p><p>Since we are going to publish the library to NPM, we need to create a NPM token to grant permissions for Travis.</p><pre>&gt; npm login<br>&gt; npm profile enable-2fa auth-only<br>&gt; npm token create</pre><pre>┌────────────────┬──────────────────────────────────────┐<br>│ token          │ 01234567-8901-2345-6789-012345678901 │<br>├────────────────┼──────────────────────────────────────┤<br>│ cidr_whitelist │                                      │<br>├────────────────┼──────────────────────────────────────┤<br>│ readonly       │ false                                │<br>├────────────────┼──────────────────────────────────────┤<br>│ created        │ 2020-05-11T01:53:11.292Z             │<br>└────────────────┴──────────────────────────────────────┘</pre><p>Next, we also need to grant permissions for Travis to read and write (publish) to Github. See more details <a href="https://docs.travis-ci.com/user/deployment/pages/#setting-the-github-token">here</a>.</p><p>Below is a screenshot of the Github permissions for the token:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*CBvU1scg2gLEg127YdT3Qw.png" /></figure><p>Once we have the tokens, add them in Travis’s setting page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cq2SaoxN-jjSwWwSXRp-EQ.png" /></figure><p>Now let’s configure Travis.</p><pre>&gt; touch .travis.yml</pre><p><strong><em>.travis.yml</em></strong></p><pre>language: node_js</pre><pre>node_js:<br>  - 12</pre><pre>jobs:<br>  include:<br>    <em># Define the release stage that runs semantic-release<br>    </em>- stage: release<br>      node_js: lts/*<br>      script: skip<br>      deploy:<br>        provider: script<br>        skip_cleanup: true<br>        script:<br>          - npx semantic-release</pre><p>Basically, we are asking Travis to run semantic-release :)</p><h4>Release the library</h4><p>Finally, it’s time to push the release!</p><pre>&gt; git add .<br>&gt; git commit -m &quot;feat: introduce calculator&quot;<br>&gt; git push</pre><p>You will see how Travis builds and deploy the library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xbozJQklWEkmnWyed9Po4w.png" /></figure><p>Once it’s completed, our library will be published to NPM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LmiXX7K-gNYplOJxsTAW5g.png" /></figure><p>And Github shows the new release will nice release note.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cH3YPR6P0L6G4laAmqqyAw.png" /></figure><p>Also a changelog is automatically created!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J9Jbz85mGwFU2QoccRI35Q.png" /></figure><p>🎉 Our calculator is live! Congratulations, you did it!</p><h3>3. Verify the library</h3><p>Now let’s see if the library can work everywhere.</p><p><a href="https://observablehq.com/@observablehq/introduction-to-require">Observable</a> works with AMD libraries, so we can require our calculator there and see if it works, yep it works!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*flVqsJnT5gQVwVdh_Qld2w.png" /></figure><p>Next, let’s test and see if our library works with CommonJS on <a href="https://repl.it/">repl</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*toPm-ICPYG_GKT2Ks_SM2w.png" /></figure><p>At last, our library should work just fine via script tag.</p><pre>&lt;script src=&quot;<a href="https://unpkg.com/@jeantimex/calculator@1.0.0/dist/calculator.js">//unpkg.com/@jeantimex/calculator@1.0.0/dist/calculator.js</a>&quot;&gt;&lt;/script&gt;</pre><pre>&lt;script&gt;<br>  const {add, sub} = calculator;<br>  console.log(&#39;1 + 2 = &#39; + add(1, 2));<br>  console.log(&#39;2 - 1 = &#39; + sub(2, 1));<br>&lt;/script&gt;</pre><p>That’s it, hope you enjoy and find this article helpful.</p><p>Source code: <a href="https://github.com/jeantimex/calculator">https://github.com/jeantimex/calculator</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccce93153dbb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Configure iTerm2 and Vim like a Pro on macOS]]></title>
            <link>https://medium.com/@jeantimex/how-to-configure-iterm2-and-vim-like-a-pro-on-macos-e303d25d5b5c?source=rss-ce35f09414c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e303d25d5b5c</guid>
            <category><![CDATA[powerlevel10k]]></category>
            <category><![CDATA[vim]]></category>
            <category><![CDATA[iterm2]]></category>
            <category><![CDATA[fzf]]></category>
            <category><![CDATA[oh-my-zsh]]></category>
            <dc:creator><![CDATA[Yong Su]]></dc:creator>
            <pubDate>Sun, 01 Dec 2019 21:00:53 GMT</pubDate>
            <atom:updated>2019-12-02T01:48:19.642Z</atom:updated>
            <content:encoded><![CDATA[<h3>Configure iTerm2 and Vim like a Pro</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fa41vhVzTowxppjD31An_w.png" /></figure><h3>Introduction</h3><p>Every time when I got a new computer or reinstalled the macOS, the first thing I would like to do is to set up my terminal and make it look cool. There are several tools I always like to gear up for the terminal including the following:</p><ul><li>iTerm2</li><li>Oh My Zsh</li><li>Powerlevel10k (The coolest theme for Zsh)</li><li>Vim Airline (Vim status bar)</li><li>NERDTree (A file system tree for Vim)</li><li>FZF (fuzzy finder)</li></ul><p>There are already a lot of great articles that teach people how to install and configure the above tools, however, in order to set them up correctly, usually I need to refer to at least 5 separate articles and it took me a while to figure out the necessary steps, and most importantly I don’t remember what I did last time. So I decided to put all I have learned together and write them down, this article will show you how to install and configure all the above tools with necessary and concrete steps, and hope it helps.</p><p>Ok let’s get started.</p><h3>Instructions</h3><p><strong><em>Step 1. Install iTerm2</em></strong></p><p>Make sure you have <a href="https://brew.sh/">Homebrew</a> installed, if not, simply paste the following in your Terminal:</p><pre>$ /usr/bin/ruby -e &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&quot;</pre><p>During the above installation, you may be asked to install the command line developer tools for xcode-select command, go ahead and install it and then finish the Homebrew installation, once it’s completed, you will be able to use brew command to install iTerm2.</p><pre>$ brew cask install iterm2</pre><p><strong><em>Step 2. Install Oh My Zsh</em></strong></p><p><a href="https://ohmyz.sh/">Oh My Zsh</a> is a framework for managing Zsh configuration and it comes with many helpful plugins, themes etc to make you enjoy shell scripting. Install Oh My Zsh is simple:</p><pre>$ sh -c &quot;$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)&quot;</pre><p><strong><em>Step 3. Install and Configure Powerlevel10k Theme</em></strong></p><p><a href="https://github.com/romkatv/powerlevel10k">Powerlevel10k</a> is a fast reimplementation of <a href="https://github.com/Powerlevel9k/powerlevel9k">Powerlevel9k</a> which is probably the most popular Powerline theme for Zsh.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*foOnmV5GeF61YDq5SZxvZw.png" /></figure><p>Run the following commands to install Powerlevel10k:</p><pre>$ git clone --depth=1 <a href="https://github.com/romkatv/powerlevel10k.git">https://github.com/romkatv/powerlevel10k.git</a> ~/powerlevel10k<br>$ echo &#39;source ~/powerlevel10k/powerlevel10k.zsh-theme&#39; &gt;&gt;! ~/.zshrc</pre><p>Now launch iTerm2 and let’s configure Powerlevel10k theme using the configuration wizard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*3XgZC1x0cRGijlQw7SfAcg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*Iy2MzjFUYao3AiKi9ezApw.png" /></figure><p>First install the Meslo Nerd Font, type y. Once the font is installed, restart iTerm2 and continue with the configuration. The wizard will then verify if the font is installed properly by asking you whether you can see some symbols correctly including a diamond, a lock, a Debian logo and some other icons, type y if you see them.</p><p>Next choose a prompt style:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*aswnGieVuOfnXwFUEGhY3Q.png" /></figure><p>The Rainbow style is very popular, I usually go with that. After choosing the prompt style, there are several styles for you to choose, including:</p><ul><li>Show current time?</li><li>Display icons?</li><li>Enable transient prompt?</li><li>Prompt separators, heads, tails, height, spacing, and flow</li></ul><p>Once it’s done, apply the changes to ~/.zshrc.</p><p>Now the Powerlevel10k theme is installed and your screen may look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*-JMGY8AMObEHSNNgFvZR_g.png" /></figure><p>I don’t like the color, let’s fix it, open iTerm2 preferences dialog, go to Profiles &gt; Colors, choose Solarized Dark color preset:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R1A76w9PiMLkufLge_Ipxw.png" /></figure><p>Now your screen should look like the following, the color looks much better, isn’t it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*9p19Y_HoQprj1FCh0GF7xA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*AtbODAlv9HpctNS51Oy_Xg.png" /></figure><p>Well done, we just completed the basic setup for our iTerm2. Let’s move on to configure Vim.</p><p><strong><em>Step 4. Install and Configure Vim Airline</em></strong></p><p><a href="https://github.com/vim-airline/vim-airline">Vim Airline</a> is an awesome Vim plugin that polishes the status bar, it provides a lot of styles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*8FuifozftKr46ZcP5wDAHw.gif" /></figure><p>In order to install Vim Airline, let’s ask a Vim plugin manager to help us, I use <a href="https://github.com/junegunn/vim-plug">Vim Plug</a>, run the following command to install it.</p><pre>$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs \<br>    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim</pre><p>Once Vim Plug is installed, edit ~/.vimrc:</p><pre>call plug#begin(&#39;~/.vim/plugged&#39;)</pre><pre>Plug &#39;vim-airline/vim-airline&#39;<br>Plug &#39;vim-airline/vim-airline-themes&#39;</pre><pre>call plug#end()</pre><p>Save the changes and exit Vim. Now reopen Vim and type in :PlugInstall and hit Enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*43tKVkh9P3bSPiFL0x9dwA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*TaJv6veR8bUB8D5-nDmOCA.png" /></figure><p>Now both Vim Airline and Vim Airline Themes are installed. If you open a file, you should be able to see the status bar like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*OBWC8ethcxJlgGvKRJEzsQ.png" /></figure><p>The status bar doesn’t look like the one from Vim Airline official website, that’s because we have to configure the fonts, run the following commands to install the missing fonts for powerline theme:</p><pre>$ git clone <a href="https://github.com/powerline/fonts.git">https://github.com/powerline/fonts.git</a> --depth=1<br>$ cd fonts<br>$ ./install.sh<br>$ cd ..<br>$ rm -rf fonts</pre><p>Finally, edit ~/.vimrc and add the following line:</p><pre>let g:airline_powerline_fonts = 1</pre><p>This will automatically populate the g:airline_symbols dictionary with the powerline symbols.</p><p>Now our Vim editor should have a better look:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*yDsFdFqXPB7vVGF4zEuLeA.png" /></figure><p><strong><em>Step 5. Install and Configure FZF</em></strong></p><p><a href="https://github.com/junegunn/fzf">FZF</a> allows you to do fuzzy search for files and folders in the Terminal and Vim, we can use brew to install it.</p><pre>$ brew install fzf</pre><pre># To install useful key bindings and fuzzy completion:<br>$ $(brew --prefix)/opt/fzf/install</pre><p>Follow the prompts and answer y(yes), once it’s done, the following has been added to ~/.zshrc:</p><pre>[ -f ~/.fzf.zsh ] &amp;&amp; source ~/.fzf.zsh</pre><p>Add some useful FZF options in the ~/.zshrc:</p><pre>[ -f ~/.fzf.zsh ] &amp;&amp; source ~/.fzf.zsh</pre><pre>export FZF_DEFAULT_OPTS=‘—height=40% —preview=“cat {}” —preview-window=right:60%:wrap’</pre><p>Basically it tells FZF to show the preview window when performing the search.</p><p>Now when you type infzf and Enter in iTerm2, FZF will search in the current directory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*2IuQ13UghlrHWCdpXx4RNg.png" /></figure><p>Use arrow keys to navigate the files, and you will see a preview window on the right.</p><p>Another way to use FZF is to type in some command and then **&lt;TAB&gt;, for example, vim **&lt;TAB&gt;:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*duk0siQ_GZZMlspFZyFPwg.png" /></figure><p>To use FZF in Vim, add the following line to ~/.vimrc:</p><pre>set rtp+=/usr/local/opt/fzf</pre><p>Save it and relaunch Vim, type in :FZF command in Vim, you will now be able to search for the file to edit:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*DKXU5Y_swEmV_45DuazjlQ.png" /></figure><p>Great, we now completed the setup of FZF!</p><p><strong><em>Step 6. Install and Configure NERDTree</em></strong></p><p><a href="https://github.com/scrooloose/nerdtree">NERDTree</a> allows us to navigate the directory inside Vim editor, to install it, let’s use Vim Plug, add the following in bold in ~/.vimrc:</p><pre>call plug#begin(&#39;~/.vim/plugged&#39;)</pre><pre>Plug &#39;vim-airline/vim-airline&#39;<br>Plug &#39;vim-airline/vim-airline-themes&#39;<br><strong>Plug &#39;scrooloose/nerdtree&#39;</strong></pre><pre>call plug#end()</pre><pre>let g:airline_powerline_fonts = 1<br><strong>let g:NERDTreeDirArrowExpandable = &#39;▸&#39;<br>let g:NERDTreeDirArrowCollapsible = &#39;▾&#39;</strong></pre><pre><strong>autocmd StdinReadPre * let s:std_in=1<br>autocmd VimEnter * if argc() == 0 &amp;&amp; !exists(&quot;s:std_in&quot;) | NERDTree | endif</strong></pre><p>Run :PlugInstall command in Vim to complete the plugin installation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*Futycu5idWuA02fImdjtIA.png" /></figure><p>Now NERDTree plugin is installed, to see the directory tree, in Vim editor, type in command :NERDTree:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*zYR1kbtPtHgL4LFQEU2Uzg.png" /></figure><p>Well done, now you can easily navigate the directory inside Vim!</p><p><strong><em>Step 7. Set color scheme for Vim</em></strong></p><p>To make our Vim look more professional, I choose <a href="https://github.com/joshdick/onedark.vim">OneDark</a> theme.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rg52SshjmZKvPV46wd04Qg.png" /></figure><p>To install the theme for Vim, first run the following command in iTerm2:</p><pre>$ git clone <a href="https://github.com/joshdick/onedark.vim.git">https://github.com/joshdick/onedark.vim.git</a> ~/onedark<br>$ cd ~/onedark<br>$ mkdir ~/.vim/colors<br>$ cp colors/onedark.vim ~/.vim/colors/<br>$ cp autoload/onedark.vim ~/.vim/autoload/</pre><p>Then edit ~/.vimrcand add the following:</p><pre>colorscheme onedark<br>syntax on<br>set number<br>highlight Normal ctermbg=None<br>highlight LineNr ctermfg=DarkGrey</pre><p>Now our Vim should look much prettier :)</p><h3>Conclusion</h3><p>As you can see, the whole process involves a lot of referencing, I hope this article can help you set up your own development environment around iTerm2 and Vim.</p><p>Happy coding!</p><h3>References</h3><ol><li>How to Jazz Up Your Bash Terminal — A Step By Step Guide With Pictures [<a href="https://www.freecodecamp.org/news/jazz-up-your-bash-terminal-a-step-by-step-guide-with-pictures-80267554cb22/">link</a>]</li><li>macOS ohmyzsh + tmux + vim + iTerm2 + Powerlevel9k = Badass terminal [<a href="https://blogs.technet.microsoft.com/jessicadeen/linux/macos-ohmyzsh-tmux-vim-iterm2-powerlevel9k-badass-terminal/">link</a>]</li><li>Beautifying your terminal with Zsh, Prezto, &amp; Powerlevel9k [<a href="https://medium.com/@oldwestaction/beautifying-your-terminal-with-zsh-prezto-powerlevel9k-9e8de2023046">link</a>]</li><li>How to Customize your Terminal with ZSH [<a href="https://hackernoon.com/how-to-trick-out-terminal-287c0e93fce0">link</a>]</li><li>Solarized [<a href="https://ethanschoonover.com/solarized/">link</a>]</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e303d25d5b5c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create your own CocoaPods library]]></title>
            <link>https://medium.com/@jeantimex/create-your-own-cocoapods-library-da589d5cd270?source=rss-ce35f09414c------2</link>
            <guid isPermaLink="false">https://medium.com/p/da589d5cd270</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Yong Su]]></dc:creator>
            <pubDate>Mon, 25 Feb 2019 01:23:39 GMT</pubDate>
            <atom:updated>2019-06-18T16:23:21.950Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learn how to create a pod from scratch and utilize Travis and Codecov to make the pod robust.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NVpPzk50hORrIqe1FfBztA.png" /></figure><h3>Introduction</h3><p>As an iOS developer, you may have used a few CocoaPods libraries in your project, and you may have been very familiar with how to install them and call their methods. However, have you ever dreamed of contributing to the iOS open-source community by distributing your own pod(CocoaPods library)? Imagine many iOS apps are going to use your awesome library, isn’t that fantastic?</p><p>In this tutorial, I will show you how to distribute a simple pod. In addition to that, you will also learn how to leverage Travis CI and Codecov to make sure your pod is reliable and robust.</p><h3>Overview</h3><p>There are many different ways to create a pod. The most common one is to follow CocoaPods official document <a href="https://guides.cocoapods.org/making/using-pod-lib-create">Using Pod Lib Create</a>, basically, you can use the following command to quickly bootstrap an Xcode workspace to develop a new pod:</p><pre>&gt; pod lib create <strong>[pod name]</strong></pre><p>In the bootstrapped workspace, one thing I don’t like is that the codes related to unit test are nested inside the example target, it doesn’t make sense to me. After some trial and error, I figured out a way to create a pod from scratch and nicely organize the codes for unit testing and examples.</p><p>Here is a quick overview of all the steps to create a pod:</p><ol><li>Set up Xcode project and necessary targets</li><li>Link to Github</li><li>Implement the pod</li><li>Write unit tests</li><li>Configure Travis CI and Codecov</li><li>Publish the pod</li></ol><p>At the time of writing, I am using the following Softwares:</p><ul><li>macOS Mojave 10.14.3</li><li>Xcode 10.1</li><li>Swift 4.2</li><li>cocoapods 1.6.0</li></ul><p>Ok, let’s get started!</p><h3>Set up Xcode project and necessary targets</h3><p>Actually, before we create the project, there’s an important task to do, let’s name our pod SwiftyLib and make sure the name has not been taken on <a href="https://cocoapods.org/">CocoaPods</a>, luckily it’s not been submitted, so we can go ahead.</p><p><strong>Create a Cocoa Touch Framework Xcode project</strong></p><p>Under the hood, a CocoaPods library is a Cocoa Touch framework library. Launch Xcode and create a new project, choose Cocoa Touch Framework .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ebA9eVspULwjpbi2P5Etkg.png" /></figure><p>Enter the name SwiftyLib<strong> </strong>, select the checkbox Include Unit Tests . On the next page select the project location and do not check Create Git repository on my Mac as we are going to create it later on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VcxWgSI-xwmzDT_wOnKAYQ.png" /></figure><p>After you hit the Create button, the project is created and the workspace should look like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*7RLcEsLlsbvLjpIaQvg8GA.png" /></figure><p><strong>Prepare the targets</strong></p><p>As you can see, we now have a project called SwiftyLib and it has two targets:</p><ol><li>SwiftyLib: Our pod implementation will happen in here</li><li>SwiftyLibTests: Unit tests our pod and collects code coverage</li></ol><p>In Xcode, each target has a scheme that allows you to control build and test behaviors. As you can see in the SwiftyLib scheme, when we perform the Test command, it will trigger the tests written in SwiftyLibTests target.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8c7cMTfeXOA57uebZuUsDg.png" /></figure><p>In many Cocoapods projects, developers like to put some demos or examples as part of their pods, those will help people better understand how to use the pods. To do that, let’s add a new target called SwiftyLibExamples . Select SwiftyLib project from the project navigator, then choose File &gt; New &gt; Target…, select Single View App as the template and click on Next .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OTju9iGMekWZaUXQy9yRKQ.png" /></figure><p>Enter the name SwiftyLibExamples and click on Finish .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JgTJfbZP0r3eESWHw5ABhA.png" /></figure><p>Now the project navigator should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wkR5xkqFBVIv5bKAqt5JGw.png" /></figure><p>The SwiftyLibTests is not nested inside the SwiftyLibExamples . Later we will implement the examples using our pod, for now, we just complete our first step and successfully scaffold the project for making a pod!</p><h3>Link to Github</h3><p>Needless to say, Github is the best hosting service for open-source projects, more importantly, when you publish the CocoaPods library, Cocoapods asks you to specify the location from where the source should be retrieved, and Github is a perfect choice.</p><p><strong>Create a new repository</strong></p><p>Go to <a href="https://github.com/">Github</a> and create a new project called SwiftyLib , keep other settings as default and click on Create repository , an empty Github repository is now created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bg8fyo6Xcn5x3Ai3Iq92Ow.png" /></figure><p>In the next screen, we are going to use the following information to link our existing Xcode project:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oNghG0nIjWoyIhqgMIpvCA.png" /></figure><p><strong>Link existing project</strong></p><p>Open up a terminal, navigate to the SwiftyLib Xcode project folder, and type in the following commands:</p><pre>&gt; git init<br>&gt; git remote add origin git@github.com:{USERNAME}/SwiftyLib.git<br>&gt; git add .<br>&gt; git commit -m &quot;Initial project setup&quot;<br>&gt; git push -u origin master</pre><p><strong>README and MIT License</strong></p><p>Now we have uploaded our source codes to Github! Before we finish this section, let’s create a README.md file and an MIT license file from the Github page. To create a README.md click on the Add a README button, to add an MIT license file, click on the Create new file button and follow Github’s official guide <a href="https://help.github.com/en/articles/adding-a-license-to-a-repository">here</a>, it’s really simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gCjh-p2K_eo6V2KKqMzAlA.png" /></figure><p>Once you are done, type in the following command to sync with the remote repository.</p><pre>&gt; git pull<br>...<br>2 files changed, 24 insertions(+)<br>create mode 100644 LICENSE<br>create mode 100644 README.md</pre><p>Well done, you have just completed another milestone!</p><h3>Implement the pod</h3><p>It’s time to write some Swift codes and implement our SwiftyLib. As we mentioned earlier, all the implementation is going to happen in the SwiftyLib target. In the project navigator, right click on the SwiftyLab target and select New File...</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r3vghW4mB0ysulxSI7-OHw.png" /></figure><p>Choose Swift File as the new file template, click on Next …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LI1QzI4_1Ax2_cSGmGqMgw.png" /></figure><p>Name the file as SwiftyLib , make sure this file belongs to the SwiftyLib target and save it in the SwiftyLib folder as shown in the screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lagvmuIuuSvhJPm9xT7GwQ.png" /></figure><p>Let’s edit the newly created SwiftyLib.swift file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d03b383cadd3cf6d012eaf7e944d65ee/href">https://medium.com/media/d03b383cadd3cf6d012eaf7e944d65ee/href</a></iframe><p>Our library is fairly simple! It has two functions to do the calculation. Save the file. Remember, whenever you edit files in the SwiftyLib target, in order to let other targets use them, don’t forget to build the SwiftyLib target! Click on the Build button or use the keyboard shortcut ⇧⌘R Shift-Command-R .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RztNZ83SdXs9X-zpxhZQkQ.png" /></figure><p>we just implemented our SwiftyLib library, let’s write some unit test cases.</p><h3>Write unit tests</h3><p>Unit testing is crucial for making sure your library is robust, and since our library is pretty simple, writing unit tests is easy :)</p><p>Edit theSwiftyLibTests.swift :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01c3fb63ea289856acde83dd61a02d04/href">https://medium.com/media/01c3fb63ea289856acde83dd61a02d04/href</a></iframe><p>Here we only test the add() function. Run the unit test by clicking on the Test task 🔧:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uk89vZyMIf1tRfwjsEnl3A.png" /></figure><p>The test case should be passed, switch to the reports navigator and check the code coverage:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bRdeEutStmLbLWrXzJJzUQ.png" /></figure><p>As you can see, the coverage is only 50%, because we didn’t write a unit test for the sub() function, let’s do that now!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6d2c8168d202dc4bcfd4f18641f2a72/href">https://medium.com/media/a6d2c8168d202dc4bcfd4f18641f2a72/href</a></iframe><p>Now run the test again and our code coverage should be improved to 100%!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pjphFrdyXbHem1cZUKFqCQ.png" /></figure><p>At this point, we have a pretty robust pod, let’s save all our changes and push them to Github.</p><pre>&gt; git add .<br>&gt; git commit -m &quot;Added test cases&quot;<br>&gt; git push</pre><h3>Configure Travis CI and Codecov</h3><p>Whenever we push new changes to Github, we should test our pod and make sure all test cases are not broken.</p><blockquote><a href="https://travis-ci.org/"><strong>Travis CI</strong> </a>is a hosted, distributed continuous integration service used to build and test software projects hosted at GitHub.</blockquote><p>We can leverage Travis to help us run test cases and submit the code coverage report to Codecov.</p><blockquote><a href="https://codecov.io/"><strong>Codecov</strong></a> is a reporting tool that is intended to process any coverage report format into a format that is standard across <strong>Codecov</strong>. You may change the configuration of how <strong>Codecov</strong> processes reports and expresses coverage information.</blockquote><p>In order to let Travis pick up any change in our Github repo, sync up your Github account on Travis and enable our SwiftyLib repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*QBLqpNO6pg8Wt2goiFzucw.png" /></figure><p>Create a .travis.yml file in our project folder:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36245ce81ad2c5796ca418b354c2801e/href">https://medium.com/media/36245ce81ad2c5796ca418b354c2801e/href</a></iframe><p>Basically, it instructs Travis to run the unit tests on two different devices that run different iOS versions.</p><p>You can ask Travis to test on more devices, but make sure the version of iPhone simulator supports those devices, you can check the full list <a href="https://docs.travis-ci.com/user/reference/osx/#xcode-version">here</a>.</p><p>Save the .travis.yml file and push it to Github, trigger a build on Travis, you should see that Travis runs the test cases for the commit you submitted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yFPsMv54nctABlHMp9delw.png" /></figure><p>Next, let’s ask Travis to send the code coverage report to Codecov. Before we go too far, let’s take a look and see what Travis has done so far. Travis executes the following script to run the test:</p><pre>&gt; xcodebuild test \<br>  <strong>-enableCodeCoverage YES</strong> \<br>  -project SwiftyLib.xcodeproj \<br>  -scheme SwiftyLib \<br>  -sdk $TEST_SDK \<br>  -destination &quot;platform=iOS Simulator,OS=$OS,name=$NAME&quot; \<br>  ONLY_ACTIVE_ARCH=YES</pre><p>Notice that the code coverage report is generated with the xcodebuild test command. If we follow Codecov’s guide, we can simply push the code coverage report to Codecov with the commands below:</p><pre>&gt; bash &lt;(curl -s https://codecov.io/bash) -t {CODECOV_TOKEN}</pre><p>you probably will see some weird report with unnecessary files being reported, but we only want to see the coverage report like the one we saw earlier in Xcode.</p><p><strong>Slather</strong></p><p>To fix the problem, that is to let Travis send the accurate code coverage report to Codecov, let’s borrow another tool <a href="https://github.com/SlatherOrg/slather"><strong>Slather</strong></a>. With slather, we can specify how to collect the code coverage information accurately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U1-eXGAEHnTean8cD0MBEw.jpeg" /></figure><p>First, let’s create the configuration file to define how to collect the code coverage information, create a new file called .slather.yml :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1690896ce9e9e90433114473475134dd/href">https://medium.com/media/1690896ce9e9e90433114473475134dd/href</a></iframe><p>Here we tell slather to collect the code coverage information from SwiftyLib scheme and please ignore the codes from the unit tests.</p><p>Now edit .travis.yml and add an after_success section to upload the report that collected by slather to Codecov after the unit testing is completed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf00dd6a2482cbbea16a9c2ceb929e5d/href">https://medium.com/media/cf00dd6a2482cbbea16a9c2ceb929e5d/href</a></iframe><p>If you take a look at the log from Travis, you will see that the reports are being collected by slather and sent to Codecov:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tBTMqihm7afiYOu2Mhx_ZQ.png" /></figure><p>You can check the code coverage details on Codecov:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9DUEAb7Zy0pALmxoarn3KQ.png" /></figure><p>Excellent! We reached another milestone, our pod is robust and protected by Travis and Codecov.</p><h3>Publish the pod</h3><p>Finally, it’s time to publish our pod! First, install cocoapods .</p><pre>&gt; gem install cocoapods</pre><p>Then create a podspec file that defines our pod, e.g., where to find the source.</p><pre>&gt; pod spec create <strong>SwiftyLib<br>...<br></strong>Specification created at <strong>SwiftyLib.podspec</strong></pre><p>Edit the SwiftyLib.podspec file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db5a5bd93b09ba9be8cf7a9e0f906739/href">https://medium.com/media/db5a5bd93b09ba9be8cf7a9e0f906739/href</a></iframe><p>Check if SwiftyLib.podspec is correct, fix issues if there is any</p><pre>&gt; pod lib lint<br>...<br>-&gt; SwiftyLib (0.0.1)<br>SwiftyLib passed validation.</pre><p>Great! Let’s save our changes to Github!</p><pre>&gt; git add .<br>&gt; git commit -m &quot;Added SwiftyLib.podspec&quot;<br>&gt; git push</pre><p><strong>Start to distribute our library</strong></p><p>Tag the correct version</p><pre>&gt; git tag 0.0.1<br>&gt; git push origin 0.0.1</pre><p>Then push it!</p><pre>&gt; <strong>pod trunk push</strong><br>...<br>Updating spec repo `master`<br>---------------------------<br>🎉  Congrats<br>🚀  SwiftyLib (0.0.1) successfully published<br>📅  February 24th, 15:49<br>🌎 <a href="https://cocoapods.org/pods/SwiftyLib">https://cocoapods.org/pods/SwiftyLib</a><br>👍 Tell your friends!<br>---------------------------</pre><p>Notice that the version number should match the spec.version defined in the SwiftyLib.podspec .</p><p><strong>Congratulations!</strong> You just published the CocoaPods library to the open-source community!</p><p>The project source code can be found in <a href="https://github.com/jeantimex/SwiftyLib">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da589d5cd270" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to open source your React components]]></title>
            <link>https://medium.com/@jeantimex/how-to-open-source-your-react-components-a2128c75b5b6?source=rss-ce35f09414c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2128c75b5b6</guid>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[deployment-automation]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[travis]]></category>
            <dc:creator><![CDATA[Yong Su]]></dc:creator>
            <pubDate>Sat, 15 Sep 2018 23:22:07 GMT</pubDate>
            <atom:updated>2018-09-16T06:53:14.041Z</atom:updated>
            <content:encoded><![CDATA[<p>Learning how to use productivity tools will save you a great amount of time</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f1HRu4YeZDn3PAS81QjuNg.jpeg" /></figure><h3>Preface</h3><p>Have you ever thought about open source your awesome React components? Follow this tutorial and you will learn how to use some of the best productivity tools to help you scaffold a project, write a React component and publish it to NPM so that it can be used by developers around the world.</p><h3>Things Required</h3><p>First, let’s think about what we need before writing any code, below is a list of the basic requirement for open-sourcing a React component:</p><ul><li><strong>Babel and Webpack</strong></li></ul><p>Although they are not necessary, they will make your life much easier. Babel allows you to use modules, JSX with ES6 syntax. Webpack allows you to hot reload the component during the development using HMR(Hot Module Replacement), you can plug in Sass loader to make writing CSS with better experience, and use the Uglify plugin to minify your JavaScript codes. Also Webpack helps you bundle the final assets for distribution.</p><ul><li><strong>Unit Test</strong></li></ul><p>Function test and code coverage are important for open source project, who wants to use a buggy component that doesn’t work as expected?</p><ul><li><strong>ES Module and UMD</strong></li></ul><p>Eventually our React component should be independent and reusable, and it needs to be self-contained. There are several ways to achieve the encapsulation, the most common ones are ES Module and UMD. With ES Module, we can require or import the component, whereas UMD allows us to use the component by loading it with &lt;script&gt; tag.</p><ul><li><strong>Deployment</strong></li></ul><p>Once we finish our development, how do we publish it to NPM? Github is the best place to host our repo, and how to make the whole release cycle easier so that whenever a new version published to NPM, our Github release page also shows the new release information including the relative changes.</p><p><a href="https://toggl.com/programming-princess/">GIT the Princess</a>!</p><p>As a JavaScript developer, I used to tackle all the above requirements by spending hours or even days of time to grab the necessary tools and made them work as desired, that helped me a lot in understanding how things work together and I enjoyed it. I even built my own tools like <a href="https://github.com/jeantimex/react-webpack-boilerplate">React Webpack Boilerplate</a> and <a href="https://github.com/jeantimex/slush-webpack-html">Slush Webpack HTML</a> to help me scaffold the websites quicker. But I haven’t tried to open source a React component, and whenever I am passionate to start doing it, I remember the following picture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*GptpYMQzwDoCtF2yqfOYiQ.png" /></figure><p>Yes, scaffolding a project takes time and I don’t want to repeat my work!</p><h3>Scaffold in 3 Steps</h3><p>Luckily, I found some tools which are super awesome to help me solve the above requirements.</p><p>Before we go too far, make sure the component name is still available on NPM, andnpm search should help. Let’s say we are going to create a fancy React button, not sure see if react-fancy-button is already been taken:</p><pre>&gt; npm search react-fancy-button</pre><pre>NAME               | DESCRIPTION  | VERSION | DATE       | ...<br>react-fancy-button | React Button | 1.0.5   | 2017-11-01 | ...</pre><p>Unfortunately, we have to pick another name react-cool-button.</p><p><a href="https://github.com/insin/nwb"><strong>nwb</strong></a></p><p>Sometimes I use <a href="https://github.com/facebook/create-react-app">Create React App</a> to play with some React components, but it’s not designed for making a single React component, it’s for building a React website.</p><p>nwb is a toolkit for developing React apps, Preact apps, Vanilla JavaScript apps, React components and libraries and npm modules for the web! The most important thing is hides all the complexity of setting up Webpack, Babel, unit test etc.</p><p>This is how I use nwb to scaffold a React component:</p><p><strong><em>Step 1.</em></strong><em> </em>Install nwb and create the project folder</p><pre>&gt; npm install -g nwb<br>&gt; nwb new react-component react-cool-button</pre><pre>Creating a react-component project...<br>? Do you want to create an ES modules build for use by compatible bundlers? Yes<br>? Do you want to create a UMD build for global usage via &lt;script&gt; tag? No<br>  create .gitignore<br>  create .travis.yml<br>  create CONTRIBUTING.md<br>  create README.md<br>  create demo/src/index.js<br>  create nwb.config.js<br>  create package.json<br>  create src/index.js<br>  create tests/.eslintrc<br>  create tests/index-test.js<br>✔ Installing react and react-dom<br>✔ Initing Git repo</pre><p>nwb created a folder named react-cool-button and installed the necessary npm packages. Run npm start and open a browser tab, go to <a href="http://localhost:3000,">http://localhost:3000</a> , you will see a demo page for the React component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D1KvFlCKkFo1U42ug0PelQ.png" /></figure><p>The coolest thing is if you modify the React Component in src/index.js or the demo page indemo/src/index.js , the demo page will be refreshed automatically!</p><p><strong><em>Step 2.</em></strong> Setup Github repository</p><p>Go to Github and create a new repository called react-cool-button , do not initialize the repository with a README, we just need an empty repository and soon will set up with the new react-cool-button folder just created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*zT65inHwuXi0jU2fJin8Mw.png" /><figcaption>Setup a new repository on Github</figcaption></figure><p>Now if you type git remote -v in react-cool-button folder, it will show you empty result. Let’s fix it so we can push local changes to remote server.</p><pre>&gt; git remote add origin git@github.com:YOUR-GITHUB-USERNAME/react-cool-button.git<br>&gt; git config user.name YOUR-GITHUB-USERNAME<br>&gt; git config user.email YOUR-GITHUB-EMAIL<br>&gt; git remote -v<br>origin <a href="/service/mailto:git@github.com">git@github.com</a>:YOUR-GITHUB-USERNAME/react-cool-button.git (fetch)<br>origin <a href="/service/mailto:git@github.com">git@github.com</a>:YOUR-GITHUB-USERNAME/react-cool-button.git (push)<br>&gt; git push -u origin master</pre><pre>...</pre><pre>Branch &#39;master&#39; set up to track remote branch &#39;master&#39; from &#39;origin&#39;.</pre><p><strong><em>Step 3.</em></strong> Setup deployment with Travis CI</p><p>Travis is one of the best CI services that allows us to execute tasks whenever there is a new push to the remote repository. We would like to use it to help us publish our React component to NPM when a commit is pushed to master branch or a new pull request is merged to master branch as well. First we need to let Travis be aware of our new repository, go to Travis and let it monitor the react-cool-button repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f0HQsYUGFtmrxGKvtwmrNQ.png" /><figcaption>Turn on Travis for react-cool-button repository</figcaption></figure><p><a href="https://github.com/semantic-release/semantic-release"><strong>semantic-release</strong></a></p><p>Publishing to npm is simple, we can use npm publish , but we don’t want to do it manually, also we want to update the Github release page to include the new release information. semantic-release is the perfect tool to achieve this, and it’s super easy to set it up.</p><p>First, install semantic-release-cli .</p><pre>&gt; npm i -g semantic-release-cli</pre><p>Then use it to set up all the necessary connections and authentication with NPM, Github and Travis:</p><pre>&gt; cd react-cool-button<br>&gt; semantic-release-cli setup</pre><pre>? What is your npm registry? <a href="https://registry.npmjs.org/">https://registry.npmjs.org/</a><br>? What is your npm username? YOUR-NPM-USERNAME<br>? What is your npm password? [hidden]<br>? What is your GitHub username? YOUR-GITHUB-USERNAME<br>? What is your GitHub password? [hidden]<br>? What is your GitHub two-factor authentication code? [hidden]<br>? What CI are you using? Travis CI<br>? Do you want a `.travis.yml` file with semantic-release setup? Yes<br>? Do you want to overwrite the existing `.travis.yml`? No</pre><p>The package.json file is now updated:</p><pre>{<br>  &quot;name&quot;: &quot;react-cool-button&quot;,<br>  <strong>&quot;version&quot;: &quot;0.0.0-development&quot;,</strong><br>  &quot;description&quot;: &quot;react-cool-button React component&quot;,<br>  &quot;main&quot;: &quot;lib/index.js&quot;,<br>  &quot;module&quot;: &quot;es/index.js&quot;,<br>  &quot;files&quot;: [<br>    &quot;css&quot;,<br>    &quot;es&quot;,<br>    &quot;lib&quot;,<br>    &quot;umd&quot;<br>  ],<br>  &quot;scripts&quot;: {<br>    &quot;build&quot;: &quot;nwb build-react-component&quot;,<br>    &quot;clean&quot;: &quot;nwb clean-module &amp;&amp; nwb clean-demo&quot;,<br>    &quot;prepublishOnly&quot;: &quot;npm run build&quot;,<br>    &quot;start&quot;: &quot;nwb serve-react-demo&quot;,<br>    &quot;test&quot;: &quot;nwb test-react&quot;,<br>    &quot;test:coverage&quot;: &quot;nwb test-react --coverage&quot;,<br>    &quot;test:watch&quot;: &quot;nwb test-react --server&quot;,<br>    <strong>&quot;travis-deploy-once&quot;: &quot;travis-deploy-once&quot;,<br>    &quot;semantic-release&quot;: &quot;semantic-release&quot;</strong><br>  },<br>  &quot;dependencies&quot;: {},<br>  &quot;peerDependencies&quot;: {<br>    &quot;react&quot;: &quot;16.x&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;nwb&quot;: &quot;0.23.x&quot;,<br>    &quot;react&quot;: &quot;^16.5.1&quot;,<br>    &quot;react-dom&quot;: &quot;^16.5.1&quot;,<br>    <strong>&quot;travis-deploy-once&quot;: &quot;^5.0.7&quot;,<br>    &quot;semantic-release&quot;: &quot;^15.9.15&quot;</strong><br>  },<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;homepage&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;MIT&quot;,<br>  <strong>&quot;repository&quot;: {<br>    &quot;type&quot;: &quot;git&quot;,<br>    &quot;url&quot;: &quot;</strong><a href="https://github.com/jeantimex/react-cool-button.git"><strong>https://github.com/jeantimex/react-cool-button.git</strong></a><strong>&quot;<br>  },</strong><br>  &quot;keywords&quot;: [<br>    &quot;react-component&quot;<br>  ]<br>}</pre><p>As you can see, running semantic-release-cli setup modified the package.jsonfile with the highlighted sections.</p><ul><li><strong>0.0.0-development</strong></li></ul><p>semantic-release calculates a new version for you based on the commit message! The commit message needs to follow <a href="https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines"><strong>Angular Commit Message Conventions</strong></a>. If you are not sure what it is, read <a href="https://blog.greenkeeper.io/introduction-to-semantic-release-33f73b117c8"><strong>Introduction to Semantic Release</strong></a>. Basically your commit message should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_0qcHDuC6aicoQs7LYdKpA.png" /></figure><p>semantic-release will bump up the new version based on the commit message like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*AYJgfgAsJo_6LLtvCRAD_A.png" /></figure><ul><li><strong>travis-deploy-once</strong></li></ul><p>travis-deploy-once ensures that the release happens only once, when all the builds have finished, instead of releasing for every tested Node version.</p><p>Now let’s modify the .travis.yml file:</p><pre>sudo: false</pre><pre>language: node_js</pre><pre><strong>cache:<br>  directories:<br>    - ~/.npm</strong></pre><pre><strong>notifications:<br>  email: false</strong></pre><pre>node_js:<br>  - 8</pre><pre>before_install:<br>  - npm install codecov.io coveralls</pre><pre>after_success:<br>  - cat ./coverage/lcov.info | ./node_modules/codecov.io/bin/codecov.io.js<br>  - cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js<br>  <strong>- npm run build<br>  - npm run travis-deploy-once &quot;npm run semantic-release&quot;</strong></pre><pre>branches:<br>  only:<br>    - master</pre><p>npm run build makes sure the distribution folder dist is generated for publishing to NPM. Once the dist folder is generated, run semantic-release .</p><p>Since package.json is updated with new packages, let’s make sure the package-lock.json is also updated, run npm install .</p><pre>&gt; npm install</pre><p>Let’s save our changes and create a new commit:</p><pre>&gt; git add -A<br>&gt; git commit -m &quot;fix: Finish scaffolding&quot;<br>&gt; git push</pre><p>Because we push directly to the master branch, Travis will trigger a job to perform unit test, build and publish to NPM. The react-cool-button package is now listed in NPM:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*smGxTVxS-kxFws2Y2n9TbA.png" /></figure><p>🎉 Congratulations! We just published our React component! And the Github release page is also updated automatically:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*CCjE7MOBP1AzKG1X0qwf6A.png" /></figure><h3>Writing React Components</h3><p>At this point, all the heavy lifting tasks are completed, now it’s time to enjoy the development of our fancy React button!</p><p>Use your favorite code editor and open the react-cool-button project.</p><ul><li>The src folder will contain all the source code for our React component.</li><li>The tests folder will contain all the unit tests.</li><li>The demo folder is used to showcase the React component.</li><li>The dist folder will be generated by running npm run build and it will contain all the JavaScript codes for npm distribution.</li></ul><p><strong><em>Step 1.</em></strong> Create CoolButton folder inside src and have the following files in it:</p><pre>src<br>├── CoolButton<br>│   ├── CoolButton.js<br>│   ├── index.js<br>│   └── styles.css<br>└── index.js</pre><p><strong><em>src/CoolButton/CoolButton.js:</em></strong></p><pre>import React, { Component } from &#39;react&#39;;<br>import &#39;./styles.css&#39;;</pre><pre>class CoolButton extends Component {<br>  render() {<br>    return (<br>      &lt;button className=&quot;cool-button&quot;&gt;<br>        {this.props.children}<br>      &lt;/button&gt;<br>    );<br>  }<br>}</pre><pre>export default CoolButton;</pre><p><strong><em>src/CoolButton/styles.css:</em></strong></p><pre>.cool-button {<br>  background-color: #fff;<br>  border-radius: 28%;<br>  box-shadow: 0 5px 15px -5px rgba(0, 0, 0, 0.1);<br>  display: inline-block;<br>  height: 90px;<br>  line-height: 90px;<br>  overflow: hidden;<br>  position: relative;<br>  text-align: center;<br>  width: 90px;<br>}</pre><p><strong><em>src/CoolButton/index.js</em>:</strong></p><pre>export { default as CoolButton } from &#39;./CoolButton&#39;;</pre><p><strong><em>src/index.js:</em></strong></p><pre>export { CoolButton } from &#39;./CoolButton&#39;;</pre><p>Now modify the <strong><em>demo/src/index.js</em></strong> to use the CoolButton:</p><pre>import React, {Component} from &#39;react&#39;<br>import {render} from &#39;react-dom&#39;</pre><pre>import { CoolButton } from &#39;../../src&#39;</pre><pre>class Demo extends Component {<br>  render() {<br>    return &lt;div&gt;<br>      &lt;h1&gt;react-cool-button Demo&lt;/h1&gt;<br>      &lt;CoolButton&gt;Cool&lt;/CoolButton&gt;<br>    &lt;/div&gt;<br>  }<br>}</pre><pre>render(&lt;Demo/&gt;, document.querySelector(&#39;#demo&#39;))</pre><p>If you run npm start , you will see the newly created CoolButton on the demo page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*9kUvPRmfhxSPoqt4maDtDA.png" /></figure><p>We have to modify the unit test, rename the index-test.js to CoolButton-test.js and edit the content like so:</p><pre>import expect from &#39;expect&#39;<br>import React from &#39;react&#39;<br>import {render, unmountComponentAtNode} from &#39;react-dom&#39;</pre><pre>import { CoolButton } from &#39;src/&#39;</pre><pre>describe(&#39;CoolButton&#39;, () =&gt; {<br>  let node</pre><pre>beforeEach(() =&gt; {<br>    node = document.createElement(&#39;div&#39;)<br>  })</pre><pre>afterEach(() =&gt; {<br>    unmountComponentAtNode(node)<br>  })</pre><pre>it(&#39;should render the CoolButton&#39;, () =&gt; {<br>    render(&lt;CoolButton&gt;Cool&lt;/CoolButton&gt;, node, () =&gt; {<br>      expect(node.innerHTML).toContain(&#39;Cool&#39;)<br>    })<br>  })<br>})</pre><p>Run npm run test and make sure it passes.</p><p>Finally let’s publish the new updates to NPM! All we need to do is commit the changes to master branch, make sure follow the Angular Commit Message Conventions:</p><pre>&gt; git add -A<br>&gt; git commit -m &quot;feat: Introduce CoolButton React component&quot;</pre><p>Once Travis completes the build, the react-cool-button package will be updated to v1.1.0 and you can ask your friends to try out this cool React button:</p><pre>&gt; npm install react-cool-button</pre><h3>Conclusion</h3><p>Managing an open source project is not easy, using the correct tools can help you save a lot of time. I hope you enjoy this tutorial and it’s helpful to you.</p><p>The source code of this tutorial can be found on my <a href="https://github.com/jeantimex/react-cool-button">Github</a> page.</p><h3>About me</h3><p>At Box, I have been using React for three years, I contribute to <a href="https://www.npmjs.com/package/box-react-ui">Box React UI</a> which is a collection of React components designed elegantly for Box projects. Also I maintain several other open source projects like <a href="https://github.com/jeantimex/react-webpack-boilerplate">React Webpack Boilerplate</a>, <a href="https://github.com/jeantimex/javascript-problems-and-solutions">JavaScript Problems and Solutions</a>, <a href="https://github.com/jeantimex/ios-swift-collapsible-table-section">iOS Collapsible Table Section</a>, <a href="https://github.com/jeantimex/klotski">Klotski</a> etc.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2128c75b5b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Implement Collapsible Table Section in iOS]]></title>
            <link>https://medium.com/@jeantimex/how-to-implement-collapsible-table-section-in-ios-142e0c6266fd?source=rss-ce35f09414c------2</link>
            <guid isPermaLink="false">https://medium.com/p/142e0c6266fd</guid>
            <category><![CDATA[custom-cell]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[collapsible-section]]></category>
            <dc:creator><![CDATA[Yong Su]]></dc:creator>
            <pubDate>Sun, 02 Oct 2016 02:04:53 GMT</pubDate>
            <atom:updated>2017-07-31T06:05:47.892Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*aM59uOjes05-u7cuvHMlPA.gif" /></figure><p>🎉 Finally the CocoaPod is released! See <a href="https://github.com/jeantimex/CollapsibleTableSectionViewController">here</a>.</p><p>This is a simple iOS project demonstrates how to implement collapsible table section programmatically, that is no main storyboard, no XIB, no need to register nib, just pure Swift 3!</p><p>In this project, the table view automatically resizes the height of the rows to fit the content in each cell, and the custom cell is also implemented programmatically.</p><p>The source code can be found on my <a href="https://github.com/jeantimex/ios-swift-collapsible-table-section">Github</a>.</p><h3>How to implement collapsible table sections?</h3><h4>Step 1. Prepare the Data</h4><p>Let’s say we have the following data that is grouped to different sections, each section is a <strong><em>Section</em></strong> object:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e19b8f71ee894c6f9e9bbdd0cd0f9c22/href">https://medium.com/media/e19b8f71ee894c6f9e9bbdd0cd0f9c22/href</a></iframe><p><strong><em>collapsed</em></strong> indicates whether the current section is collapsed or not, by default is <strong><em>false</em></strong>.</p><h4>Step 2. Setup TableView to Support Autosizing</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6daa7013c0b477f34f2ea9491fa73c14/href">https://medium.com/media/6daa7013c0b477f34f2ea9491fa73c14/href</a></iframe><h4>Step 3. The Section Header</h4><p>According to <a href="https://developer.apple.com/reference/uikit/uitableviewheaderfooterview">Apple API reference</a>, we should use <strong><em>UITableViewHeaderFooterView</em></strong>. Let’s subclass it and implement the section header <strong><em>CollapsibleTableViewHeader</em></strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20b90974f45cee479f56d92166772f58/href">https://medium.com/media/20b90974f45cee479f56d92166772f58/href</a></iframe><p>We need to collapse or expand the section when user taps on the header, to achieve this, let’s borrow <strong><em>UITapGestureRecognizer</em></strong>. Also we need to delegate this event to the table view to update the <strong><em>collapsed</em></strong> property.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56872562478b8c04ef626ac15485f8fd/href">https://medium.com/media/56872562478b8c04ef626ac15485f8fd/href</a></iframe><p>Since we are not using any storyboard or XIB, how to do auto layout programmatically? The answer is <strong><em>NSLayoutConstraint</em></strong>’s <strong><em>constraintsWithVisualFormat</em></strong> function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0b8142642a98039da4f72fb0e603e92/href">https://medium.com/media/c0b8142642a98039da4f72fb0e603e92/href</a></iframe><h4>Step 4. The UITableView DataSource and Delegate</h4><p>The number of sections is <strong><em>sections.count</em></strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b8afc800436ccb76b029551e31bba86/href">https://medium.com/media/2b8afc800436ccb76b029551e31bba86/href</a></iframe><p>and the number of rows in each section is:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22e585dd79338f6d11201ce80d1da3f3/href">https://medium.com/media/22e585dd79338f6d11201ce80d1da3f3/href</a></iframe><p>Noticed that we don’t need to render any cell for the collapsed section, this can improve the performance a lot if there are lots of cells in that section.</p><p>Next, we use tableView’s viewForHeaderInSection function to hook up our custom header:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a19392fe565edd38cf94b7a7e66beff/href">https://medium.com/media/9a19392fe565edd38cf94b7a7e66beff/href</a></iframe><p>The normal row cell is pretty straightforward:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2ae06facc0b13fc94e8b5ac20e1753a/href">https://medium.com/media/e2ae06facc0b13fc94e8b5ac20e1753a/href</a></iframe><p>In the above code, we use the plain UITableViewCell, if you would like to see how to make a autosizing cell, please take a look at our CollapsibleTableViewCell in the source code. The CollapsibleTableViewCell is a subclass of UITableViewCell that adds the name and detail labels, and the most important thing is that it supports autosizing feature, the key is to setup the autolayout constraints properly, make sure the subviews are properly stretched to the top and bottom in the contentView.</p><h4>Step 5. How to Toggle Collapse and Expand</h4><p>The idea is really simple, if a section’s <strong><em>collapsed</em></strong> property is <strong><em>true</em></strong>, we set the height of the rows inside that section to be <strong><em>0</em></strong>, otherwise <strong><em>UITableViewAutomaticDimension</em></strong>!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/323d67dbc06ccb12b96797f23b43f503/href">https://medium.com/media/323d67dbc06ccb12b96797f23b43f503/href</a></iframe><p>And here is the toggle function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f70de0b826f87044a9052e67ad44419/href">https://medium.com/media/5f70de0b826f87044a9052e67ad44419/href</a></iframe><p>After the sections get reloaded, the number of cells in that section will be recalculated and redrawn.</p><p>That’s it, we have implemented the collapsible table section! Please refer to the source code and see the detailed implementation.</p><h3>License</h3><p>This project is licensed under the MIT license, Copyright © 2017 Yong Su.</p><p><em>Author: </em><a href="https://github.com/jeantimex"><em>Yong Su</em></a><em> @ Box Inc.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=142e0c6266fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>