<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hitesh Vijay</title>
    <description>The latest articles on DEV Community by Hitesh Vijay (@hiteshvijayhv).</description>
    <link>https://dev.to/hiteshvijayhv</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F408030%2F052fa487-6aa9-41c7-ad68-f544d9aa4649.jpg</url>
      <title>DEV Community: Hitesh Vijay</title>
      <link>https://dev.to/hiteshvijayhv</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hiteshvijayhv"/>
    <language>en</language>
    <item>
      <title>Async  / Await Explained</title>
      <dc:creator>Hitesh Vijay</dc:creator>
      <pubDate>Mon, 01 Nov 2021 05:29:43 +0000</pubDate>
      <link>https://dev.to/hiteshvijayhv/async-await-explained-2a1d</link>
      <guid>https://dev.to/hiteshvijayhv/async-await-explained-2a1d</guid>
      <description>&lt;p&gt;In JavaScript to make Asynchronous programming easier to implement and read, Special Async and Await keywords were introduced. &lt;/p&gt;

&lt;h3&gt;
  
  
  Lets see why these are used
&lt;/h3&gt;

&lt;p&gt;These functions can be used in multiple use cases where a function execution depends on the output of the previous function call and it needs to wait for it An&lt;br&gt;
easy example for this is an API call, where the data from the API call need to be fetched first before doing other operations on it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Async
&lt;/h2&gt;

&lt;p&gt;An Async function can be declared by adding the Async keyword in front of a function. This function returns a promise &lt;/p&gt;

