<?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 Juliano Appel Klein on Medium]]></title>
        <description><![CDATA[Stories by Juliano Appel Klein on Medium]]></description>
        <link>https://medium.com/@julianoaklein?source=rss-4114c820d159------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*H_wmDcbTkFi_kHCc.</url>
            <title>Stories by Juliano Appel Klein on Medium</title>
            <link>https://medium.com/@julianoaklein?source=rss-4114c820d159------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 01:45:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@julianoaklein/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[Tiny React Lib — Shared Business Logic Using Hooks]]></title>
            <link>https://medium.com/@julianoaklein/tiny-react-lib-shared-business-logic-using-hooks-984efe067c04?source=rss-4114c820d159------2</link>
            <guid isPermaLink="false">https://medium.com/p/984efe067c04</guid>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Juliano Appel Klein]]></dc:creator>
            <pubDate>Sat, 05 Feb 2022 17:47:31 GMT</pubDate>
            <atom:updated>2022-04-16T13:46:19.455Z</atom:updated>
            <content:encoded><![CDATA[<h3>Tiny React Lib — Shared Business Logic Using Hooks</h3><p>Using React hooks to separate logic from a Component is not a new thing.</p><p>But what if you want to use this business logic elsewhere and also need to share the state? Here is a simple approach.</p><pre>import * as React from &quot;react&quot;;</pre><pre>export function makeBLContext&lt;LogicFacade, LogicProps&gt;({<br>  useLogic,<br>}: {<br>  useLogic: (props: LogicProps) =&gt; LogicFacade;<br>}) {<br>  const ContainerContext = React.createContext&lt;LogicFacade&gt;(null as any);</pre><pre>const ContainerContextProvider = (props: LogicProps &amp; { children: React.ReactNode }) =&gt; {<br>    const { children, ...rest } = props;<br>    const facade = useLogic(rest as any);<br>    return &lt;ContainerContext.Provider value={{ ...facade }}&gt;{children}&lt;/ContainerContext.Provider&gt;;<br>  };</pre><pre>return {<br>    useLogicContext: () =&gt; {<br>      return React.useContext(ContainerContext);<br>    },<br>    LogicContextProvider: ContainerContextProvider,<br>  };<br>}</pre><p>So how does it works? You create a hook that contains the logic. This hook must return a <em>facade</em> to enable components to interact with this logic. Finally, you use the higher-order function makeBLContext to wrap everything. It is so simple that it hurts.</p><p>Here is a sample usage:</p><pre>// create the extended logic hook</pre><pre>function useCounterLogic(context: { id: number }){<br>  const [count, setCount] = React.useState(0);<br>  return {<br>    count,<br>    increment: () =&gt; setCount(count+1)<br>  };<br>}</pre><pre>export const { LogicContextProvider: ConterLogicContextProvider, useLogicContext: useCounterLogicContext } = makeBLContext({ useLogic: useCounterLogic });</pre><p>Now you must wrap your app with your ConterLogicContextProvider and then you can use the new hook useCounterLogicContext anywhere in your tree.</p><p>If two different components need to use the same logic and related state, they just need to use the same hook.</p><p>This approach is not so different from Flutter BLOC pattern.</p><p>Check a small demo using the library on GitHub: <a href="https://github.com/julianoappelklein/use-logic-context">https://github.com/julianoappelklein/use-logic-context</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=984efe067c04" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Warm Up NextJS Using Netlify Scheduled Functions]]></title>
            <link>https://medium.com/@julianoaklein/warm-up-nextjs-using-netlify-scheduled-functions-c537a5cb3dc?source=rss-4114c820d159------2</link>
            <guid isPermaLink="false">https://medium.com/p/c537a5cb3dc</guid>
            <category><![CDATA[lambda-function]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[netlify]]></category>
            <category><![CDATA[cold-start]]></category>
            <category><![CDATA[cron]]></category>
            <dc:creator><![CDATA[Juliano Appel Klein]]></dc:creator>
            <pubDate>Wed, 02 Feb 2022 23:55:44 GMT</pubDate>
            <atom:updated>2022-02-03T21:11:06.785Z</atom:updated>
            <content:encoded><![CDATA[<p>It is quite easy to run NextJS on Netlify. I did this a few weeks ago for a project. But because we are using heavy front-end libraries, the initial load for dynamic pages was taking too long.</p><p>The problem was that the lambda function in charge of rendering the pages was “cold”. But how to solve this? Time to warm things up!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9YJWmKpJIcU3iHqA" /><figcaption>Photo by <a href="https://unsplash.com/@jeremybezanger?utm_source=medium&amp;utm_medium=referral">Jeremy Bezanger</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Today I could finally find a solution, because <strong>today</strong> Netlify launched a service called <a href="https://www.netlify.com/blog/quirrel-joins-netlify-and-scheduled-functions-launches-in-beta">Scheduled Functions</a>.</p><p>Right now it is a beta service, so you have to enable it. You can find detailed instruction here: <a href="https://github.com/netlify/labs/blob/main/features/scheduled-functions/documentation/README.md">https://github.com/netlify/labs/blob/main/features/scheduled-functions/documentation/README.md</a></p><p>Here is a simple function to keep your endpoints warm:</p><pre>const axios = require(&#39;axios&#39;); //you can use another libray<br>const { schedule } = require(&#39;@netlify/functions&#39;); //use the most recent version</pre><pre>const url = process.env.DEPLOY_PRIME_URL; //this will point to your homepage - it&#39;s a Netlify environment variable</pre><pre>const handler = async function(event, context) {<br>  try{<br>    const res = await axios.get(url);<br>    console.log(`Warmed up ${url} - StatusCode: ${res.status}`);<br>  }<br>  catch(e){<br>    console.log(`Failed to warm up ${url} - Error: ${e.toString()}`);<br>  }<br>};</pre><pre>module.exports.handler = schedule(&quot;*/5 * * * *&quot;, handler); // this is just a cron expression</pre><p>That’s it. Let me know if it worked for you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c537a5cb3dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Better Way To Copy a Immutable Object Using Dart]]></title>
            <link>https://medium.com/@julianoaklein/a-better-way-to-copy-a-immutable-object-using-dart-9a92963b3ae2?source=rss-4114c820d159------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a92963b3ae2</guid>
            <dc:creator><![CDATA[Juliano Appel Klein]]></dc:creator>
            <pubDate>Tue, 18 Aug 2020 17:34:29 GMT</pubDate>
            <atom:updated>2020-08-18T17:43:01.829Z</atom:updated>
            <content:encoded><![CDATA[<p>Cloning objects in Dart is boring, but we have to do it eventually. And many times we need a copy with just a small change. We can’t simple mutate the original object, we need to create a new one — reactive frameworks like immutability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eScVJwxZSAOuVN2JXOTG8g.jpeg" /></figure><p>I see the following pattern in some places:</p><pre>@immutable<br>class Profile {<br>  const Profile({@required this.name, @required this.age});</pre><pre>  final String name;<br>  final int age;<br>  <br>  Profile copyWith({<br>    String name,<br>    int age<br>  }) {<br>    return Profile(<br>      name: name ?? this.name,<br>      age: age ?? this.age,<br>    );<br>  }<br>}</pre><p>The problem happens when I need to copy an object and set a property to null. It’s not possible using the method copyWith above.</p><p>Below is the solution I use:</p><pre>@immutable<br>class Profile {<br>  const Profile({@required this.name, @required this.age});<br>  <br>  final String name;<br>  final int age;</pre><pre>  Profile copyWith({<br>    String Function() name,<br>    int Function() age,<br>  }) {<br>    return Profile(<br>      name: name != null ? name() : this.name,<br>      age: age != null ? age() : this.age,<br>    );<br>  }<br>}</pre><p>Now, instead of passing directly the value I need to change, I pass the a function that returns the new value. Passing null will not change the value, but passing a function that returns null will set the value to null.</p><pre>var profile0 = Profile(name: &quot;Old Name&quot;, age: 35);<br>var profile1 = profile0.copyWith(name: ()=&gt; &quot;New Name&quot;); //name = &quot;New Name&quot;<br>var profile2 = profile0.copyWith(name: ()=&gt; null); //name = null<br>var profile3 = profile0.copyWith(); //name = &quot;Old Name&quot;;<br>var profile4 = profile0.copyWith(name: null); //name = &quot;Old Name&quot;;</pre><p>I hope this helps you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a92963b3ae2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>