<?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 Trangianglong on Medium]]></title>
        <description><![CDATA[Stories by Trangianglong on Medium]]></description>
        <link>https://medium.com/@trangianglong4003?source=rss-70e08c5fc66e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*K3OS7EMhG7aREdYI</url>
            <title>Stories by Trangianglong on Medium</title>
            <link>https://medium.com/@trangianglong4003?source=rss-70e08c5fc66e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 19:16:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@trangianglong4003/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[Combine RxSwift with Swift Concurrency.]]></title>
            <link>https://medium.com/@trangianglong4003/combine-rxswift-with-swift-concurrency-c3fd15c969cf?source=rss-70e08c5fc66e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3fd15c969cf</guid>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[rxswift]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Trangianglong]]></dc:creator>
            <pubDate>Tue, 03 May 2022 09:32:37 GMT</pubDate>
            <atom:updated>2022-05-03T09:32:37.604Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ligaLcsywRpV2KDHYRlpMw.png" /></figure><p>RxSwift is a famous library that every developer, who starts engineering in mobile development, must know. It makes mobile applications more responsible and interactable by using the observer pattern, the iterator pattern, and functional programming style.</p><p>Swift Concurrency is the latest technology that Apple has introduced last year. It allows developers to have a syntax sugar for writing asynchronous code similar to javascript and dart. Meanwhile, those two are strong in couple with a build-in event loop system, Swift still lets developers choose the way how the code will be executed.</p><p>How to combine those two technologies? If you start with a new empty project, mostly you will choose to use one of them. But how about existing apps that are still in development? Does combining RxSwift with Swift Concurrency bring advantages? In this small article, I will share some experiences from my working at P2P Validator. I am responsible for developing a decentralised wallet application and improving the quality of existing code.</p><h3>Using RxSwift in concurrency code</h3><p>The P2P Wallet has been developing before introducing Swift Concurrency. The application actively uses RxSwift for writing asynchronous code. The below picture illustrates the splitting layer in our application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/121/1*gDDZQCaLQJA5QHLHWlwHwg.png" /><figcaption>P2P Wallet architectur.</figcaption></figure><p>Calling from service to SolanaSDK layer will return Single. In some hard cases we have to combine many callings by using zip, flatMap or withLatestFrom. As consequence it makes our code hard to read and maintain. The code example below demonstrates the case, many of you maybe recognize that boiled code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7683df06d154a55c1cd7762ad76cd6bc/href">https://medium.com/media/7683df06d154a55c1cd7762ad76cd6bc/href</a></iframe><p>Since version 6.5.0 of RxSwift we can await on Observable , Single , Maybe and Completable. You can read more about it <a href="https://github.com/ReactiveX/RxSwift/blob/main/Documentation/SwiftConcurrency.md">here</a>. In the first place that affects our service layer and helps to remove many wrappings of closures. Let’s rewrite the previous code with async syntax.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e478c8b7ef030768c48d39f119d10ec2/href">https://medium.com/media/e478c8b7ef030768c48d39f119d10ec2/href</a></iframe><p>Swift Concurrency also solves the problem of sharing variables in a chain. If we want to access to values from step 2 in step 4, we have to pass them through step 3 by using tuple (getTradablePoolsPairs(...), .just(a), .just(b)). By using Concurrency step 2 and step 4 are in the same scope, so we can easily get access to them.</p><h3>Using concurrency code in RxSwift</h3><p>In the previous section we can see how easy to use existing code with Swift Concurrency. But how to run code that has been written in async/await syntax in flatMap , getLatestFrom , … ? A lot of existing projects still use MVVM pattern, where ModelView exposes Driver to View. Rewriting some code in the service layer in async style also requires rework in ViewModel and View layers.</p><p>Unfortunately RxSwift at this moment doesn’t provide any built-in ways to do it. <a href="https://github.com/TrGiLong/RxConcurrency">RxConcurrency</a> package that was created by me can solve this problem. It provides the most used transformation operators that support direct writing async in closure and wrapping async function into Observable. The code below shows the basic usage of the package. If you are interesting how does it work, check the source code of <a href="https://github.com/TrGiLong/RxConcurrency">RxConcurrency</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a87f299e3a1b1719bafcfd5e0747665/href">https://medium.com/media/1a87f299e3a1b1719bafcfd5e0747665/href</a></iframe><p>The package is very fresh at this moment. If you find a bug or have a new idea, feel free to create PRs.</p><p>I am glad that Apple finally introduce Swift Concurrency. Flutter with their excellent approach to writing UI using the event loop concept shows a completely new way to develop a mobile app. Now I can enjoy writing mobile apps in Swift the same way as I do in Flutter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3fd15c969cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to import files in dart, but in a better way.]]></title>
            <link>https://medium.com/@trangianglong4003/how-to-import-files-in-dart-but-in-a-better-way-eaf47bc5dfbc?source=rss-70e08c5fc66e------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaf47bc5dfbc</guid>
            <category><![CDATA[tools]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[clean-architecture]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Trangianglong]]></dc:creator>
            <pubDate>Sun, 25 Jul 2021 18:19:06 GMT</pubDate>
            <atom:updated>2021-07-25T18:19:06.135Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AEs-bTcGqQ-pZ84QWXRw2Q.png" /></figure><p>You have started a small flutter project one day. You created a few widgets and some necessary cubits. Later on you started to assemble them into a new page screen. You imported each of them and finally your file looked like the picture bellow:</p><pre>import “package:bear_app/pages/home/widget/welcome_widget.dart”;<br>import “package:bear_app/pages/home/widget/login_widget.dart”;<br>import “package:bear_app/pages/home/widget/news_widget.dart”;<br>import “package:bear_app/pages/home/cubit/home_cubit.dart”;<br>import “package:bear_app/pages/post/widget/daily_post_widget.dart”;<br>import “package:bear_app/pages/post/widget/hot_post_widget.dart”</pre><p>Now you think you can create a single file and export all necessary all the components. The home.dart will export all files here, while the post.dart will export files that relate to the post components, and so on…</p><p>Now your page screen looks better:</p><pre>import “package:bear_app/pages/home/home.dart”;<br>import “package:bear_app/pages/post/post.dart”;</pre><p>But what should you do if your project has hundred of files? Are you sure you want to go through all of them? Using this small dart script will help you automate this work.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f73f2eec84aaf5201844f5eb13e1c9d/href">https://medium.com/media/8f73f2eec84aaf5201844f5eb13e1c9d/href</a></iframe><p>The first step is putting this script somewhere in your computer. I personally put it into the utils directory of my project. Don’t forget to also commit your code just to be safe. To call this script, follow the example below:</p><pre>dart ./utils/generate_exports.dart ./lib/modules -i &quot;state.dart&quot;</pre><p>All dart files in ./lib/modules will be exported. The -i flag help you to ignore all file names which contain state.dart . The state of cubit is normally located separately and is a part of the cubit file, so we only need to export the cubit file.</p><p>This small script saves me about 1 minute for each created file and definitely a lot of unnecessary stress :D</p><p>Extra tip: import_sorter is a wonderful package for you to have a more organised importing process. You can read more about this package <a href="https://pub.dev/packages/import_sorter">here</a>.</p><pre><em>// Flutter imports:<br></em>import &#39;package:flutter/material.dart&#39;;<br><br><em>// Package imports:<br></em>import &#39;package:bear_repository/dictionary_repository.dart&#39;;<br>import &#39;package:flutter_bloc/flutter_bloc.dart&#39;;<br><br><em>// Project imports:<br></em>import &#39;package:bigdict_3/components/components.dart&#39;;<br>import &#39;package:bigdict_3/utils/utils.dart&#39;;<br>import &#39;package:bigdict_3/modules/social/social.dart&#39;;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaf47bc5dfbc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>