<?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 Pavol Fulop on Medium]]></title>
        <description><![CDATA[Stories by Pavol Fulop on Medium]]></description>
        <link>https://medium.com/@pavolfulop?source=rss-6b77d812db56------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CruUidoPjPRVWTu97Mrf-A.gif</url>
            <title>Stories by Pavol Fulop on Medium</title>
            <link>https://medium.com/@pavolfulop?source=rss-6b77d812db56------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 16:10:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pavolfulop/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[Takeaways from using AppSync]]></title>
            <link>https://medium.com/@pavolfulop/takeaways-from-using-appsync-5ceee30984c9?source=rss-6b77d812db56------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ceee30984c9</guid>
            <category><![CDATA[appsync]]></category>
            <category><![CDATA[serverless-framework]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Pavol Fulop]]></dc:creator>
            <pubDate>Sun, 24 Feb 2019 23:01:00 GMT</pubDate>
            <atom:updated>2019-02-24T23:01:00.949Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nrM0x66w4UCfs_clT8h9QQ.png" /><figcaption><strong>source: undraw.co</strong></figcaption></figure><p>Recently I’ve been developing a web app for my friends and decided to go with AppSync (well at first I went with my old stack but then switched to AppSync). There are a couple of things I learned along the way and it seems only logical to share those things with the world.</p><p>The app will be released soon and it consists of your typical queries to access data including paginated results and mutations to alter/create/delete records. Besides that, it includes some subscriptions that are vital to the overall business logic of the application. It also relies on dynamoDB triggers for when some data are deleted and more actions are required on the server side.</p><h3>Why appsync</h3><p>I was looking into changing my usual stack for a while and getting into the whole serverless world. The idea looked very promising considering the server provider at that time wasn’t allowing me to use Docker containers which complicated separation of environments. Furthermore, this app has huge potential to grow and scalability is in some ways already handled by AWS.</p><h4>What I used before</h4><p>Before jumping on serverless hype train I was using my default stack consisting of MySQL/PostgreSQL, react, a GraphQL server using apollo-server-express. All usually hosted in your standard VPS.</p><h3>The nice things</h3><p>The first thing I noticed (and immediately fell in love with) was the fact that I can write everything in the yaml file to define all that I need. Maybe this is a great opportunity to mention that I went with the serverless framework and not with amplify. I first wanted to try amplify-cli but it felt short when I wanted to introduce SSR on one specific route and also set the caching policy of this route. To my knowledge amplify-cli is not yet there when it comes to advanced configurations.</p><p>The serverless framework allowed me to specify everything in yaml files and deploy them with one command. Everything from AppSync gateway trough databases, functions, SSR entry point, CloudFront settings, lambda@edge functions, domains, and an SSL certificate. This is really practical and with some plugins easy to set up.</p><p>Another nice thing was the possibility to specify the direct mapping from query/mutation to the dynamoDB table. Lots of times I didn’t have to write the necessary code to do simple operations and instead, I just copied some VTL templates and altered them. Chaining of them is now possible so the operations can be somewhat more complex. When I had no other option but to write lambda functions, usually, I had all the environmental variables available to do write the logic of the operation quickly.</p><p>I also like that the AppSync client is basically an Apollo client so this was very familiar territory for me. Writing subscriptions became easier too, I just had to specify which mutation should trigger an update for the clients.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48afc745ae39dfec64e8c7906176e4f7/href">https://medium.com/media/48afc745ae39dfec64e8c7906176e4f7/href</a></iframe><p>The community around serverless is so huge that when I wanted a plugin to take care of a certificate for my domain, or one that can bundle my assets and upload them to the s3 bucket, I usually found them within a minute.</p><p><em>Plugins I used:</em></p><p><a href="https://github.com/arabold/serverless-export-env">serverless-export-env</a></p><p><a href="https://github.com/serverless-heaven/serverless-webpack">serverless-webpack</a></p><p><a href="https://github.com/silvermine/serverless-plugin-cloudfront-lambda-edge">serverless-plugin-cloudfront-lambda-edge</a></p><p><a href="https://github.com/gilmarsquinelato/serverless-spa">serverless-spa</a></p><p><a href="https://github.com/sid88in/serverless-appsync-plugin">serverless-appsync-plugin</a></p><p><a href="https://github.com/svdgraaf/serverless-pseudo-parameters">serverless-pseudo-parameters</a></p><p><a href="https://github.com/awslabs/aws-amplify-serverless-plugin">aws-amplify-serverless-plugin</a></p><p><a href="https://github.com/pfulop/serverless-cloudfront-distribution-certificate">serverless-cloudfront-distribution-certificate</a></p><p>The fact that AppSync takes away the need for me to understand and set up a whole lot of stuff around the server architecture makes my life easier and is a nice argument to why serverless is being so popular lately and why it will tempt more people to give it a try.</p><h3>Where it gets darker</h3><p>For instance, trying to notify your subscribers outside of AppSync world is deemed almost impossible. You need to search and find a way how to basically fire a mutation to which you previously mapped your subscription in schema. This code is not provided in any library but luckily there are snippets and articles floating around that will help you with this task.</p><p><a href="https://read.acloud.guru/backend-graphql-how-to-trigger-an-aws-appsync-mutation-from-aws-lambda-eda13ebc96c3">Backend GraphQL: How to trigger an AWS AppSync mutation from AWS Lambda</a></p><p>Dynamodb is also not ideal, I kinda knew that because I worked with firebase before and I knew what I should expect from the NoSQL database and how to architecture it so it fits all my needs. But it still took me a while to wrap around my head around the range and hash keys. In the end if you accept what it offers and that you’ll probably have to do streams to Amazon ES for advanced searches, DynamoDB will be just enough.</p><p>VTL files can do quick and easy tasks take you almost no time at all, but debugging is almost impossible. From what I found your only option is raising error from the response to read them.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b58b603b23fbb7626883a0cf08ac906/href">https://medium.com/media/3b58b603b23fbb7626883a0cf08ac906/href</a></iframe><p>VTL files can do quick and easy tasks and writing them takes almost no time at all, but debugging is almost impossible. From what I found your only option is raising an error from the response to read them. And if you need to do something more complicated, well you either need to go and write chained VTL functions (which is even harder to debug) or just write the lambda function. Most of my issues would be simply fixed if VTL would support <a href="https://aws.amazon.com/blogs/aws/new-amazon-dynamodb-transactions/">transactional operations</a> (sadly it’s just not possible right now)</p><p>Lambda@edge is perfect to go around CloudFront limitations but guess what, they can get stuck easily when you want to remove them and will just be there in your dashboard (unless you decide to delete your account).</p><p>Speaking of CloudFront, why it doesn’t support the brotli compression? I would really love not to put more logic into my lambda function so I can just respond with compressed files.</p><p><a href="https://medium.com/@felice.geracitano/brotli-compression-delivered-from-aws-7be5b467c2e1">Brotli compression delivered from AWS</a></p><p>Offline support is also another painful struggle. To some extent, there is a plugin to support offline AppSync and help you spin up a local dybamoDB instance, but the AppSync emulator doesn’t support CloudFormation syntax. Also, cognito doesn’t provide any way for you to run it locally. In the end, I usually just deployed the stack to the dev environment and connected to it.</p><p>Last but not least, AppSync or better to say AWS, provides such a nice and complex way to do authentication and authorization that at some point I was considering switching to custom jwt solution. When you finally do your roles and groups and assign permissions to them, you will find out there is no straight forward way to refresh the credentials including the new group on the client. You need to do something like this to get it done.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8c4340c5d00e61117a41c60db9ec42d/href">https://medium.com/media/d8c4340c5d00e61117a41c60db9ec42d/href</a></iframe><h3>Controversy</h3><p>The huge point for serverless naysayers is the fact that you get stuck in a single ecosystem and then you’re left on the mercy of that ecosystems maintainers/owners. While this is hugely true, the point when you realize you need to get away from it because of cost or technology limitations is usually the point where you would pay for a huge refactor anyway. While this is not ideal, it’s not as bad of a nightmare as everybody says it is when it comes to quickly spinning up projects. There are also alternatives that I plan investigating with the new project (looking at your <a href="https://kubeless.io/">kubeless</a>)</p><h3>Final words</h3><p>I wouldn’t be able to get a good insight into the serverless world without doing this project. I’ve chosen AppSync because it covered the basics I needed and while there were a couple of hiccups on the way, in the end, it delivered,</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ceee30984c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing serverless-cloudfront-distribution-certificate]]></title>
            <link>https://medium.com/@pavolfulop/introducing-serverless-cloudfront-distribution-certificate-52f28ee79c66?source=rss-6b77d812db56------2</link>
            <guid isPermaLink="false">https://medium.com/p/52f28ee79c66</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[certificate]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloudfront]]></category>
            <category><![CDATA[serverless-framework]]></category>
            <dc:creator><![CDATA[Pavol Fulop]]></dc:creator>
            <pubDate>Sun, 24 Feb 2019 09:31:00 GMT</pubDate>
            <atom:updated>2019-02-24T09:31:00.597Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KzqeWt5kJ10llTUTy7dNJA.png" /><figcaption><strong>source: undraw.co</strong></figcaption></figure><p>I was in a need for a serverless plugin to create a certificate for my CloudFront distribution. While there are some plugins that can request a certificate they usually can assign it only to APIGateway or they’ll create CloudFront distribution for you.</p><h4>Existing plugins</h4><p><a href="https://github.com/schwamster/serverless-certificate-creator">https://github.com/schwamster/serverless-certificate-creator</a> <a href="https://github.com/amplify-education/serverless-domain-manager">https://github.com/amplify-education/serverless-domain-manager</a></p><h4>My plugin</h4><p>What I needed is something that can simply assign a certificate to a domain associated with CloudFront distribution. This is already possible using CloudFormation ACM entry, but you’re required to validate the certificate all by yourself. If you don’t do that your stack creation progress will get stuck.</p><p>So this plugin easily creates the certificate if needed, creates a route53 entry to validate it and in the end assigns the certificate ARN to your CloudFront distribution.</p><p>If you feel like this is something you need, go check it out.</p><p><a href="https://github.com/pfulop/serverless-cloudfront-distribution-certificate">pfulop/serverless-cloudfront-distribution-certificate</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52f28ee79c66" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Repeat onPress action when holding button [react native]]]></title>
            <link>https://medium.com/@pavolfulop/repeat-onpress-action-when-holding-button-react-native-2c697cf28032?source=rss-6b77d812db56------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c697cf28032</guid>
            <category><![CDATA[touch]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[press]]></category>
            <dc:creator><![CDATA[Pavol Fulop]]></dc:creator>
            <pubDate>Mon, 06 Mar 2017 07:02:00 GMT</pubDate>
            <atom:updated>2017-03-06T07:02:00.901Z</atom:updated>
            <content:encoded><![CDATA[<p>This is rather a small recipe that I couldn’t find straightforwardly. Let’s say we have a button (<a href="https://facebook.github.io/react-native/docs/touchablehighlight.html"><strong>TouchableHighligh</strong></a><strong>,</strong> <a href="https://facebook.github.io/react-native/docs/touchablenativefeedback.html"><strong>TouchableNativeFeedback</strong></a><strong>, </strong><a href="https://facebook.github.io/react-native/docs/touchableopacity.html"><strong>TouchableOpacity</strong></a><strong>, </strong><a href="https://facebook.github.io/react-native/docs/touchablewithoutfeedback.html"><strong>TouchableWithoutFeedback</strong></a><strong> and </strong><a href="https://facebook.github.io/react-native/docs/button.html"><strong>Button</strong></a>) that has onPress action that increases amount of something.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/219/1*UowIdc80zCJb2I2t4ztqTA.gif" /><figcaption>Pretty simple</figcaption></figure><p>Everybody can do that, it’s pretty simple. Now what will do ordinary user if you ask him to add 50 more? He will do what comes natural, just holding down button and wait until he hits the mark. But when you provided <strong>onPress </strong>to increase amount by one, it won’t do any more than that, <strong>onLongPress </strong>won’t help either, it just fires one function when users holds button for long enough period of time. So what now?</p><p>There are two more props you can pass to touchable component, <strong>onPressIn</strong> and <strong>onPressOut</strong>. They are, as the name suggests, called upon pressing down the button and releasing it.</p><p>So with simple code and one timer we can just create something like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71c8390af2934fa1e94358dc4bf79bff/href">https://medium.com/media/71c8390af2934fa1e94358dc4bf79bff/href</a></iframe><p>Here we can see creating null object timer in the constructor of the component. Next are two functions, <strong>addOne</strong> which increases the state and with little bit of a delay calls itself again, <strong>stopTimer </strong>just clears the timeout. We can now use this two functions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee11033b98c848b1170a153ed697eb62/href">https://medium.com/media/ee11033b98c848b1170a153ed697eb62/href</a></iframe><p>Touchable opacity gets in onPressIn prop that calls mentioned function <strong>addOne</strong> while <strong>onPressOut</strong> just clears the timer. The result is instant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/219/1*m_317FPd2Mkv4tKODH63zA.gif" /><figcaption>Keep adding</figcaption></figure><p>When you press you will just increase state by one as before, but holding the button down will keep increasing the state until you release.</p><p>It’s simple, but effective.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c697cf28032" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase and redux living in the native house. Pt. 4— login with Facebook]]></title>
            <link>https://medium.com/@pavolfulop/firebase-and-redux-living-in-the-native-house-pt-4-login-with-facebook-e343837b5850?source=rss-6b77d812db56------2</link>
            <guid isPermaLink="false">https://medium.com/p/e343837b5850</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[facebook]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Pavol Fulop]]></dc:creator>
            <pubDate>Mon, 27 Feb 2017 07:02:00 GMT</pubDate>
            <atom:updated>2017-02-27T07:02:00.563Z</atom:updated>
            <content:encoded><![CDATA[<p>In the process of making an app you should have one thing on mind every time, the User. You should provide easy ways of authentication for user. Email login is somewhat safe way to be sure anybody can register an login, but using Facebook login, you are making what was before two fields form into one simple button.</p><p>The process of integration Facebook login into react native app with firebase is a bit of a tedious task. You can’t rely on methods such as <strong>signInWithPopUp </strong>or<strong> signInWithRedirect,</strong> you still need to follow the basic steps of enabling Facebook login and providing app id and secret, but the way of acquiring access_token is up to you.</p><p>Facebook has their whole sdk ready for react-native <a href="https://github.com/facebook/react-native-fbsdk">here</a>, but you are required to follow their step by step guide to include all the libs for ios and android. The boring part is mainly iOS since you have to put libs there manually. After that, you are ready to use fbsdk.</p><p>Next step is to include Facebook button in our app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec43d98cd84a6b0fa64e44ccfebeccff/href">https://medium.com/media/ec43d98cd84a6b0fa64e44ccfebeccff/href</a></iframe><p>The main part here is the onLoginFinished callback. As you can see, it gets currentAccessToken and uses that to call action that handles login with firebase.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c79fda0ce380a2717ed0659bf366253/href">https://medium.com/media/0c79fda0ce380a2717ed0659bf366253/href</a></iframe><p>Action is simple, it dispatches notification about logging in and then creates Facebook credential from acquired token. Next is just calling signInWithCredential and <em>voila </em>we have just logged in. It’s basically token for token right? One thing to notice, see how we have firebaseApp and firebase? FirebaseApp is an instance with all our configuration while firebase is just imported straight out of lib.</p><p>That’s basically all, the worst part is including all the necessary libs for bot platforms, the rest is pretty simple.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e343837b5850" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase and redux living in the native house. Pt. 3— login with email]]></title>
            <link>https://medium.com/@pavolfulop/firebase-and-redux-living-in-the-native-house-pt-3-login-with-email-a6232e168846?source=rss-6b77d812db56------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6232e168846</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[email]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Pavol Fulop]]></dc:creator>
            <pubDate>Mon, 20 Feb 2017 07:02:00 GMT</pubDate>
            <atom:updated>2017-02-20T07:02:00.816Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s been a while since I worked with firebase in react native. The main reason for writing these tutorials has been one project which has been put on hold in last couple of months. But things has changed and I will make at least two more articles (including this one) when it comes to firebase and react-native.</p><p>Every app that consists of active user base needs some sort of login. Firebase has been great in providing means of implementing various login methods trough well known providers or various custom implementations.</p><p>In this article I would like to cover registration and login via email and password. For purpose of this article, I am not going to dive deep into UI, but rather into actions for redux. Bare in mind that all mentioned code can be found in the <a href="https://github.com/pfulop/react-native-redux-firebase">repo</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*LwppNstQLb-Gz88HDAvbSg.gif" /><figcaption>Two simple inputs and register/login button. (ignore the FB button for now)</figcaption></figure><p>To login with email into firebase you must have Email/Password enabled in sign-in providers. You can find it in Authentication tab. Once you have that, you can put actual code to work.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ad60788e716ed4aed5e0c41c08dfe58/href">https://medium.com/media/2ad60788e716ed4aed5e0c41c08dfe58/href</a></iframe><p>In this function we can see dispatching action <strong>CREATING_ACCOUNT</strong>. This is useful if you need to provide some sort of loading information for user. This simple action just changes state loading from false to true. Next up we use our firebase instance to call function <strong>createUserWithEmailAndPassword.</strong> It<strong> </strong>takes two parameters and returns promise with newly created user. At this moment I also recommend to save any other additional data for user. Once this is done you can change the loading state back and do any other related action (redirect user to other screen, show success etc.) The catch part will return error in case something went wrong (array of errors).</p><p>Once account is created you can get some action for login.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8971396b924c51634b63cfad8702c68/href">https://medium.com/media/b8971396b924c51634b63cfad8702c68/href</a></iframe><p>Login is as simple as register. If you really go trough it, you can notice just change of method that is called.</p><p>Better than dispatching new user with login is to listen for login changes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0e3f07e22b414263dee5407f08e09be/href">https://medium.com/media/f0e3f07e22b414263dee5407f08e09be/href</a></iframe><p>In this way, you can do any login/logout logic whenever the auth status is changed from any part of your app. This can also provide an easy way to check for logged in user at the time of freshly started app.</p><p>Bare in mind that firebase has custom rules for passwords and you are required to provide at least 6 characters when creating new account.</p><p>In the next part we will take a look at FB and see what extra steps are required.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6232e168846" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Headless JS [react native] the missing parts]]></title>
            <link>https://medium.com/@pavolfulop/headless-js-react-native-the-missing-parts-d9b265061964?source=rss-6b77d812db56------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9b265061964</guid>
            <category><![CDATA[headlessjs]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Pavol Fulop]]></dc:creator>
            <pubDate>Mon, 13 Feb 2017 07:02:00 GMT</pubDate>
            <atom:updated>2018-01-10T20:12:34.212Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Edit: Check out this awesome </strong><a href="https://hackernoon.com/easy-os-background-tasks-in-react-native-bc4476c48b8a"><strong>article</strong></a><strong> by </strong><a href="https://hackernoon.com/@reidmayo"><strong>Reid Mayo</strong></a><strong>. Maybe that’s all that you’ll need.</strong></p><p>We all know that these days you don’t need to know anything about platform specific code to write iOS and android app, but there is a limit to not knowing. You can do only so much with just javascript. Fonts, social media libs, custom memory efficient lists and much more will require some sort of skill in native parts of iOS or android, whether it is just adding permissions or writing code in java or objective-c / swift. The good news is there are plenty of libs taking some of this “pain” away.</p><p>Not so long ago, <a href="https://facebook.github.io/react-native/docs/headless-js-android.html">Headless JS</a> was introduced into react-native. It helps you to use javascript for background tasks.</p><blockquote>Headless JS is a way to run tasks in JavaScript while your app is in the background</blockquote><p>It sounds wonderful, and it really lets you use javascript for background tasks, however some of the java code is still required. In the official docs is nice example on how to write your first background job, how to register it and how to write java service to run it. When you have all of the basics mastered there is only one thing left: <strong>run the task</strong>. How do I run it? The number one question that I see on forums, reddit and Stack Overflow is how do I run the background task? That’s what I will try to explain in this article.</p><h4>The purpose</h4><p>You probably have reason to write background task in the first place right? I mean you are not just trying to run something in the background for the lolz. Background tasks can have various reasons: downloading some sort of data periodically, running alarms or checking some state of the app.</p><h4>Running task is easy</h4><p>It really is easy, look, here is the code:</p><pre>Intent serviceIntent = <strong>new</strong> Intent(context, MyTaskService.class); context.startService(serviceIntent);</pre><p>And now it’s running.</p><p><strong>From where do I run it?</strong></p><p>This is the right question. The task can be run from anywhere, it can be run right from the app initialisation (this will probably result in crash tho). Task should be run from the place most related to it’s purpose.</p><p>For example, I want my app to measure connection speed whenever phone gets connected to the network. The best place to put it would be in <strong>BroadcastReceiver </strong>that listens on connection change.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c001460ee0172ea1a4b1effb09f17bc/href">https://medium.com/media/4c001460ee0172ea1a4b1effb09f17bc/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81e5adbc375bdc353b715e0f5623c242/href">https://medium.com/media/81e5adbc375bdc353b715e0f5623c242/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afa52aea1d436cb27578cac0316edac0/href">https://medium.com/media/afa52aea1d436cb27578cac0316edac0/href</a></iframe><p>There are couple of things you may noticed:</p><ol><li>We check if app is in foreground, this is required precaution, if app would be in foreground it would just crash. This is to prevent any slow UI caused by your background task (since js engine is single threaded #goFastCrashHarder). You can use ActivityManager to see if app is in foreground <a href="http://stackoverflow.com/questions/2166961/determining-the-current-foreground-application-from-a-background-task-or-service">http://stackoverflow.com/questions/2166961/determining-the-current-foreground-application-from-a-background-task-or-service</a></li><li>We acquire wakelock. This is recommended by react native docs. Doing this will ensure we have necessary CPU power to finish our task.</li></ol><p>Now you can run your js code to react on any intent your app will receive. You can run it even from other parts of your app just make sure you don’t run it while app is in foreground.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9b265061964" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lazy me working with objection.js and Apollo stack]]></title>
            <link>https://medium.com/@pavolfulop/lazy-me-working-with-objection-js-and-apollo-stack-ea3bc89ef26a?source=rss-6b77d812db56------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea3bc89ef26a</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[apollostack]]></category>
            <category><![CDATA[objection]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Pavol Fulop]]></dc:creator>
            <pubDate>Mon, 19 Sep 2016 06:01:02 GMT</pubDate>
            <atom:updated>2016-09-19T06:01:02.454Z</atom:updated>
            <content:encoded><![CDATA[<p>As I am writing back end for one of our project, I realize I would be much more happy to listen to imperial march playing outside by live band.</p><p>So why not to automate part of the process? (there is a TL;DR at the end)</p><h4>The setup</h4><p>Since the front end is not important in this case, let’s talk back end. We are using MySQL/MariaDB database (not really sure at this point and since we are using knex.js, there is still time to make this decision), knex.js for query construction and as mentioned at the beginning, apollo stack, which means we are running apollo server over express.js.</p><p>If you are somewhat familiar with apollo stack, you know it comes with bunch of great tools to simplify your work, but mainly to combine your resolvers with schema. Now here is the great thing, you are not required to use any specific thing in resolvers and it’s completely up to you how you will fetch data.</p><p>But since we have pretty big database, and I am used to ORMs, I have chosen one. From the headline it’s obvious we are using objection.js. I could give you many reasons why objection.js, but since internet is full of them I let it on you, the reader, to figure out if it’s any use for your project (but you can find some subjective opinions <a href="https://www.reddit.com/r/node/comments/49sq6a/reliable_nodejs_orm_for_rdbms/?st=isyu5pqh&amp;sh=ce08f473">here</a>).</p><p>So now you have pretty basic overview of what is there serving data, now for the automation part.</p><h4>Schema and resolvers in one go… with a catch</h4><p>It would be nice if I wouldn’t have to write schema and resolvers. We have models why can’t there be and automatic way to do it?</p><p>That was the major thinking, I have written the models why can’t they just somehow be plugged into the Apollo server by themselves? It turns out, they can.</p><p><a href="https://github.com/Vincit/objection-graphql">Objection-graphql</a> made by the same development expert as objection.js itself does exactly that. You just choose from which models to generate shcema, and it will do so including resolvers.</p><p>It’s easy as:</p><pre>let Schema = graphQlBuilder().model(Dog).model(Cat).build();</pre><p>You can have whole api in minutes. There is a catch, it’s all public. As far as documentation goes and my tries with it, you can’t secure back end by custom user validations (like if he has rights to see his or hers profile). And this was a huge drawback for me.</p><h4>My solution</h4><p>So here goes the lazy part. I wasn’t sure how long it would take me to write custom code that would transform everything into schema with resolvers that could have injected some kind of user checks, but I was sure it has to be easy to write something to generate just schema.</p><p>When you look at the objection.js and it’s way of model validation (via JSON Schema), it looks really familiar. From that point it was just converting that exact schema we written once for each model into grapqhl schema. We used just String,Integer,Id and Float types but you are by no means held to not make custom enums generation and whatever you need.</p><p>There is also one great thing and that’s creating a custom base model that all the other models can extend.</p><p>So in the end, the result looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/70d5c0ad90685e4f8412ee7e7e525851/href">https://medium.com/media/70d5c0ad90685e4f8412ee7e7e525851/href</a></iframe><p>Which can be then called as simple as this:</p><pre>Dog.generateGraphSchema</pre><p><strong>TL;DR: </strong>I created custom function in base model that converts objection.js JSON Schema into grapqhl schema.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea3bc89ef26a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase and redux living in the native house. Pt. 2— playing with fire]]></title>
            <link>https://medium.com/@pavolfulop/firebase-and-redux-living-in-the-native-house-pt-2-playing-with-fire-2a9330d1e43d?source=rss-6b77d812db56------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a9330d1e43d</guid>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Pavol Fulop]]></dc:creator>
            <pubDate>Sat, 10 Sep 2016 18:21:02 GMT</pubDate>
            <atom:updated>2016-09-10T18:21:02.132Z</atom:updated>
            <content:encoded><![CDATA[<h3>Recap</h3><p>In the last part we prepared our app, we initialized redux and firebase so we can work with it now.</p><h3>Action</h3><p>First of, let’s create folder for our actions.</p><pre>mkdir app/actions</pre><p>And let’s create our first file that will describe our actions over items.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/460ee05d5467107fe2b295e7d4b4f6fe/href">https://medium.com/media/460ee05d5467107fe2b295e7d4b4f6fe/href</a></iframe><p>Do you remember our dummy item reducer? It’s time to give him some purpose. We will add default initial state that will hold empty array and after that reaction to our action type CHANGED_ITEMS.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9b755357f43ba1ec9287f78ff6bf292/href">https://medium.com/media/d9b755357f43ba1ec9287f78ff6bf292/href</a></iframe><p>It’s pretty simple, it just replaces actual state with the new one. If you would like to be more efficient you could listen only once for values, and after that listen for specific actions such as addChild or removeChild. Than you would have to implement more complex reducer but in the end transport little bit less data with every change.</p><h3>SHOWTIME</h3><p>At this point it would be nice to implement some front end functionality. Since I am not going to get into navigation we will have everything on one screen.</p><p>First we create component that will be connected to our redux store. It will send functions as props for items manipulation as well as items themselves.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10f8d0edef05fbd0784cb1d20374c6f5/href">https://medium.com/media/10f8d0edef05fbd0784cb1d20374c6f5/href</a></iframe><p>Then we create component for item adding. Which is simple input and button that dispatches action via props.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d85291dc8e71fff254078c01340845e2/href">https://medium.com/media/d85291dc8e71fff254078c01340845e2/href</a></iframe><p>In the end there is component that shows all the items. For sake of simplicity, the remove action is dispatched on long press and update on short one (with some random number).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9a76daa1d7d93454b24198670ee3575/href">https://medium.com/media/e9a76daa1d7d93454b24198670ee3575/href</a></iframe><p>And tat is all to data manipulation.</p><p>The repo can be found in <a href="https://github.com/pfulop/react-native-redux-firebase">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a9330d1e43d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Firebase and redux living in the native house. Pt. 1 — init]]></title>
            <link>https://medium.com/@pavolfulop/firebase-and-redux-living-in-the-native-house-pt-1-init-50b041d2b06c?source=rss-6b77d812db56------2</link>
            <guid isPermaLink="false">https://medium.com/p/50b041d2b06c</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Pavol Fulop]]></dc:creator>
            <pubDate>Sat, 10 Sep 2016 18:01:02 GMT</pubDate>
            <atom:updated>2016-09-10T18:01:02.315Z</atom:updated>
            <content:encoded><![CDATA[<p>In this series I would like to introduce a concept that we use in our company, or better to say will be used. It will be step by step tutorial on how to use react-native with redux and firebase.</p><p>So let’s start out….</p><h3>The init part</h3><p>Every react-native projects needs to be initialized, so let’s not waste time and do:</p><pre>react-native init TheCall</pre><p>This will initialize the project with everything. What you can find there is pretty nicely described on react-native pages, so I am not going to get into it. Let’s however add what we are missing.</p><pre>mkdir -p app/{actions,components,reducers,store}</pre><p>You may notice I am using just components folder instead of components and containers combo. I am doing that because I rather have sub-folders where components are grouped together than have everything in two folders. You are free to do however you please tho.</p><p>Now we need some libraries.</p><pre>npm i --save redux react-redux</pre><p>And a little bit of touch.</p><pre>touch app/index.js</pre><p>Index.js will essentially be place of entry point for our app, we will link it there from platform specific indexes. Let’s get into it right now.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38fbfe3f4c4d8e2bb2f2c2e2268c0afd/href">https://medium.com/media/38fbfe3f4c4d8e2bb2f2c2e2268c0afd/href</a></iframe><h3>The happy story store part</h3><p>You should probably know what redux is, you also probably know we need to do some initialization on it.</p><p>Let’s create simple reducer that for now does nothing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7538bde6106cac4bb44e623bceea7f74/href">https://medium.com/media/7538bde6106cac4bb44e623bceea7f74/href</a></iframe><p>Then we can export them in index file for our reducers</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/303bd9c7875a6f38ae34dfce07b51089/href">https://medium.com/media/303bd9c7875a6f38ae34dfce07b51089/href</a></iframe><p>And in the end, we need to setup our store. This is simple creation of store with some hot reducer replacement, we will return here when we will be going trough firebase setup.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c89d43a787ebd5e5d099f1a6a8d46cb4/href">https://medium.com/media/c89d43a787ebd5e5d099f1a6a8d46cb4/href</a></iframe><p>Now back to our app entry point and add some component so we can test it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/812e998baa617f2d405991392a74e17f/href">https://medium.com/media/812e998baa617f2d405991392a74e17f/href</a></iframe><p>And here is the code for the App component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4040b06c36cdf6c4e3d1e07d79e6362/href">https://medium.com/media/d4040b06c36cdf6c4e3d1e07d79e6362/href</a></iframe><h3>The firebase part</h3><p>Since we have our redux hooked and our app is pretty much running, let’s add some real life connection to it. We need to somehow access firebase in our app to add/remove/watch items in our database. The best way I think there is for this kind of task, is using redux-thunk with pretty little feature it has.</p><p>But first some dependency installation.</p><pre>npm i --save firebase redux-thunk</pre><p>Now I assume you have your firebase app created and we can initialize it on our device.</p><p>As I said we will be using one feature that redux-thunk has that is Injecting a custom argument. So let’s take a look how it will affect our store creation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64ff1c53ad4c1c0f146c2a8f02017aeb/href">https://medium.com/media/64ff1c53ad4c1c0f146c2a8f02017aeb/href</a></iframe><p>We simply initialize our firebase app, then we plug it into thunk as a extra argument, and in the end apply middleware to our store.</p><p>If you run this app now, there won’t be much to see other than the well known initial facebook provided screen, but in the background, there is a whole initialization going on and ready to use redux with firebase.</p><p>In the next one, I will show you how to create/edit/delete/watch items in our database.</p><p>The repo can be found in <a href="https://github.com/pfulop/react-native-redux-firebase">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50b041d2b06c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>