&lt;p&gt;It can be declared like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const test = async () =&amp;gt; {
    console.log("Async function")
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Await
&lt;/h2&gt;

&lt;p&gt;An await function can be declared in the same way as an Async function by adding the Await keyword in front of the function declaration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const test = await () =&amp;gt; {
    console.log("Async function")
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Await keyword can only be declared inside an Async function.&lt;/p&gt;

&lt;p&gt;Await keyword makes the code execution stop from the line it is declared till the promise completes. While it does stop the execution of the code from the line it is declared. It does not stop the code execution outside the Async block.&lt;/p&gt;

&lt;p&gt;Now that we know how to write these functions individually lets see what we can achieve with these functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const testFunc = async () =&amp;gt; {
    const a = await "Hello World!"
    console.log(a;
}

console.log("Before testFunc() call")
testFunc()
console.log("After testFunc() call")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Output
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Before testFunc() call
After testFunc() call 
Hello World
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Top 5 Kotlin Resources 💻</title>
      <dc:creator>Hitesh Vijay</dc:creator>
      <pubDate>Wed, 01 Jul 2020 02:53:39 +0000</pubDate>
      <link>https://dev.to/hiteshvijayhv/top-5-kotlin-resources-597f</link>
      <guid>https://dev.to/hiteshvijayhv/top-5-kotlin-resources-597f</guid>
      <description>&lt;br&gt;
Kotlin is officially supported language for Android Development, But Kotlin is not just used for Android Development. It can be used for Sever Side programming, Cross-platform development too. So here I compile Top 5 Kotlin Resources, take a look 👇👇👇👇

&lt;h3&gt;Telusko YouTube Playlist&lt;/h3&gt;

&lt;p&gt;Telusko channel hosted by Navin Reddy is a really easy way to learn programming you might know him from his Java playlist. &lt;a href="https://www.youtube.com/playlist?list=PLsyeobzWxl7rooJFZhc3qPLwVROovGCfh"&gt;Kotlin playlist&lt;/a&gt; by Telusko is really good and you can learn from it very easily. But a prior knowledge of Java will help to learn faster. &lt;/p&gt;

&lt;h3&gt;Official Kotlin Documentation&lt;/h3&gt;

&lt;p&gt;The &lt;a href="https://kotlinlang.org/docs/reference/native-overview.html"&gt;Kotlin documentation&lt;/a&gt; is definitely the best way to learn if you want to learn quickly and in-depth concepts. No tutorial will teach advanced concepts like documentation. But if you are a beginner look for tutorials first it might be difficult to learn form documentations as a beginner&lt;/p&gt;

&lt;h3&gt;Codecademy Website&lt;/h3&gt;

&lt;p&gt;No doubt Codecademy is a really good place to learn coding without any prior experience in an interactive and easy way. They recently launched the &lt;a href="https://www.codecademy.com/catalog/language/kotlin"&gt;Kotlin Course&lt;/a&gt;. It does not include advanced concepts like OOP, Coroutines, but are a good platform to consider if you are an absolute beginner&lt;/p&gt;

&lt;h3&gt;Kotlin for Java Developers by IntelliJ&lt;/h3&gt;

&lt;p&gt;If you are already an experienced Java developer and been coding for over a year then I recommend this &lt;a href="https://www.coursera.org/learn/kotlin-for-java-developers"&gt;Kotlin for Java Developers&lt;/a&gt; Course. They also provide certification if you pass the graded assignments.&lt;/p&gt;

&lt;h3&gt;Head First Kotlin by O'Reilly&lt;/h3&gt;

&lt;p&gt;Head First books have reputation to teach concepts really easily. Head First books feel like they're talking to you and teaching the really easy way. The &lt;a href="https://www.oreilly.com/library/view/head-first-kotlin/9781491996683/"&gt;Head First Kotlin by O'Reilly&lt;/a&gt; Book is no exception to this. The book was launched on Feb, 2019. It wont be up-to-date with all the latest Kotlin updates but a good start to get into the Kotlin world.&lt;/p&gt;

&lt;p&gt;===========================&lt;br&gt;
If you know any other resources please share in the comments below👇👇👇👇.&lt;/p&gt;

&lt;p&gt;===========================&lt;br&gt;
Follow me on twitter for latest updates &lt;a href="https://www.twitter.com/hiteshvijayhv"&gt;Click Here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;===========================&lt;/p&gt;

&lt;p&gt;If you like the post please Heart it🤍🤍🤍🤍&lt;/p&gt;

</description>
      <category>kotlin</category>
      <category>android</category>
    </item>
    <item>
      <title>Android ViewModel Example</title>
      <dc:creator>Hitesh Vijay</dc:creator>
      <pubDate>Mon, 15 Jun 2020 05:36:00 +0000</pubDate>
      <link>https://dev.to/hiteshvijayhv/android-viewmodel-tutorial-49ll</link>
      <guid>https://dev.to/hiteshvijayhv/android-viewmodel-tutorial-49ll</guid>
      <description>&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
The ViewModel is part of Android JetPack and is used to effectively implement MVVM architecture pattern in android.

&lt;h3&gt;Why ViewModel?&lt;/h3&gt;

&lt;p&gt;MVVM architecture requires the activity to do minimum number of logical operations on the activity. That means we can do the logical operations needed for the View to be performed in ViewModel and then reference it in the Activities. Also ViewModel allows to observe &lt;a href="https://developer.android.com/topic/libraries/architecture/livedata"&gt;LiveData&lt;/a&gt; in apps&lt;/p&gt;

&lt;h3&gt;Benefits&lt;/h3&gt;

&lt;p&gt;When we rotate the android device the activity is restarted an all the data is reloaded again. We can prevent this from happening if we are loading all the data in views from ViewModel class. An activity doesn't survive a state change while a ViewModel does.&lt;/p&gt;

&lt;h3&gt;Why can't just use a simple Kotlin/Java class&lt;/h3&gt;

&lt;p&gt;Some people might think that why can we use a simple Kotlin/Java class that does't extend ViewModel class to save the current state. The simple reason is that it won't survive state change. You can try the below example with a Kotlin/Java class.&lt;/p&gt;

&lt;h3&gt;Implementation&lt;/h3&gt;

&lt;p&gt;ViewModel class&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MainViewModel : ViewModel() {
    var number: Int = 0
    fun changeMainText(){
        number += 1
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Reference the view model class in activity&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private lateinit var viewModel: MainViewModel = ViewModelProviders.of(this).get(MainViewModel::class.java)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Increment the number by calling&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;viewModel.changeMainText()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Get the value of the number&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;viewModel.number
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fFET3o1u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/46933160/84643169-16d11380-af1b-11ea-8b27-ea19a25f7611.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fFET3o1u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/46933160/84643169-16d11380-af1b-11ea-8b27-ea19a25f7611.jpg" width="100dp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Wj3a_85B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/46933160/84643188-1cc6f480-af1b-11ea-80c2-324827088c31.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Wj3a_85B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/46933160/84643188-1cc6f480-af1b-11ea-80c2-324827088c31.jpg" height="100dp" width="200dp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This way we can save the data at state change without using some database. If you have any questions feel free ask me. If you learned something from this post please heart it❤&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
    </item>
  </channel>
</rss>
