<?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 Volodymyr Klymenko on Medium]]></title>
        <description><![CDATA[Stories by Volodymyr Klymenko on Medium]]></description>
        <link>https://medium.com/@volodymyrklymenko?source=rss-fa0742f554d7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5K_DJ0thgB0mjGVlJ2YvVA.jpeg</url>
            <title>Stories by Volodymyr Klymenko on Medium</title>
            <link>https://medium.com/@volodymyrklymenko?source=rss-fa0742f554d7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 10:14:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@volodymyrklymenko/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[Multilingual NLP with Microsoft Azure Services]]></title>
            <link>https://medium.com/nexxt-intelligence-engineering/multilingual-nlp-with-microsoft-azure-services-b2b0f5d219a3?source=rss-fa0742f554d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2b0f5d219a3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Volodymyr Klymenko]]></dc:creator>
            <pubDate>Tue, 23 Jun 2020 14:13:25 GMT</pubDate>
            <atom:updated>2020-06-23T14:13:25.052Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9fWuuphHfKjOLbua" /></figure><p>It’s quite possible that you might have multilingual input if you have users from different countries, and you collect some input from them in your application. If you do any natural language processing (NLP) in your app, it can be a challenge. Obviously, if you trained your NLP models with data in English, and you try to feed it with some French text, it will fail to analyze it and produce correct results. What should you do it in this case? We will show you a simple solution <strong><em>without any NLP engineering</em></strong>!</p><p>We at Nexxt Intelligence mainly use Microsoft Azure services for our infrastructure, and we had an opportunity to work and play with some really fascinating services that Microsoft offers. In this article, we will cover a few language APIs that Azure Cognitive Services has. <a href="https://azure.microsoft.com/en-us/services/cognitive-services/#customer-stories">Cognitive Services</a> also include APIs for :</p><ul><li>Decision making</li><li>Speech<strong> </strong>processing</li><li>Computer Vision</li><li>Web search</li></ul><p>In this post, we’ll create a web application that would be able to accept input in different languages and do some sentiment analysis on this data. We‘re going to use React on the client side and Express on the back end.</p><p>Firstly, let’s discuss how this idea can be brought into life. As I promised you, we’ll avoid Machine Learning programming, and we will fully rely on Azure Services instead. This solution consists of two main parts:</p><ol><li>Normalize data, i.e. translate it into one language. Obviously, it’s going to be English in our case.</li><li>Do sentiment analysis.</li></ol><p>Both these tasks can be done by <a href="https://azure.microsoft.com/en-us/services/cognitive-services/text-analytics/">Text Analytics API</a> and <a href="https://azure.microsoft.com/en-us/services/cognitive-services/translator/">Translator API</a> from Azure Cognitive Services 🚀</p><h4>Prerequisites</h4><ul><li>Microsoft Azure account</li><li>Create resources for <a href="https://azure.microsoft.com/en-us/services/cognitive-services/text-analytics/">Text Analytics API</a> (v3.0) and <a href="https://azure.microsoft.com/en-us/services/cognitive-services/translator/">Translator API</a> (v3.0) on Azure Portal</li><li>Node.js</li></ul><h3>Let’s build it!</h3><p>Now that we have an idea of how we can implement this, let’s set up our project. I’ll split this project into two folders: client and server. I initialized a React app using <a href="https://create-react-app.dev/">create-react-app</a> in the client directory and an express app in the server directory. Also, here is the list of dependencies I’m going to use for this app:</p><h4>server</h4><ul><li>express</li><li>axios</li><li>cors</li><li>dotenv</li><li>nodemon</li></ul><h4>client</h4><ul><li>axios</li><li><a href="https://github.com/pinterest/gestalt">gestalt</a> (a cute React UI component library)</li></ul><p>You can install these dependencies by running npm install DEPENDENCY_NAME or yarn add DEPENDENCY_NAME in the corresponding folder (client or server).</p><p>How about preparing our back-end first, and then we can build UI for it?</p><p>We can start with a simple Express app template that you probably saw many times:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f61af7c7ac7e9bf009269e8563e44f24/href">https://medium.com/media/f61af7c7ac7e9bf009269e8563e44f24/href</a></iframe><p>You’ll also need a .env file with the following content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3a773ed4532de83a8aaa86fa988f394/href">https://medium.com/media/e3a773ed4532de83a8aaa86fa988f394/href</a></iframe><p>You should replace YOUR_URL_GOES_HERE and YOUR_KEY_GOES_HERE with the URLs and API keys you got from Azure Portal when you created resource for Text Analytics and Translator APIs.</p><p>We’ll need just two endpoints for this app: /translate and /sentiment. As you might guess, translate route would translate text into English, and sentiment endpoint would return sentiment analysis for input data.</p><p>Let’s create translate endpoint:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62556e81fe5dbe42bc47b41b198b3059/href">https://medium.com/media/62556e81fe5dbe42bc47b41b198b3059/href</a></iframe><p>The piece of code above takes text property from request body that we would send from the front-end, splits it into an array by \n delimiter, and creates an array of objects with text property, which is a format Tranlsator API expects.</p><p>You might wonder why would we split a string into the array by \n? We do it in order to ensure that Translator API returns correct translations. Currently, this API is not capable of picking up several languages on the same string object. Even though it’s very unlikely that you would have multilingual text on the same line, we still want to have a little rule for the input data of our application:<br>if a sentence starts with a different language comparing to the previous sentence, it must be on a new line, so it can be easily identified and translated into English.</p><p>Finally, we simply make a POST request to the Translator API with this data, and all required headers and send data back to user.</p><p>sentiment endpoint is next.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/208ff6714aa64d49c8f115476bc83e90/href">https://medium.com/media/208ff6714aa64d49c8f115476bc83e90/href</a></iframe><p>It’s pretty similar to /translate, actually. The main difference is that we have a normalizeData function here that takes request body and formats it to satisfy the Text Analytics API requirements.</p><p>That’s it! Now, we can build client-side of our application.</p><p>As I mentioned earlier, we will build UI using <a href="https://gestalt.netlify.app/#/">Gestalt</a>, a library developed by Pinterest engineers, which has a lot of beautiful components.</p><p>We can start with some UI for collecting input from user and send it to our back end when a button is clicked:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e2bb233d368041f7fed39d81dd2d644c/href">https://medium.com/media/e2bb233d368041f7fed39d81dd2d644c/href</a></iframe><p>Let’s walk through this code. There are four states:</p><ul><li>text which holds the value of the TextArea input field.</li><li>overallScore which is the overall sentiment analysis score for the whole text document.</li><li>sentences which contains all translated sentences as well as their sentiment scores.</li><li>isLoading which indicates the loading state.</li></ul><p>There is also a getSentiment function that call that sends data from the text to the back end when the button is clicked. By the way, I’m running back-end locally, so my baseUrl is http://localhost:8080.</p><p>Next, we want to visualize the results that we get from the back end server. Before I do that, I’ll make a few UI components.</p><h4>ScoreBar</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1712d21091bfaa0cfe7cb198c9f934e/href">https://medium.com/media/a1712d21091bfaa0cfe7cb198c9f934e/href</a></iframe><p>It accepts a score object as a prop, and it will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KXRuvghqVJqgQsUitR7ygg.png" /></figure><h4>SentenceCard</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/34e730f90ace0c861ad0c5f1c9f7b558/href">https://medium.com/media/34e730f90ace0c861ad0c5f1c9f7b558/href</a></iframe><p>It accepts an emoji and a sentence as props. Sentence object will contain text and its sentiment scores. As you can see, we also use ScoreBar that we created in the prev. step. Here is how a SentenceCard will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*0iaWmnd48WAu2nkA8XR-WA.png" /></figure><h4>AnalysisContainer</h4><p>Finally, let’s integrate all our components into one component and visualize sentiment analysis of user’s text.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65559bcbb0478f5fd4297ccd0c8a1eb7/href">https://medium.com/media/65559bcbb0478f5fd4297ccd0c8a1eb7/href</a></iframe><p>This components basically displays overall sentiment score using ScoreBar, all sentences from user’s input using SentenceCards, and there is also a SegmentControl component, which looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wd8voJojPr9to6wBiJ83cg.png" /></figure><p>and allows users to filter sentences.</p><p>After this is done, simply import AnalysisContainer in the App component, and put in in the end of &lt;Box display=”flex” wrap minWidth={275} justifyContent=”evenly”&gt;, passing down local state properties as props:</p><pre>&lt;AnalysisContainer<br>    isLoading={isLoading}<br>    overallScore={overallScore}<br>    sentences={sentences}<br>/&gt;</pre><h3>Demo</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T7fnd_yY44DIzWQRdeudOg.gif" /></figure><h3>Final thoughts</h3><p>In this post, I showed you how to build a simple NLP application that can do sentiment analysis <em>only</em> using cognitive services available on Azure. Definitely, this solution isn’t perfect and may not work well with complex input data. Even when I tested with some simple data, I was not always satisfied with the results as it could show a high positive sentiment score on quite obvious neutral statement. This is one of the reasons why we do a lot of in-house NLP Research &amp; Development at Nexxt Intelligence.</p><p>On the other hand, developing this application didn’t even involve any line of NLP-related code! It would be fair to mention that Azure Text Analytics has “ <a href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/how-tos/text-analytics-how-to-entity-linking?tabs=version-3">named entity recognition</a>” feature which lets you identify different entities and categorize them, but it’s far beyond the scope of this post. Also, note that <a href="https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/language-support?tabs=sentiment-analysis#language-list-and-status">it currently supports only 19 languages, and Text Analytics API v3.x is not available in Central India, UAE North, China North 2 and China East</a>.</p><p>Source code is available on GitHub:</p><p><a href="https://github.com/nexxt-intelligence/multilingual-nlp">nexxt-intelligence/multilingual-nlp</a></p><p>Hope you enjoyed this reading! Feel free to share and give this post a few claps so others can enjoy it too 👏</p><p>If you have any questions, drop a comment below 👇</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2b0f5d219a3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nexxt-intelligence-engineering/multilingual-nlp-with-microsoft-azure-services-b2b0f5d219a3">Multilingual NLP with Microsoft Azure Services</a> was originally published in <a href="https://medium.com/nexxt-intelligence-engineering">Nexxt Intelligence Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A list of awesome Swift projects to contribute to on Hacktoberfest 2019]]></title>
            <link>https://medium.com/@volodymyrklymenko/a-list-of-awesome-swift-projects-to-contribute-to-on-hacktoberfest-2019-9151cf7a7880?source=rss-fa0742f554d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/9151cf7a7880</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[hacktoberfest]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Volodymyr Klymenko]]></dc:creator>
            <pubDate>Tue, 01 Oct 2019 05:21:27 GMT</pubDate>
            <atom:updated>2019-10-01T05:21:27.033Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*59c9itNGvqhGSXkTn7RjfA.png" /></figure><p>It’s October 1st, and it means that the biggest event of the open source community called <a href="https://hacktoberfest.digitalocean.com/"><strong>Hacktoberfest</strong></a> starts today 🎃🌍🖥</p><p>For those of you who haven’t heard about Hacktoberfest challenge, here is a short description from <a href="https://hacktoberfest.digitalocean.com/faq">the official website</a>:</p><blockquote>Hacktoberfest is a month-long celebration of open source software run by DigitalOcean and DEV. Hacktoberfest is open to everyone in our global community. To participate, four pull requests must be submitted to public GitHub repositories. You can sign up anytime between October 1 and October 31.</blockquote><p>The first 50,000 developers, who complete the challenge, will receive an awesome Hacktoberfest t-shirt 🔥</p><p>Last year, I had completed this challenge as part of my open source course at Seneca College, and it was so much fun that I decided to take part in this challenge again this year. In this post, I would like to compile a list of open source iOS/macOS projects you can contribute to. There are not as many Swift open source projects as JavaScript OS projects, for example, so I hope this article will help you to find one.</p><p>I would like to start with the ones that I worked on previously and had a positive experience.</p><h3>iOS</h3><h3>Browsers</h3><h4>Brave 🦁</h4><p>The very first browser I contributed to was Brave for iOS. It’s a privacy focused browser available on all major platforms including iOS and macOS. I made a small contribution last year, and the maintainers were very kind and supportive. Also I had classmates who fixed some bugs in this app, and they said good things about this project too. I definitely recommend to check out this project:</p><p>🖥 <a href="https://github.com/brave/brave-ios">GitHub Repo</a></p><h4>Firefox 🔥🦊</h4><p>Last year, I had an opportunity to fix some bugs and implement some features in <a href="https://github.com/mozilla-mobile/focus-ios">Firefox Focus for iOS</a>, which is another privacy browser but from Mozilla. It was another fun project to work on for me, and similar to Brave, the maintainers were willing to help me if I had any questions or struggles. Unfortunately, Mozilla paused the development of this project, but they still have their main iOS browser — Firefox. I haven’t had any experience working with this particular project yet, but I plan on doing it this month (I’ve already made a small patch and opened a pull request there). However, I worked on bunch of other Mozilla’s projects (Firefox, Firefox add-ons, Focus), and I find their community very welcoming to their contributors, which is essential in open source projects.</p><p>If you’re interested in contributing to Firefox for iOS, visit:</p><p>🖥 <a href="https://github.com/mozilla-mobile/firefox-ios">GitHub Repo</a></p><h3>Messengers</h3><h4>Signal</h4><p>A private, open source messenger. Its codebase consists of both Objective-C and Swift. There are 361 issues opened, check it out and try to find one for yourself:</p><p>🖥 <a href="https://github.com/signalapp/Signal-iOS/issues">GitHub Repo</a></p><h4>Telegram</h4><p>Telegram is a popular cloud-based messaging service, and it’s also open source. The project includes not only Swift, but also Objective-C, Objective-C++, C, C++, and it has 360 contributors. If you’re new to open source development, I wouldn’t recommend this project as a start point.</p><p>🖥 <a href="https://github.com/TelegramMessenger/Telegram-iOS">GitHub Repo</a></p><h3>macOS</h3><h4>IINA 🎬</h4><p>It’s an open-source media player for macOS written in Swift. It seems like this project is being developed actively (688 issues and 23 PRs are opened at the moment).</p><p>🖥 <a href="https://github.com/iina/iina">GitHub Repo</a></p><h4>Lona 💻</h4><p>It’s a tool for defining design systems and using them to generate cross-platform UI code, Sketch files, and other artifacts. I had made about 5 contributions to this project earlier this year, and I found it quite interesting. Also, if you don’t have much background in macOS dev, you can find some really good first issues since the maintainers do a great job in writing issue descriptions and help their contributors. It doesn’t seem that they’ve been developing this project actively in these latter days, so I suggest you to reach out to Devin, who is maintaining this project, on Twitter (<a href="https://twitter.com/dvnabbott">@dvnabbott</a>) and tell him that you want to work on this project (that’s how I got involved in this project 😀).</p><p>🖥 <a href="https://github.com/airbnb/Lona">GitHub Repo</a></p><h3>Swift libraries and frameworks</h3><h4>Alamofire</h4><p>An HTTP networking library written in Swift.</p><p>🖥 <a href="https://github.com/Alamofire/Alamofire">GitHub Repo</a></p><h4>Eureka</h4><p>An elegant iOS form builder in Swift.</p><p>🖥 <a href="https://github.com/xmartlabs/Eureka">GitHub Repo</a></p><h4>Kitura</h4><p>A server-side Swift framework developed and maintained by IBM.</p><p>🖥 <a href="https://github.com/IBM-Swift/Kitura">GitHub Repo</a></p><h4>Lottie</h4><p>A library for rendering vector based animations developed and maintained by Airbnb.</p><p>🖥 <a href="https://github.com/airbnb/lottie-ios">GitHub Repo</a></p><h4>SwifterSwift</h4><p>This project contains a large collection of all kinds of Swift extensions. It doesn’t have many issues opened, but you’re free to create your own extension that you think can be helpful for other Swift developers, and submit a Pull Request!</p><p>🖥 <a href="https://github.com/SwifterSwift/SwifterSwift">GitHub Repo</a></p><h4>Vapor</h4><p>A server-side Swift framework.</p><p>🖥 <a href="https://github.com/vapor/vapor">GitHub Repo</a></p><h3>Bonus</h3><h4>Swift</h4><p>I wrote about all types of different projects above, but if you feel really confident, you should go and checkout a <a href="https://bugs.swift.org/secure/Dashboard.jspa">bug tracker</a> of the Swift programming language!</p><p>🍏 <a href="https://github.com/apple/swift">GitHub Repo</a></p><p><strong><em>Happy Hacktoberfest</em></strong> 🎉</p><p>If you have any projects to suggest, feel free to drop a comment 👇</p><p>You can also reach out to me on Twitter: <a href="https://twitter.com/klymenko_v">@klymenko_v</a> 🙌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9151cf7a7880" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to set up Core Bluetooth for a macOS app]]></title>
            <link>https://medium.com/@volodymyrklymenko/how-to-set-up-core-bluetooth-for-a-macos-app-1758b27c36f6?source=rss-fa0742f554d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/1758b27c36f6</guid>
            <category><![CDATA[objective-c]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[corebluetooth]]></category>
            <dc:creator><![CDATA[Volodymyr Klymenko]]></dc:creator>
            <pubDate>Thu, 05 Sep 2019 03:29:18 GMT</pubDate>
            <atom:updated>2019-09-05T03:29:18.578Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OO0cgblUBPO5BGxy" /></figure><p>If you create a Cocoa macOS app in Xcode, import Core Bluetooth and try to use this framework, you’ll run into an error:</p><pre><strong>[CoreBluetooth] XPC connection invalid</strong></pre><p>Here is a quick guide on how to set up your macOS project to work with Core Bluetooth:</p><ol><li>Go to Project Settings -&gt; Capabilities -&gt; App Sandbox</li><li>Check in Bluetooth option under “Hardware” heading</li><li>Then, go to Info.plist</li><li>Add “Privacy — Bluetooth Peripheral Usage Description” property, and add a description of how your app is going to use Bluetooth.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1758b27c36f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Server-side Swift: how to use Vapor 3 with MongoDB]]></title>
            <link>https://medium.com/@volodymyrklymenko/server-side-swift-how-to-use-vapor-3-with-mongodb-baf9b79c8d0?source=rss-fa0742f554d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/baf9b79c8d0</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[mongodb]]></category>
            <dc:creator><![CDATA[Volodymyr Klymenko]]></dc:creator>
            <pubDate>Thu, 18 Jul 2019 19:15:45 GMT</pubDate>
            <atom:updated>2020-02-09T21:15:01.695Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6mqcLIpfsWR6m-fgV6MC7w.png" /></figure><p>I’m working on a side project, which is an iOS app, and it is going to communicate with a database. I had to select a technology for my back-end, and I chose an interesting and rare at the same time tech stack for the back-end.</p><p>I decided to give a try to server-side Swift, and I selected <a href="https://vapor.codes/">Vapor</a> as a Swift back-end framework. Then, I needed a NoSQL database, and I chose <a href="https://www.mongodb.com/">MongoDB</a>.</p><p>I couldn’t find much information on the web on how to combine these technologies, so I decided to figure out it by myself and share some of my learnings and knowledge on this topic.</p><h4>Prerequisites</h4><ul><li><a href="https://docs.mongodb.com/manual/installation/">Install MongoDB</a></li><li>Host your MongoDB on a hosting service of your choice or run it locally on your machine</li><li>Basic experience with <a href="https://vapor.codes/">Vapor 3</a></li><li>Install Vapor 3 (<a href="https://docs.vapor.codes/3.0/install/macos/">macOS</a>/<a href="https://docs.vapor.codes/3.0/install/ubuntu/">Ubuntu</a>)</li><li><a href="https://docs.vapor.codes/3.0/getting-started/toolbox/">Create a Vapor application</a></li></ul><h3>MongoSwift installation</h3><p>In order to work with MongoDB in Swift applications, you need a MongoDB driver for Swift. There was a couple of driver options:</p><ul><li><a href="https://github.com/mongodb/mongo-swift-driver">MongoSwift</a></li><li><a href="https://github.com/OpenKitten/MongoKitten">MongoKitten</a></li></ul><p>I decided to go with MongoSwift because it’s an official MongoDB driver for Swift developed by mongodb.</p><p>Let’s install MongoSwift in our application.</p><p>First, run the following command to install mongo c driver:</p><pre>brew install mongo-c-driver</pre><p>Then, add MongoSwift to the Package.swift. Your package should look like (the highlighted line is the one you need to add):</p><pre>import PackageDescription</pre><pre>let package = Package(<br>    name: &quot;AppName&quot;,<br>    products: [<br>        .library(name: &quot;AppName&quot;, targets: [&quot;App&quot;]),<br>    ],<br>    dependencies: [<br>        .package(url: &quot;https://github.com/vapor/vapor.git&quot;, from: &quot;3.0.0&quot;),<br>        <strong><em>.package(url: &quot;https://github.com/mongodb/mongo-swift-driver.git&quot;, from: &quot;0.1.3&quot;)</em></strong><br>    ],<br>    targets: [<br>        .target(name: &quot;App&quot;, dependencies: [&quot;Vapor&quot;, &quot;MongoSwift&quot;]),<br>        .target(name: &quot;Run&quot;, dependencies: [&quot;App&quot;]),<br>        .testTarget(name: &quot;AppTests&quot;, dependencies: [&quot;App&quot;])<br>    ]<br>)</pre><p>Run:</p><pre>swift build</pre><p>That’s it! If there are no errors, you are set up to build some cool stuff with MongoDB and Vapor 😀👏</p><h3>How to work with MongoDB in a Vapor app</h3><p>Let’s build a small server that would perform CRUD operations in our MongoDB. I’m going to write 4 endpoints for:</p><ol><li>creating a user and adding it to the database</li><li>reading a users collection from the database and returning a list of usernames</li><li>updating the user by id</li><li>deleting the user by id</li></ol><p>Where user is a simple data structure that contains id (integer), username (string), and password(string).</p><p>We can start with creating a data model for our server. Create a User.swift file inside the Models folder of the App and put the following structure there:</p><pre><strong>import</strong> Vapor</pre><pre><strong>struct</strong> User: Content {<br>  <strong>var</strong> id: Int<br>  <strong>var</strong> username: String?<br>  <strong>vr</strong> password: String?<br>}</pre><h4>Configuration</h4><p>Now, let’s configure our app. Go to configure.swift and add the following code inside configure function:</p><pre><strong>let</strong> client = <strong>try</strong> MongoClient(&quot;mongodb://localhost:27017&quot;)<br><strong>let</strong> db = client.db(&quot;vaporapp&quot;)<br><strong>do</strong> {<br>  <strong>_</strong> = <strong>try</strong> db.createCollection(&quot;users&quot;)<br>} <strong>catch</strong> {<br>  <strong>_</strong> = db.collection(&quot;users&quot;)<br>}<br>services.register(client)</pre><p>The first line create a connection to MongoDB server. If you’re connecting to mongo’s default port on your localhost, you might omit passing the connection string parameter.</p><p>Next, I initialize an instance of vaporapp database. After that, I create a collection called users if it doesn’t exist. Lastly, we register our client, so we can access it later in the app.</p><p>Also, add the following line of code in the end of the file, so our MongoClient conforms to Vapor’s Service.</p><pre><strong>extension</strong> MongoClient: Service {}</pre><p>Configuration part of this tutorial is done ✅</p><h4>Endpoints implementation</h4><p>The first endpoint of our server is going to be a <strong>POST</strong> request that would accept a user JSON object and insert it to the database. Add a user route inside routes.swift with the following content:</p><pre>router.post(&quot;user&quot;) { req -&gt; Future&lt;HTTPStatus&gt; <strong>in<br>    return</strong> <strong>try</strong> req.content.decode(User.<strong>self</strong>).map(to: HTTPStatus.<strong>self</strong>) { user <strong>in</strong></pre><pre><strong>        let</strong> client = <strong>try</strong>! req.make(MongoClient.<strong>self</strong>)<br>        <strong>let</strong> collection = client.db(&quot;vaporapp&quot;).collection(&quot;users&quot;, withType: User.<strong>self</strong>)<br>        <strong>_</strong> = <strong>try</strong>! collection.insertOne(user)<br>        <strong>return</strong> .ok</pre><pre>    }<br>}</pre><p>Let me walk you through the code:</p><ol><li>In the first line, I register a post request for /user route, and I specify the return value of the closure (Future&lt;HTTPStatus&gt;). If you are not familiar with Futures, <a href="https://www.vaporforums.io/viewThread/45">read this article</a>.</li><li>It does exactly what it says: it decodes the content from the request and maps it to the closure’s return value. The user parameter in the end is the instance of the object being passed by the request.</li><li>client is, basically, the MongoClient we made in the configure.swift.</li><li>collection access the users collection from vaporapp database, and associates it with User type.</li><li>This is where insertion to the database happens. user instance is passed as an argument.</li><li>Return .ok HTTPStatus.</li></ol><p>It’s time to test this endpoint!</p><p>First of all, make sure that the Vapor app is running:</p><ol><li>vapor build</li><li>vapor run</li></ol><p>A default port is 8080.</p><p>I use <a href="https://www.getpostman.com/">Postman</a> to test my APIs during development. Here is my request to the newly created endpoint:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P6W72RyVNmqHD7Z5UKct8A.png" /></figure><p>I sent a POST request with the request body (that you can see on the screenshot above). You can see the successful response with status 200 in the bottom right corner.</p><p>Now, let’s implement an endpoint for retrieving a list of usernames from our database. Let’s code a <strong>GET</strong> method /users route:</p><pre>router.get(&quot;users&quot;) { req -&gt; [String] <strong>in<br>    let</strong> client = <strong>try</strong>! req.make(MongoClient.<strong>self</strong>)<br>    <strong>let</strong> collection = client.db(&quot;vaporapp&quot;).collection(&quot;users&quot;, withType: User.<strong>self</strong>)<br>    <strong>let</strong> cursor = <strong>try</strong>! collection.find()<br>    <strong>var</strong> usernames = [String]()<br>    <strong>for</strong> document <strong>in</strong> cursor {<br>        <strong>if</strong> <strong>let</strong> username = document.username {<br>            usernames.append(username)<br>        }<br>    }<br>    <strong>return</strong> usernames<br>}</pre><p>First few lines are pretty similar to what we’ve done in the first POST method (note that I use router.get instead of router.post). Next, I use a find() method of the collection instance, which returns a mongo cursor that is being used for working with documents in the database. Note, you can pass a filter query as a parameter of find() if you need to search for a specific document.</p><p>Then, I iterate documents in the cursor, and push a username property of each document into my usernames string array. Finally, I return the usernames, and let’s take a look at the output from my <strong>GET</strong> request:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rh2apXone_XKrxhHm9xjng.png" /></figure><p>The request returned volodymyr user, which has been added earlier.</p><p>The next endpoint would be a PUT request that updates a specific user (username, password) by using id of the user. Let’s get straight to the coding:</p><pre>router.put(&quot;user&quot;) { req -&gt; Future&lt;HTTPStatus&gt; <strong>in<br>    return</strong> <strong>try</strong> req.content.decode(User.<strong>self</strong>).map(to: HTTPStatus.<strong>self</strong>) { user <strong>in<br>        let</strong> client = <strong>try</strong>! req.make(MongoClient.<strong>self</strong>)<br>        <strong>let</strong> collection = client.db(&quot;vaporapp&quot;).collection(&quot;users&quot;, withType: User.<strong>self</strong>)<br>        <strong>let</strong> query: Document = [&quot;id&quot;: user.id]<br>        <strong>let</strong> updatedUser: Document = [&quot;$set&quot;: [&quot;username&quot;: user.username!, &quot;password&quot;: user.password!] <strong>as</strong> Document]<br>        <strong>_</strong> = <strong>try</strong>! collection.updateOne(filter: query, update: updatedUser)<br>        <strong>return</strong> .ok<br>    }<br>}</pre><p>The first part of the code is the same to what we’ve seen earlier (note that I use router.put). It decodes the body of the request and creates the client and collection variables.</p><p>Then, I create a query of MongoSwift’s <a href="https://mongodb.github.io/mongo-swift-driver/Structs/Document.html">Document</a> type, which is, basically, a struct that represents the BSON document type. As you can see, the query I made will look for a user.id that we’re getting from the request body. Also, I made an updatedUser variable of the Document type, which I’m going to use in my update method call. It specifies new username and password in its definition.</p><p>After that, I simply call collection.updateOne with the filter: query and update: updatedUser arguments. This line of code will look for a user with specified id, and update the username and password of that user.</p><p>Let’s test it! I’m going to send a <strong>PUT</strong> request with the following request body:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zDKU_tdsVWaBmwuNhekO8A.png" /></figure><p>Here, I’m using an id of the user I’ve created earlier, but I’m using a new username and a new password. I got a successful response from the server (see right bottom corner) after sending this request.</p><p>Now, the updated username should be volodymyr10 now instead of just volodymyr, and the user should have a new password: newPassword. Let’s send a <strong>GET</strong> request to http://localhost:8080/users in order to confirm that user’s info was updated:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ln-oDlAIg93-xrq5ZsIQbw.png" /></figure><p>It returned an updated username.</p><p>Finally, let’s take a look at how to implement a user deletion endpoint:</p><pre>router.delete(&quot;user&quot;, Int.parameter) { req -&gt; HTTPStatus <strong>in<br>    let</strong> userId = <strong>try</strong> req.parameters.next(Int.<strong>self</strong>)<br>    <strong>let</strong> client = <strong>try</strong>! req.make(MongoClient.<strong>self</strong>)<br>    <strong>let</strong> collection = client.db(&quot;vaporapp&quot;).collection(&quot;users&quot;, withType: User.<strong>self</strong>)<br>    <strong>let</strong> query: Document = [&quot;id&quot;: userId]<br>    <strong>_</strong> = <strong>try</strong>! collection.deleteOne(query)<br>    <strong>return</strong> .ok<br>}</pre><p>This code is almost the same as our router.put function but a little bit simpler. Here, I read user&#39;s id from the request’s parameter and assign it to userId variable. Then, I create the client, collection, and query variables in exactly the same way as I did in the previous endpoint.</p><p>Lastly, I call collection.deleteOne with the query I’ve made. It will look for a document that has that user id and delete it from the database.</p><p>Time to test it! First, I want to add some more users to the database. I’ve sent a couple of POST requests with the new users, and here is a new list of users:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6uvpKL34vdfE9dj9BiBnEQ.png" /></figure><p>Now, let’s try to delete volodymyr10 user. I’m sending a DELETE request to <a href="http://localhost:8080/user/1:">http://localhost:8080/user/1:</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*keCICO_Ta9xgdYIzR76UQg.png" /></figure><p>I got a successful response with status 200 (see the bottom right corner). Let’s see the list of users now:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AExfBa4FadzsinLIsQw2cA.png" /></figure><p>User volodymyr10 is gone!</p><p>Enjoyed this post? Feel free to give this post a few claps so others can enjoy it too 👏👏👏</p><p>If you have any questions, feel free to ask them in the comments section, or you can reach out to me on Twitter: <a href="https://twitter.com/klymenko_v">@klymenko_v</a> 🙌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=baf9b79c8d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a React component library: React Cupertino]]></title>
            <link>https://medium.com/@volodymyrklymenko/creating-a-react-component-library-react-cupertino-65b8753d6d0b?source=rss-fa0742f554d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/65b8753d6d0b</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Volodymyr Klymenko]]></dc:creator>
            <pubDate>Mon, 29 Apr 2019 01:08:45 GMT</pubDate>
            <atom:updated>2019-04-29T01:08:45.008Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*amEzm00U2zU-1-RvpEHKmQ.png" /></figure><p>When I had one of my internships, I developed with React a lot. One time, I needed a complicated component for a project, and I looked for a ready-to-use component in favor of time. I came across <a href="https://blog.bitsrc.io/11-react-component-libraries-you-should-know-178eb1dd6aa4">an article on Medium</a> about top React component libraries.</p><blockquote><strong>React component library</strong> is a set of reusable components that save developer’s time for implementing components from scratch.</blockquote><p>When I looked at the libraries presented in that list, I found that most of them look so similar between each other, and it’s difficult to select one at first sight. Most of the libraries there implement Google Material Design, and if you take a look at them, you’ll see that the components look pretty similar to each other:</p><ul><li><a href="https://material-ui.com/">Material-UI: A popular React UI framework</a></li><li><a href="http://react-toolbox.io/#/">React Toolbox</a></li><li><a href="https://onsen.io/react/">React UI Components by Onsen UI Hybrid Mobile App Framework</a></li></ul><p>Eventually, I selected Material-UI because it had the most stars on GitHub, a big community, so it looked reliable to me. It was a good choice because I had a good experience using it 👍</p><p>That article made me think about creating a library by myself that would look different from the libraries presented there. Plus, I wanted to make my contribution to React and its community because I work with it, and I like this library a lot.</p><p>Design ideation process was next. As I am a big fan of Apple and, especially, their design philosophy, an idea came to my mind to create UI components that would look like Apple’s design.</p><p>Then, I came up with a name for the project quickly. I combined React and the name of the city, where Apple’s headquarters are based in, called Cupertino. That’s how I’d got React Cupertino 😄</p><p>Also, I told my friend Abhi, who was another intern in my team and worked with React, about this project idea and offered him to join me. He agreed, and we started the development.</p><h3>Development ⚒</h3><p>We didn’t know how to develop a component library from scratch, and what tools should we use, so the first step was to do a research. I read several articles and tutorials, however, none of them worked 100% for different reasons at that time. So we decided to start developing components and think about bootstrapping and deployment things later.</p><p>I haven’t heard about <a href="https://storybook.js.org/">Storybook</a> at that time, so I simply made an app using <a href="https://facebook.github.io/create-react-app/">create-react-app</a>, and we developed the majority of the components there.</p><p>Coding components wasn’t that difficult for me. The real two challenges were <strong>the components’ design</strong> and <strong>the library’s set up</strong>. Let’s talk about each of these challenges in details.</p><h3>Design</h3><p>Neither of us is a designer, and we had to design the components ourselves. It was difficult but fun at the same time. I didn’t even use any of graphics editors. I either used Keynote to prototype components, or I coded components designing them off the top of my head.</p><h4>Inspiration</h4><p>I would like to mention some design works that influenced me when I designed my components:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.behance.net%2Fgallery%2F62549811%2FmacOS-11-Concept-by-Alvaro-Pabesio%3Fiframe%3D1&amp;url=https%3A%2F%2Fwww.behance.net%2Fgallery%2F62549811%2FmacOS-11-Concept-by-Alvaro-Pabesio&amp;image=https%3A%2F%2Fmir-s3-cdn-cf.behance.net%2Fprojects%2F404%2Ffd33c262549811.Y3JvcCwxMDI1LDgwMiwzNyww.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=behance" width="700" height="900" frameborder="0" scrolling="no"><a href="https://medium.com/media/38cb8d3da4fa55088adf5034e5f5938e/href">https://medium.com/media/38cb8d3da4fa55088adf5034e5f5938e/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.behance.net%2Fgallery%2F57309065%2FApple-OS-MacOS-2020-redesign-Edge-to-edge-Macbook%3Fiframe%3D1&amp;url=https%3A%2F%2Fwww.behance.net%2Fgallery%2F57309065%2FApple-OS-MacOS-2020-redesign-Edge-to-edge-Macbook&amp;image=https%3A%2F%2Fmir-s3-cdn-cf.behance.net%2Fprojects%2F404%2Ff315a457309065.Y3JvcCwzMDc1LDI0MDcsNjgsMA.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=behance" width="700" height="900" frameborder="0" scrolling="no"><a href="https://medium.com/media/5eb1fc4e8edcf6522c1af9b55417ec99/href">https://medium.com/media/5eb1fc4e8edcf6522c1af9b55417ec99/href</a></iframe><h3>Set up</h3><p>When I started working on the set up of this project, I hoped that there is something like create-react-app but for creating React libraries. I found several tools: <a href="https://github.com/transitive-bullshit/create-react-library#readme">create-react-library</a> and <a href="https://github.com/insin/nwb">nwb</a>. I tried to use them, but none of them worked for me because my CSS files weren’t exported properly there. My component file structure looked like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/172/1*POhp5UoXJYBnu3Ue7mc-jg.jpeg" /><figcaption>File Structure of a component in the library</figcaption></figure><p>It was clear to me that I had to use <a href="https://webpack.js.org/">webpack</a> to bundle my components into a module because this tool would let me configure my project as I want it to work. The only problem was that I hadn’t had any experience with webpack before. I had to learn how to use it and how to configure the project properly.</p><p>I watched some tutorials, read some articles about webpack, and I was able to write a config file, which would work almost fine. As you can see from the image above, I keep my CSS styles in a separate file, and for some reason, they weren’t included in the bundle. I tried to find a solution to this problem, but nothing worked.</p><p>One of the videos I watched was about developing React component libraries by <a href="https://twitter.com/DavidWells">David Wells</a>. I decided to reach out to him on Twitter, and he responded to me! He shared a gist file with a webpack configuration for a similar project, and I could figure out how to fix my problem. <br>Web dev community is amazing 🤩👏 Big thanks to David 🙌</p><p>My final version of the webpack config file looked like this:</p><pre>const fs = require(&#39;fs&#39;);<br>const ExtractTextPlugin = require(&#39;extract-text-webpack-plugin&#39;);<br>const path = require(&#39;path&#39;);<br>const webpack = require(&#39;webpack&#39;);<br>const packageInfo = require(&#39;./package.json&#39;);</pre><pre>const outputPath = path.join(__dirname, &#39;lib&#39;);</pre><pre>const srcPath = path.join(__dirname, &#39;src&#39;);<br>const componentsPath = path.join(srcPath, &#39;components&#39;);<br>const keepCSSFileReference = true;<br>const componentExternals = [];</pre><pre>const entryPoints = {<br>    index: &#39;./src/components/index.js&#39;<br>};</pre><pre><em>// Assign entry points and externals</em></pre><pre>fs.readdirSync(componentsPath)<br>  .filter(<em>x</em> =&gt; x !== &#39;.DS_Store&#39; &amp;&amp; x !== &#39;index.js&#39; &amp;&amp; !x.match(/\.md/))<br>  .forEach(<em>component</em> =&gt; {<br>    entryPoints[component] = [`./src/components/${component}`];<br>    componentExternals.push(`../${component}`);<br>});</pre><pre>const externals = []<br>  .concat(Object.keys(packageInfo.dependencies))<br>  .concat(componentExternals);</pre><pre>module.exports = {</pre><pre>    entry: entryPoints,<br>    output: {<br>        path: outputPath,<br>        filename: &#39;[name]/index.js&#39;,<br>        publicPath: &#39;/dist/&#39;,<br>        library: packageInfo.name,<br>        libraryTarget: &#39;commonjs2&#39;<br>    },<br>    resolve: {<br>        modules: [&#39;node_modules&#39;, path.resolve(__dirname, &#39;lib/index&#39;)],<br>         extensions: [&#39;.js&#39;, &#39;.jsx&#39;]<br>    },<br>    externals,<br>    plugins: [<br>        new webpack.optimize.OccurrenceOrderPlugin(true),<br>        new ExtractTextPlugin(<br>        &#39;[name]/[name].css?[hash]-[chunkhash]-[contenthash]-[name]&#39;,  </pre><pre>        {<br>            disable: false,<br>            allChunks: true,<br>            keepCSSFileReference<br>        }<br>        ),<br>        new webpack.DefinePlugin({<br>            &#39;process.env&#39;: {<br>                NODE_ENV: &#39;&quot;production&quot;&#39;<br>            }<br>        })<br>    ],</pre><pre>module: {<br>     rules: [<br>     {<br>        test: /\.js$/,<br>        loader: &#39;babel-loader&#39;,<br>        options: {<br>            presets: [&#39;@babel/preset-env&#39;, &#39;@babel/react&#39;]<br>        },<br>        include: srcPath<br>      },<br>      {<br>        test: /\.css$/,<br>        use: [&#39;style-loader&#39;, &#39;css-loader&#39;]<br>      },<br>      {<br>        test: /\.svg$/,<br>        loader: &#39;url-loader?limit=10000&amp;mimetype=image/svg+xml&#39;<br>      }<br>      ]<br>    }<br>};</pre><p>Also, I used <a href="https://babeljs.io/">Babel</a> to transpile my JS code, <a href="https://prettier.io/">Prettier</a> and <a href="https://eslint.org/">ESLint</a> to produce a better code. Later, I came across <a href="https://storybook.js.org/">Storybook</a>, which is a nice tool that helps to develop components in isolation, and I integrated it into the project. I also used Travis CI as my Continuous integration service.</p><h3>Components</h3><p>Here is what React Cupertino components look like as of today:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*53ZBsUrIH_0aggiqx3sS_A.png" /></figure><h3>React Cupertino Documentation</h3><p>You can learn more about each component and how to install React Cupertino to your project on the documentation website:</p><p><a href="https://react-cupertino.github.io/">React Cupertino</a></p><h3><strong>React Cupertino Source Code</strong></h3><p>Did you find a bug? Do you want to contribute? Here is a link to the GitHub repository:</p><p><a href="https://github.com/react-cupertino/react-cupertino">react-cupertino/react-cupertino</a></p><p>If you have any questions, feel free to ask them in the comments, or you can reach out to me on Twitter: @klymenko_v 🙌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65b8753d6d0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding Hide/Show functionality of  the bottom panel to Lona]]></title>
            <link>https://medium.com/@volodymyrklymenko/adding-hide-show-functionality-of-the-bottom-panel-to-lona-25ba40deeedd?source=rss-fa0742f554d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/25ba40deeedd</guid>
            <category><![CDATA[open-source-software]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Volodymyr Klymenko]]></dc:creator>
            <pubDate>Fri, 12 Apr 2019 22:37:02 GMT</pubDate>
            <atom:updated>2019-04-12T22:37:02.747Z</atom:updated>
            <content:encoded><![CDATA[<h3>Adding Hide/Show functionality of the bottom panel to Lona</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KAh36K8up3hcvpdxpPMBGw.png" /></figure><p>It’s Friday, and it’s time for another story about my Open Source journey. I continue working on Lona, and I’ve fixed another bug earlier this week. Let’s take a look at the issue:</p><h3>Bug 🐞</h3><p>The interface of Lona is really similar to Xcode’s interface, and it has three panels. One on the right, one on the left, and one in the bottom. The bottom panel contains some utilities such as parameters, logic, examples and details of the component, and for some reasons, the hide/show button in the navbar didn’t do anything. My goal was to implement this functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*vc0YhVNLfFAa-1aDgsoVxg.png" /></figure><h3>Fix 🔧</h3><p>In order to fix this bug, I did the following steps:</p><ol><li>In the ComponentEditorViewController, which contains the bottom panel, I wrote a new function that, basically, hides and shows the bottom panel depending on the value passed in the argument:</li></ol><pre>private func setBottomItemVisibility(to visible: Bool) {<br>        if (visible &amp;&amp; bottomItem.isCollapsed) || (!visible &amp;&amp; !bottomItem.isCollapsed) {</pre><pre>            bottomItem.animator().isCollapsed = !visible</pre><pre>        }<br>}</pre><p>2. I created a public variable utilitiesViewVisible, which I’m going to use later in the WorkspaceViewController. This variable has a getter that returns the value of bottomItem.isCollapsed, and a setter which uses the function from the first step to update the value of bottomItem.isCollapsed:</p><pre>public var utilitiesViewVisible: Bool {<br>    get { return bottomItem.isCollapsed }<br>    set { setBottomItemVisibility(to: newValue) }<br>}</pre><p>The reason why I made this variable is that bottomItem is private, and I cannot access it from the WorkspaceViewController.</p><p>3. Then, I used a newly created variable in the WorkspaceViewController:</p><pre><em>// this variable contains an array of all panels in the app.<br>// I added a conditional statement inside filter function that<br>// checks whether the current item is bottom one.<br>// If it is true, it returns value of </em><strong><em>utilitiesViewVisible</em></strong><br>public var activePanes: [WorkspacePane] {<br>  get {<br>   return WorkspacePane.all.filter {<br>      <strong><em>if $0 == .bottom {<br>        return !(componentEditorViewController.utilitiesViewVisible)<br>      }</em></strong> else {<br>        ...<br>      }<br>    }<br>  }<br>  ...<br>}</pre><p>Also, I added another conditional statement to the setVisibility function which is called when the hide/show button is clicked:</p><pre>private func setVisibility(to visible: Bool, for pane: WorkspacePane, animate: Bool) {<br>    <strong>if pane == .bottom {<br>        componentEditorViewController.utilitiesViewVisible = visible<br>    } </strong>else {<br>        guard let item = splitViewItem(for: pane) else { return }<br>        if (visible &amp;&amp; item.isCollapsed) || (!visible &amp;&amp; !item.isCollapsed) {<br>            if animate {<br>                item.animator().isCollapsed = !visible<br>            } else {<br>                item.isCollapsed = !visible<br>            }<br>        }<br>    }<br>}</pre><h3>Result</h3><p>As you can see in the GIF below, the bottom panel works properly when the hide/show button is clicked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*0OO73o18HrynQDJT95w6Bg.gif" /></figure><p>Here is a link to the pull request:</p><p><a href="https://github.com/airbnb/Lona/pull/374">Hide/show bottom panel by klymenkoo · Pull Request #374 · airbnb/Lona</a></p><p>Enjoyed this post? Feel free to give this post a few claps so others can enjoy it 👏👏👏</p><p>Check out my previous story about Lona:</p><p><a href="https://medium.com/@volodymyrklymenko/adding-component-duplication-to-lona-bba7ca59dcda">Adding Component Duplication to Lona</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25ba40deeedd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From writing unit tests to working on the software from Mozilla, Microsoft and Airbnb]]></title>
            <link>https://medium.com/@volodymyrklymenko/from-writing-unit-tests-to-working-on-the-software-from-mozilla-microsoft-and-airbnb-4ef5fbcaec48?source=rss-fa0742f554d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ef5fbcaec48</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Volodymyr Klymenko]]></dc:creator>
            <pubDate>Fri, 05 Apr 2019 20:54:30 GMT</pubDate>
            <atom:updated>2019-04-05T23:46:26.225Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LPC-YQMWUtfpLaH7YklwCQ.png" /></figure><p>Last September, I registered for OSD600 as part of my studies at my school (Seneca College, Toronto), and my journey to the world of Open Source Software began. OSD stands for Open Source Development.</p><blockquote>This course introduces students to the technological, social, and pragmatic aspects of developing open source software through direct involvement in large open source projects. Students will learn to use the tools, techniques, and strategies of open source developers. This is a project-based programming course. (from the <a href="https://wiki.cdot.senecacollege.ca/wiki/OSD600">Course website</a>)</blockquote><p>This course had an interesting philosophy and outline that are not really typical to other courses: there were no midterms, final exams or any other tests. Instead, students had to contribute to open source projects, along with learning git essentials, and document it by writing blogs. In my opinion, that’s a great idea as students can build their personal brand by blogging. Also, unlike other courses, students are encouraged to collaborate and work together!</p><p>I made my first Pull Request (PR) to the project called filer, which is a POSIX-like file system interface for node.js and browser-based JavaScript, at the end of September, and I wrote my first blog post related to this course:</p><p><a href="https://medium.com/@volodymyrklymenko/my-first-contributions-to-open-source-world-6af2e77e0eb7">My first contributions to Open-source World</a></p><p>I add some tests to the filer in that PR. I feel like it was so long ago, but it actually was less than 7 months ago! I’ve grown as an OSS developer so much since that moment, and I’m excited to share my story in this summary blog post 🥳</p><h3>Hacktoberfest 🎃</h3><p>Shortly after submitting a pull request to <em>filer</em>, <a href="https://hacktoberfest.digitalocean.com/">Hacktoberfest</a> started, and I had to submit find <em>five </em>issues and submit<em> five </em>pull requests in 4 weeks 😦 It was quite intimidating for several reasons:</p><ol><li>I had to find issues in real projects.</li><li>I had to find solutions to those issues in such a short period of time.</li></ol><p>It was so different from the classes where you have assignments, list of tasks you need to complete, and you can imagine how your end result might look like.</p><p>Fortunately, students can work on any projects they pick. As I’d just started learning Swift last fall, I decided that it was a great opportunity to enhance my skills and learn new things about iOS development + I also had a Plan B, which was to work on JavaScript projects, in case I wouldn’t find a good issue in Swift projects or I would struggle at something.</p><p>I ended up participating in the following projects:</p><ul><li>Ethereum Wallet app (Swift) — added Alamofire library (Swift networking library) and replaced all networking calls with Alamofire API.</li><li>Algorithms project (Swift) — added graph algorithms.</li><li>Brave iOS (Swift) — fixed some warnings.</li><li>Adaptive learning (Java) — refactored code by removing a project module.</li><li>Mozilla add-ons (React, CSS) — fixed styling issue for a component.</li></ul><p>You can find a more detailed summary I wrote on the last day of Hacktoberfest here:</p><p><a href="https://medium.com/@volodymyrklymenko/hacktoberfest-2018-summary-3d48843cb39e">Hacktoberfest 2018 Summary</a></p><h3>Mozilla 🔥🦊</h3><p>After completing Hacktoberfest challenge, I felt much more confident. It was such a boost when my contributions to iOS apps were accepted and merged! I had never built any iOS app at that moment, and my changes were merged into pretty big projects!</p><p>In the following two months after Hacktoberfest, I had to deliver 3 contributions that were supposed to be larger. I succeeded in making PRs to iOS apps, so I wanted to continue working on iOS projects. I started exploring available open source options. I was looking at Mozilla’s projects because I had already participated in one of their projects (Add-ons), and I really liked the community there. I found a project called Firefox Focus.</p><blockquote>Firefox Focus for iOS devices is a privacy browser with tracking protection and content blocking. (Retrieved from <a href="https://support.mozilla.org/en-US/kb/focus">Mozilla</a>)</blockquote><p>I had more time to complete these pull requests comparing to Hacktoberfest, so I picked a couple of larger issues there. There was a couple of bugs in the URL bar of the browser, so I started hacking on them. By the way, these issues were actually bugs comparing to the previous one I worked on. Before, I just refactored code, added some new features, or fixed a small styling issue. Here, I had to fix a real bug in such a big app. These contributions involved more effort, debugging and research time. I started discovering Focus codebase and try to write my own code there. It was more difficult, but hard work pays off!</p><p>My patches were accepted and merged into the master branch of Firefox Focus! Later, an update popped up on App Store for Firefox Focus, and that update included my bug fixes! It was an amazing feeling contributing to such a big app, which is used by many people.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FW9G8OK82R3dfO%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Frocky-balboa-W9G8OK82R3dfO&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FW9G8OK82R3dfO%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/11f9ba9312a31e373796157c2fc3af51/href">https://medium.com/media/11f9ba9312a31e373796157c2fc3af51/href</a></iframe><p>Again, check out my blog posts, which contain more technical details, about my participation in Firefox Focus dev:</p><ul><li><a href="https://medium.com/@volodymyrklymenko/bug-fix-in-firefox-focus-for-ios-ebf66d76b7fd">Bug fix in Firefox Focus for iOS</a></li><li><a href="https://medium.com/@volodymyrklymenko/bug-fix-2-in-firefox-focus-for-ios-e6c8e07a36af">Bug fix #2 in Firefox Focus for iOS</a></li></ul><p>Thereafter, I had to select my next issue to work on. I thought about proceeding with Focus, but there weren’t any new issues opened at that moment. Our professor brought up a list of issues in the Firefox related to ESLint coverage of its codebase. I thought that I can get an interesting experience working on Firefox because it’s probably one of the most popular and the most used software in the world!</p><p>Firefox was released in 2002. As you can imagine, it is a complicated piece of software with a tremendous amount of code. In 2013, a popular JavaScript linting utility called ESLint was created. Many JavaScript projects started integrating it, and Mozilla was not an exception. However, it was extremely hard to cover all JavaScript code of Firefox, so there are many files that are ignored by ESLint.</p><p>My task was to enable ESLint int one of the files in the DOM section of Firefox. The whole process working on this issue differed from my previous experiences. First, I had to use Bugzilla instead of GitHub for communicating with maintainers and discussing the issue. Then, the installation of Firefox code locally was different from just making a fork on GitHub and cloning the repo. I needed to install some additional tools for compiling the code. Also, it was a good opportunity to work with Mercurial in order to clone a repo and submit my patch later, and I found it very similar to GitHub.</p><p>Eventually, I submitted my changes, and they were also accepted! I literally had left my mark on Firefox code. It was another big accomplishment in my OSD600 class, and that was a great way to conclude my course.</p><h3>OSD700</h3><p>In the winter semester, I had an option to take OSD700 course, which is a second OSD course and includes more advanced contributions. I really enjoyed OSD600, so I registered for OSD700.</p><p>I chose Firefox Focus for my first PR because I’d already known it, and I felt like it was a good project to start with. I noticed that the development of Focus was not as active as it used to be in Fall, so I had to pick up issues that were filed some time ago. I sent two PRs to Focus during this term:</p><ol><li>I went through the codebase and refactored it by moving magic numbers into a separate file. It was a good exercise which helped me to learn more about the codebase as I intended to do more development on this project in the future.</li><li>I added UI tests. I’ve never done testing in iOS apps before, so I learned something new doing this contribution.</li></ol><h3>Microsoft VSCode</h3><p>As I mentioned above, the development of this project was not so active, so I decided to look for a new project I can contribute to. I felt confident enough, so I went to large organizations like Microsoft, Facebook, Google, etc.</p><p>I stopped at VSCode. I had looked at this project last Fall, but after I saw 4k issues, all my desire was gone. It seemed to me that it was so hard to find a good issue to work on. However, one of my classmates contributed to VSCode, and he shared his strategy on how to find a good issue. The strategy is simple: look at the issues that were filed a long time ago (1 month and longer). I used it, and I found an interesting issue related to an extensions search bar.</p><p>The process of installing VSCode locally, fixing the bug, debugging it, submitting PR, and finally, merging it into master branch took almost a month! However, it was a tremendous experience I’d gained during fixing that bug. Also, I was happy about this contribution because millions of developers including me use VSCode almost every day!</p><p>If you would like to learn all the technical details, you can read my blog posts:</p><ul><li><a href="https://medium.com/@volodymyrklymenko/working-on-a-bug-in-microsoft-vscode-part-1-eb810e867372">Working on a bug in Microsoft VSCode (Part 1)</a></li><li><a href="https://medium.com/@volodymyrklymenko/working-on-a-bug-in-microsoft-vscode-part-2-c7557082b857">Working on a bug in Microsoft VSCode (Part 2)</a></li></ul><h3>Lona</h3><p>Even though I had a good time working on VSCode, I wanted to switch back to Swift development, and I started searching for a new project. Again, I looked at major organizations, and I came across a project called Lona in Airbnb GitHub organization. Lona is a design tool, which lets users create and design components, and then generate code for different platforms like React and Swift. I liked the idea of this project a lot.</p><p>I found that there were not many issues filed there, but I saw that there a lot of commits pushed every day, so I reached out to Devin (@dvnabbott), who is the maintainer of this project on Twitter:</p><h3>Volodymyr Klymenko on Twitter</h3><p>Hey, @dvnabbott, I&#39;m considering contributing to https://t.co/SA7tfC0NWU Could you suggest any good bug to fix or feature to implement for a first-time contributor?</p><p>Devin was very kind and helpful, and he filed some issues in the repository. I fixed a couple of bugs, and I liked the process of working on Lona so much that I decided to work on it till the end of the semester, and maybe even more in the future! Also, I would like to mark the way that issues are filed there: they have amazing descriptions which help new contributors to start working on it quickly. I have sent four patches to Lona so far, and you can find out more about them in the following posts:</p><ul><li><a href="https://medium.com/@volodymyrklymenko/contribution-to-lona-how-to-set-up-ruby-environment-on-macos-d8c7fb35433e">Contribution to Lona + How to set up Ruby environment on macOS</a></li><li><a href="https://medium.com/@volodymyrklymenko/adding-svg-support-to-lonas-file-preview-d22ade3d9b97">Adding SVG support to Lona’s file preview</a></li><li><a href="https://medium.com/@volodymyrklymenko/moving-forward-with-lona-c80538a99dce">Moving forward with Lona</a></li><li><a href="https://medium.com/@volodymyrklymenko/adding-component-duplication-to-lona-bba7ca59dcda">Adding Component Duplication to Lona</a></li></ul><h3>Ukrainian translation of React documentation</h3><p>The following part was not really a part of my OSD course, however, I believe that OSD classes influenced me a lot, so I would like to share this story.</p><p>I was scrolling my Twitter feed, and I came across this tweet:</p><h3>Dan Abramov on Twitter</h3><p>We&#39;re setting up official translations of the React docs (for real this time!) @tesseralis wrote up our plan in an issue. If you have experience maintaining localized docs or already manage a fork of React docs, please comment! We&#39;d love to work with you. https://t.co/2ZQiwbCHnJ</p><p>I develop a lot using React, and I love this library a lot. I wanted to contribute to the React community, and it was a great opportunity to do it, so I applied for it. Shortly after it, the repository for Ukrainian translation was created, and I was assigned to maintain it 🤠</p><p>It’s been a new and interesting experience for me because this time, I was not only a contributor but also a maintainer, who is responsible for helping others to start, reviewing their work, and even resolving conflicts. For example, we had two people submitting a translation for the same document, and I solved this issue by taking half of the translation from the first PR and the second half from the other PR.</p><p>As of today, we have the following percentage of translated documentation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*cErBDN1x5wP7yuS5svIOCg.png" /></figure><p>I believe that the core documentation will be finished soon. Just 3 documents left. The documentation website is already available online, so if you speak Ukrainian, check it out 😀</p><p><a href="https://uk.reactjs.org/">React - JavaScript-бібліотека для створення користувацьких інтерфейсів</a></p><h3>Summary</h3><p>Wow! It’s been less than 7 months, and the progress I’ve made is tremendous. I started with writing simple tests in <em>filer</em>, and I ended up with contributing to projects from large companies like Mozilla, Microsoft, Facebook and Airbnb! I learned so much during working on these projects! I met new people around the world just by working together with them on the same thing. Open Source world is amazing, you can learn, get help, meet new people and make your mark in the codebases of the world’s most used software, and it’s all for free! You don’t even need to be in a specific location; you can just work from wherever you’re located. Also, I would like to thank my professor, <a href="https://twitter.com/humphd">David Humphrey</a>, who taught me about open source and helped me along my journey. I’m glad that I took these courses; it definitely helped me to grow as a developer, and I will try to keep contributing to Open Source Software in the future.</p><p>If you have any questions, feel free to ask them in the comment section, or you can reach out to me on Twitter: @klymenko_v 🙌</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ef5fbcaec48" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding Component Duplication to Lona]]></title>
            <link>https://medium.com/@volodymyrklymenko/adding-component-duplication-to-lona-bba7ca59dcda?source=rss-fa0742f554d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/bba7ca59dcda</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[macos-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Volodymyr Klymenko]]></dc:creator>
            <pubDate>Fri, 29 Mar 2019 03:26:35 GMT</pubDate>
            <atom:updated>2019-04-02T17:17:32.135Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H9CvgMRIwTMlf-URoQau-g.png" /></figure><p>As you might know, I’ve decided to proceed with making more contributions to <a href="https://github.com/airbnb/Lona">Lona</a>, and earlier this week I had an opportunity to add a new feature to this app. Here is an overview of my contribution:</p><h3>Feature request ⚙️</h3><p>Users often create new components based on the existing ones, and the only way to do it was to go to Finder and copy &amp; paste a component file. So, there was a feature request to add component duplication support to the File Navigator.</p><p>First, let’s take a look at the context menu of the file in File Navigator:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*cP0yCFGHZi2lNhsBxiHk5A.png" /></figure><p>My task was to add a new option called “Duplicate As…” to the context menu, and once the option was selected, it should display the Save dialog. After the user typed a file name, selected location for it and pressed “Save”, the program should open a newly created component in the Component Editor.</p><p>Link to the issue:</p><p><a href="https://github.com/airbnb/Lona/issues/355">[Lona Studio] Add easy component duplication · Issue #355 · airbnb/Lona</a></p><h3>Implementation ⚒</h3><p>There is a function menuForFile, which creates a context menu, in the FileNavigator class, and that’s the place, where I needed to place my new code:</p><pre><strong>// <em>Check if selected file has a &quot;.component&quot; extension</em><br>if</strong> NSURL(fileURLWithPath: path).pathExtension == &quot;component&quot; {<br>    menu.addItem(NSMenuItem(title: &quot;Duplicate As...&quot;, onClick: {<br>        <strong>var</strong> saveURL: String<br>        // <strong><em>Show Save Dialog</em></strong><br>        <strong>let</strong> dialog = NSSavePanel()<br>        dialog.title = &quot;Save .component file&quot;<br>        dialog.showsResizeIndicator = <strong>true<br>        </strong>dialog.showsHiddenFiles = <strong>false<br>        </strong>dialog.canCreateDirectories = <strong>true<br>        </strong>dialog.allowedFileTypes = [&quot;component&quot;]<br>        dialog.directoryURL = URL(fileURLWithPath: path).deletingLastPathComponent()</pre><pre><em>        </em><strong><em>// User canceled the save. Don&#39;t swap out the document.</em></strong><em><br>        </em><strong>if</strong> dialog.runModal() != NSApplication.ModalResponse.OK {<br>            <strong>return<br>        </strong>}</pre><pre><strong>        guard</strong> <strong>let</strong> url = dialog.url <strong>else</strong> { <strong>return</strong> }<br>        saveURL = url.path</pre><pre><strong>// Try to copy file. If successful, open the file in the Component Editor. Otherwise, display an alert with an appropriate message.<br>        do</strong> {<br>             <strong>try</strong> FileManager.default.copyItem(atPath: path, toPath: saveURL)<br>        } <strong>catch</strong> {<br>             <strong>let</strong> alert = NSAlert()<br>             alert.messageText = &quot;Couldn&#39;t copy component to \(saveURL)&quot;<br>             alert.addButton(withTitle: &quot;OK&quot;)<br>             alert.runModal()<br>             return<br>        }<br>        <strong>self</strong>.onAction?(saveURL)<br>    }))<br>}</pre><h3>Result</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*zIH00X2WpNQriG3SEqUHeA.gif" /><figcaption>Component Duplication demo</figcaption></figure><p>Link to PR:</p><p><a href="https://github.com/airbnb/Lona/pull/359">Fixes #355: Add component duplication support by klymenkoo · Pull Request #359 · airbnb/Lona</a></p><p>Enjoyed this post? Feel free to give this post a few claps so others can enjoy it 👏👏👏</p><p>Check out my previous posts related to Lona:</p><ul><li><a href="https://medium.com/@volodymyrklymenko/contribution-to-lona-how-to-set-up-ruby-environment-on-macos-d8c7fb35433e">Contribution to Lona + How to set up Ruby environment on macOS</a></li><li><a href="https://medium.com/@volodymyrklymenko/adding-svg-support-to-lonas-file-preview-d22ade3d9b97">Adding SVG support to Lona’s file preview</a></li><li><a href="https://medium.com/@volodymyrklymenko/moving-forward-with-lona-c80538a99dce">Moving forward with Lona</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bba7ca59dcda" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Moving forward with Lona]]></title>
            <link>https://medium.com/@volodymyrklymenko/moving-forward-with-lona-c80538a99dce?source=rss-fa0742f554d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/c80538a99dce</guid>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[macos-development]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Volodymyr Klymenko]]></dc:creator>
            <pubDate>Thu, 28 Mar 2019 01:45:43 GMT</pubDate>
            <atom:updated>2019-03-28T01:45:43.722Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AP_tW0GDtNx9wXwr7ruR5Q.png" /></figure><p>I continue exploring and working on Lona as well as learning Swift and macOS development along the way. Let me walk you through the bug I was fixing earlier this week.</p><h3>Bug 🐛</h3><p>First of all, let me remind you how UI looks like in Lona:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*62917itY82_vrxKdO9jmpQ.png" /></figure><p>As you can see on the screenshot above, we have File Navigator on the left, Component Editor in the middle (please note that “Add” menu on top; it’s part of the issue), and Property Inspector on the right.</p><p>The app had the following issue:<br>When a user added, deleted or moved component files to a different location, the “Add” menu, which includes some UI elements and list of components in the current workspace that can be added to the selected component, wouldn’t update the list of components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/290/1*ae1hB86mCKnwddxqtob8zQ.png" /><figcaption>“Add” menu in the Component Editor</figcaption></figure><p>In order to update the list of components, the user had to restart the app, which, obviously, was quite annoying.</p><p>Link to the issue description:</p><p><a href="https://github.com/airbnb/Lona/issues/338">[Lona Studio] Update the &quot;add&quot; menu when new components are created · Issue #338 · airbnb/Lona</a></p><h3>Fix 🔧</h3><p>There is a file called LonaPlugins, which contains an enumeration LonaPluginActivationEvent that consists of some event types:</p><pre><strong>enum</strong> LonaPluginActivationEvent: String, Decodable {</pre><pre><strong>    case</strong> onSaveComponent = &quot;onSave:component&quot;</pre><pre><strong>    case</strong> onSaveColors = &quot;onSave:colors&quot;</pre><pre><strong>    case</strong> onSaveTextStyles = &quot;onSave:textStyles&quot;</pre><pre><strong>    case</strong> onReloadWorkspace = &quot;onReload:workspace&quot;</pre><pre><strong>    case</strong> onChangeTheme = &quot;onChange:theme&quot;</pre><pre>}</pre><p>I added a new case to this <strong>enum</strong>:</p><pre><strong>case</strong> onChangeFileSystemComponents = &quot;onChange:fileSystem:components&quot;</pre><p>As you can guess, it will be triggered once a component was created, deleted or moved.</p><p>Next, I triggered this event type on each possible case (creation, deletion, or movement of the file) in the main View Controller WorkspaceViewController:</p><pre>fileNavigator.onCreateFile = { path, options in</pre><pre>    LonaPlugins.current.trigger(eventType: .onChangeFileSystemComponents)       </pre><pre>}</pre><pre>fileNavigator.onDeleteFile = { path, options <strong>in</strong></pre><pre>    LonaPlugins.current.trigger(eventType: .onChangeFileSystemComponents)</pre><pre>}</pre><pre>fileNavigator.performMoveFile = { prev, next <strong>in</strong></pre><pre>     LonaPlugins.current.trigger(eventType: .onChangeFileSystemComponents)</pre><pre>}</pre><p>In a nutshell, WorkspaceViewController has a variable fileNavigator that is an object of class FileNavigator, which handles all workspace’s files and has some closures that are executed on the events I’m interested in (onCreateFile, onDeleteFile, performMoveFile).</p><p>Finally, I had to subscribe to the onChangeFileSystemComponents event and add some behaviour that’s going to be performed when it’s triggered. I had to do it inside the component LayerListHeader, which is part of our “Add” menu.</p><pre><em>// subscriptions array of closures<br></em><strong>private</strong> <strong>var</strong> subscriptions: [() -&gt; Void] = []</pre><pre><strong>init</strong>() {<br>    <strong>super</strong>.init(frame: .zero)</pre><pre>    ...</pre><pre><em>    // subscribe to our event and update menu items when triggered<br></em>    subscriptions.append(LonaPlugins.current.register(eventType: .onChangeFileSystemComponents) { [<strong>unowned</strong> <strong>self</strong>] <strong>in<br>         self</strong>.updateMenuItems()<br>    })<br>}</pre><pre><strong>private</strong> <strong>func</strong> updateMenuItems() {<br>    button.menu(forSegment: 0)?.items = ComponentMenu.menuItems()<br>}</pre><pre><strong>deinit</strong> {<br>    subscriptions.forEach({ sub <strong>in</strong> sub() })<br>}</pre><p>In the first version of my Pull Request, my subscription closure looked like this:</p><pre>subscriptions.append(LonaPlugins.current.register(eventType: .onChangeFileSystemComponents) {<strong><br>         self</strong>.updateMenuItems()<br>    })</pre><p>(I didn’t have <strong>[unowned self] </strong>closure parameter), and a reviewer asked me to add it to ensure that it will be deallocated later. I’m still relatively new to Swift, and I’ve never seen and, of course, used <strong>unowned self</strong>, so it was a great opportunity to learn it. Here is one important thing about unowned I learned while reading docs, which applies to my use case above:</p><blockquote>Define a capture in a closure as an unowned reference when the closure and the instance it captures will always refer to each other, and will always be deallocated at the same time.</blockquote><blockquote>Conversely, define a capture as a weak reference when the captured reference may become nil at some point in the future. (<a href="https://docs.swift.org/swift-book/LanguageGuide/AutomaticReferenceCounting.html">Swift documentation</a>)</blockquote><h3>Results</h3><p>Here are some GIFs that shows the final result of my patch 🤠</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*YWoLean1lI3_FOUv1kmUVA.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*K1g6DXbclXHw2G4Vq3qnLg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*uhcSIuk3ZLshLStq1iMZOw.gif" /><figcaption>When the user adds (1), deletes (2), or moves (3) component file, the list of components within “Add” menu updates. (Click the GIF to enlarge it)</figcaption></figure><p>Link to my PR:</p><p><a href="https://github.com/airbnb/Lona/pull/348">Fixes #338: Update &quot;Add&quot; menu on component change in fileNavigator by klymenkoo · Pull Request #348 · airbnb/Lona</a></p><p>Enjoyed this post? Feel free to give this post a few claps so others can enjoy it 👏👏👏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c80538a99dce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding SVG support to Lona’s file preview]]></title>
            <link>https://medium.com/@volodymyrklymenko/adding-svg-support-to-lonas-file-preview-d22ade3d9b97?source=rss-fa0742f554d7------2</link>
            <guid isPermaLink="false">https://medium.com/p/d22ade3d9b97</guid>
            <category><![CDATA[macos-development]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[airbnb]]></category>
            <dc:creator><![CDATA[Volodymyr Klymenko]]></dc:creator>
            <pubDate>Fri, 15 Mar 2019 03:12:23 GMT</pubDate>
            <atom:updated>2019-03-15T03:12:23.131Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KVl-4Mmb7FpDmPZT1JGb4A.png" /></figure><p>Last week, I made my first contribution to Lona. If you haven’t read my previous post, you can find it here:</p><p><a href="https://medium.com/@volodymyrklymenko/contribution-to-lona-how-to-set-up-ruby-environment-on-macos-d8c7fb35433e">Contribution to Lona + How to set up Ruby environment on macOS</a></p><p>I really liked the experience of contributing to this project, and I decided to work on it until the end of the semester. Earlier this week, I had an opportunity to fix the following bug:</p><blockquote>Currently Lona Studio displays some image files, e.g. PNG files, when selected in the file navigator. However, it doesn’t display SVG files, which it really should, since it handles them elsewhere correctly. (from the <a href="https://github.com/airbnb/Lona/issues/339#issue-420138137">issue description</a>)</blockquote><p>Here is how the .png files are displayed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kjcD-vKGW5ZJJBe48ltQwQ.png" /></figure><p>The .svg files are not displayed at all:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tv0hFt_v1LEXCY8TcmAKeg.png" /></figure><h3>Fix</h3><p>First, I had to add SVG to the list of supported formats in Info.plist.</p><p>Then, I added the following lines to the implementation of the read function, which is called on file selection event:</p><pre>let data = try Data(contentsOf: url, options: NSData.ReadingOptions())</pre><pre>if url.pathExtension == &quot;svg&quot; {<br>    let size = CGSize(width: 450<em>,</em> height: 450)<br>    content = SVG.render(contentsOf: url<em>,</em> size: size<em>,</em> resizingMode: .scaleAspectFit)<br>} else {<br>    content = NSImage(data: data)<br>}</pre><p>Let’s walk through this chunk of code.</p><ol><li>It checks the extension of the selected file.</li><li>If the file has ansvg extension, it sets the content (which has type of NSImage) to the result of render function, which was implemented in the SVG enum.</li><li>If the file has any other image extensions, it just sets content variable to NSImage with data.</li></ol><p>And here is the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kD75r3G2O4_xBapS_PbI6Q.png" /></figure><p>As you can see, the SVG image is rendered when a user selects the image in the file navigator 👍</p><p>Enjoyed this post? Feel free to give this post a few claps so others can enjoy it 👏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d22ade3d9b97" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>