<?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 Vasyl Stokolosa on Medium]]></title>
        <description><![CDATA[Stories by Vasyl Stokolosa on Medium]]></description>
        <link>https://medium.com/@shystruk?source=rss-a27da3214e5c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*IWTLveoK9YvzpMbKIUkvgA.jpeg</url>
            <title>Stories by Vasyl Stokolosa on Medium</title>
            <link>https://medium.com/@shystruk?source=rss-a27da3214e5c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 22:35:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shystruk/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[Web Workers in React + Redux application]]></title>
            <link>https://medium.com/hackernoon/web-workers-in-react-redux-application-129274e84a4e?source=rss-a27da3214e5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/129274e84a4e</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Vasyl Stokolosa]]></dc:creator>
            <pubDate>Tue, 23 Oct 2018 08:26:10 GMT</pubDate>
            <atom:updated>2018-10-23T08:26:10.108Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1yBlyY5wRASOZawcjZU8lA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/aysgVUqJaMw?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Ben Konfrst</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><em>Run scripts in background threads and perform tasks without interfering with the user interface.</em></p><p>We all know that the JavaScript code executes in a single thread. It means that code will execute line by line and if a particular task takes a long time to complete everything else is held up until that task finishes. If we want to unload the main threat Web Workers what is all about.</p><h3>☝️ <strong>What you should know</strong></h3><p>Web Workers is supported almost in all browsers. For slightly more controlled error handling and backwards compatibility, it is a better way to do a check.</p><pre>if (window.Worker) {<br><br>  ...<br><br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mVj2YBzHyGLervr-ZQEi3w.png" /></figure><p>Create only one instance, each call new Worker(&#39;worker.js&#39;) is going to load worker.js file. So, you may see something like that in Network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TSAbHo6MfsSjXqgOdYlVXg.png" /></figure><h3>React + Redux</h3><p>With Redux update store is simple. So, we are going to have a place or a file where we create a Worker instance, export it and listen onmessage event where we dispatch an event when a data comes from the Worker.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7aa0e5f0199c77f5b5781a34df6d2b0/href">https://medium.com/media/c7aa0e5f0199c77f5b5781a34df6d2b0/href</a></iframe><p>In worker.js we may importScripts if we need to import some scripts to global worker scope. In Web Worker you may use <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIXMLHttpRequest">XMLHttpRequest</a> so in example below I import <a href="https://github.com/axios/axios">axios</a> and use it for XHR calls. onmessage listener is called whenever new message bubbles through the worker. postMessage method sends a message to the worker’s inner scope.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec78b71a9ad2fb83a436a9d810873791/href">https://medium.com/media/ec78b71a9ad2fb83a436a9d810873791/href</a></iframe><p>Use Worker instance. Import already existing Worker and call postMessage method with data which you want to pass to the Worker worker.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5820f1443f1f4ae4885959059ab4eead/href">https://medium.com/media/5820f1443f1f4ae4885959059ab4eead/href</a></iframe><h3>Conclusion</h3><p>Web Workers is powerful API you should definitely use it. It is good for background sync, prefetching data, ray tracing. Using web workers can have a significant impact on the performance of your web application.</p><h3>📃 Useful links</h3><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers">Using Web Workers</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Worker">The Worker interface</a></li><li><a href="https://johnresig.com/blog/web-workers/">Computing with JavaScript Web Workers</a></li><li><a href="https://blog.teamtreehouse.com/using-web-workers-to-speed-up-your-javascript-applications">Using Web Workers to Speed-Up Your JavaScript Applications</a></li><li><a href="https://html.spec.whatwg.org/multipage/workers.html">Web Workers Spec</a></li></ul><p>👏 <strong>Thank you for reading. Suggestions, comments, thoughts are welcome </strong>👍</p><p><strong>If you like this, clap, follow me on </strong><a href="http://medium.com/@shystruk"><strong>medium</strong></a><strong>, </strong><a href="https://twitter.com/shystrukk"><strong>twitter</strong></a><strong>, </strong><a href="https://github.com/shystruk"><strong>github</strong></a><strong> share with your friends </strong>😎</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=129274e84a4e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/web-workers-in-react-redux-application-129274e84a4e">Web Workers in React + Redux application</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrate Custom Elements into React app]]></title>
            <link>https://codeburst.io/integrate-custom-elements-into-react-app-ef38eba12905?source=rss-a27da3214e5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef38eba12905</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Vasyl Stokolosa]]></dc:creator>
            <pubDate>Tue, 14 Aug 2018 22:19:43 GMT</pubDate>
            <atom:updated>2018-08-17T14:26:12.483Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rKQnLhmMm09EnVaDfScMkw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@stairhopper">Alex Holyoake</a> on <a href="https://unsplash.com/">Unsplash</a></figcaption></figure><p><em>Web Components in React with support in all popular browsers, including IE 11</em></p><p>To be short and clear <a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements">Custom Element</a> is a HTML element that encapsulates your functionality on an HTML page. <a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components">Web Components</a> is a suite of different technologies allowing you to create reusable custom elements.</p><p>Quite a long time I’ve been thinking for creating a Web Components pattern library. The main question was, which framework to choose ❔ A company may have projects on a different frameworks and Web Components should have an opportunity to be integrated with any of them. Custom Elements right now is the best way to do that.</p><p>So, what I did first is started to investigate how it works, limitations and <a href="https://caniuse.com/#feat=custom-elementsv1">browser support</a> 👮</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kx-soyObmJIMlYlUL80uAQ.png" /></figure><p>Firefox, IE, Opera Mini not yet. Ok, maybe we have <a href="https://github.com/WebComponents/webcomponentsjs">polyfills</a>? Yes, we do 👍 We even have a couple <a href="https://www.webcomponents.org/introduction">libraries</a> which helps us to build a web components. Who starts with a library if it does not know vanilla JavaScript 👲</p><h4>☝️ Idea</h4><p>Web Component should be simple, reusable, configurable and all apps have it. Tada, <a href="https://www.webcomponents.org/element/notification-service-js">notification-service</a>, already published and you may try to consume😉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*4ziBHikiKzOKobGBxdQS0w.gif" /><figcaption>Demo</figcaption></figure><h4>🙉 Start</h4><p>How to build Custom Element step by step, lifecycle hooks, props, attrs etc. you may find <a href="https://developers.google.com/web/fundamentals/web-components/customelements">here</a>.</p><p>In our case, we are going to communicate trough <a href="https://github.com/shystruk/custom-event-js">CustomEvent</a> dispatcher as we initialize service ones and receive notifications from any place of an app. For that, we have connectedCallback when element is inserted to the DOM and disconnectedCallback. Moreover, we give an opportunity to rewrite custom styles. For that we use style-src property.</p><blockquote>&lt;notification-service<strong> style-src=”build/style.css”</strong>&gt;&lt;/notification-service&gt;</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b12ea8d58c6f28d2b7a018818ec46d9/href">https://medium.com/media/1b12ea8d58c6f28d2b7a018818ec46d9/href</a></iframe><h4>🔧 <a href="https://github.com/WebComponents/webcomponentsjs">Polyfills</a></h4><p>As we are going to support all popular browsers, including IE 11 we definitely have to use polyfills.</p><p>What we need:</p><ul><li>webcomponents-bundle.js contains all of the web components polyfills</li><li>custom-elements-es5-adapter.js support ES6 class in Custom Element</li><li><a href="https://github.com/zloirock/core-js">core-js</a> for fixing <a href="https://github.com/webcomponents/webcomponentsjs/issues/972">Out of stack space</a> issue in IE</li></ul><h4>🏆Integration</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1aac581ab64dbf9e013556fbc2484c85/href">https://medium.com/media/1aac581ab64dbf9e013556fbc2484c85/href</a></iframe><p>You can try how it works <a href="https://github.com/shystruk/create-react-redux-app-structure">here</a> 🚀</p><p><em>Build configurations: </em><a href="https://github.com/shystruk/create-react-redux-app-structure/blob/master/webpack.config.js"><em>webpack.config.js</em></a><em>, </em><a href="https://github.com/shystruk/create-react-redux-app-structure/blob/master/gulpfile.js"><em>gulp task ( web_components_vendor)</em></a></p><h4>Conclusion</h4><p>I like Custom Elements so far and functionality which it provides. With different varieties of frameworks finally, you may start simply build truly reusable web components using nothing more than vanilla JS/HTML/CSS 😎 Hope all browsers is going to support Custom Elements soon. Happy coding! Have fun! 🕜</p><h4>📃 Useful links</h4><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements">Using Custom Elements</a></li><li><a href="https://developers.google.com/web/fundamentals/web-components/customelements">Custom Elements v1</a></li><li><a href="https://developers.google.com/web/fundamentals/web-components/">Building Components</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components">Web Components</a></li><li><a href="https://custom-elements-everywhere.com/">Custom Elements Everywhere</a></li><li><a href="https://www.webcomponents.org/introduction#what-are-web-components-">What are web components?</a></li><li><a href="https://html.spec.whatwg.org/multipage/custom-elements.html#custom-element">Specs</a></li><li><a href="https://github.com/WebComponents/webcomponentsjs">Polyfills</a></li></ul><p>👏 <strong>Thank you for reading. Suggestions, comments, thoughts are welcome </strong>👍</p><p><strong>If you like this, clap, follow me on </strong><a href="http://medium.com/@shystruk"><strong>medium</strong></a><strong>, </strong><a href="https://twitter.com/shystrukk"><strong>twitter</strong></a><strong>, </strong><a href="https://github.com/shystruk"><strong>github</strong></a><strong> share with your friends </strong>😎</p><h3>Vasyl Stokolosa on Twitter</h3><p>Integrate Custom Elements into React app&quot; https://t.co/0KLsfXer6F #javascript #react #customElements</p><figure><a href="http://bit.ly/codeburst"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i3hPOj27LTt0ZPn5TQuhZg.png" /></a></figure><blockquote>✉️ <em>Subscribe to </em>CodeBurst’s<em> once-weekly </em><a href="http://bit.ly/codeburst-email"><strong><em>Email Blast</em></strong></a><strong><em>, </em></strong>🐦 <em>Follow </em>CodeBurst<em> on </em><a href="http://bit.ly/codeburst-twitter"><strong><em>Twitter</em></strong></a><em>, view </em>🗺️ <a href="http://bit.ly/2018-web-dev-roadmap"><strong><em>The 2018 Web Developer Roadmap</em></strong></a><em>, and </em>🕸️ <a href="http://bit.ly/learn-web-dev-codeburst"><strong><em>Learn Full Stack Web Development</em></strong></a><em>.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef38eba12905" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/integrate-custom-elements-into-react-app-ef38eba12905">Integrate Custom Elements into React app</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[v4 Create React + Redux app structure with build configurations. What’s new?]]></title>
            <link>https://codeburst.io/v4-create-react-redux-app-structure-with-build-configurations-whats-new-523bdec328c6?source=rss-a27da3214e5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/523bdec328c6</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Vasyl Stokolosa]]></dc:creator>
            <pubDate>Mon, 02 Jul 2018 21:56:14 GMT</pubDate>
            <atom:updated>2018-07-10T17:04:42.475Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mM8u_Sm-EKH_5ZRBUzkBsA.png" /></figure><p>If you missed first part go <a href="https://hackernoon.com/how-create-react-redux-app-structure-helps-you-to-start-a-project-faster-cf564c64689c">here</a> and figure out what is <a href="https://github.com/shystruk/create-react-redux-app-structure">create-react-redux-app-structure</a> about 😎</p><h3>🕵️‍What’s new?</h3><p>In <strong>v4</strong> there are a few new things, <a href="https://github.com/shystruk/no-internet">offline</a> mode support, Webpack 4, <a href="https://www.npmjs.com/package/react-intl">internationalization</a>.</p><h4>📡 Offline</h4><p>Determine if an application is an offline help you to behave differently. You will notify a user and try to save as much user actions as possible, and when you go back online execute them.</p><p>In <a href="https://github.com/shystruk/create-react-redux-app-structure/blob/master/app/pages/App.jsx">app/pages/App.jsx</a> file you will find <a href="https://github.com/shystruk/no-internet">noInternet</a> service which helps you to find out when the internet is no accessible.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce2e4a4df704c895be2ad4bd3740728e/href">https://medium.com/media/ce2e4a4df704c895be2ad4bd3740728e/href</a></iframe><h4>🎼 Webpack 4</h4><p><a href="https://medium.com/webpack/webpack-4-released-today-6cdb994702d4">Here</a> you may find why Webpack 4 is cool and what’s new.</p><p>CommonsChunkPlugin was replaced by default API called optimization.splitChunks. So now, out of the box you will have shared chunks automatically generated for you in a variety of scenarios.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7005291a68ea34f483927ead5643d9d/href">https://medium.com/media/f7005291a68ea34f483927ead5643d9d/href</a></iframe><h4>🌍 Internationalization</h4><p>It is really good to have an application accessible for everyone. Check out file <a href="https://github.com/shystruk/create-react-redux-app-structure/blob/master/app/app.jsx">app/app.jsx</a> where you may find intl configuration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc3927da8aaca0e26da2e776bae7cb7b/href">https://medium.com/media/bc3927da8aaca0e26da2e776bae7cb7b/href</a></iframe><h3>🙇 Thank you</h3><p>To all of those use <a href="https://github.com/shystruk/create-react-redux-app-structure">create-react-redux-app-structure</a> and help to make it better, faster and easier to use. Hope it help you to start a project faster and enjoy what you are doing ✌️</p><p>👏 <strong>Thank you for reading. Suggestions, comments, thoughts are welcome </strong>👍</p><p><strong>If you like this, clap, follow me on </strong><a href="http://medium.com/@shystruk"><strong>medium</strong></a><strong>, </strong><a href="https://twitter.com/shystrukk"><strong>twitter</strong></a><strong>, </strong><a href="https://github.com/shystruk"><strong>github</strong></a><strong> share with your friends </strong>😎</p><figure><a href="http://bit.ly/codeburst"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i3hPOj27LTt0ZPn5TQuhZg.png" /></a></figure><blockquote>✉️ <em>Subscribe to </em>CodeBurst’s<em> once-weekly </em><a href="http://bit.ly/codeburst-email"><strong><em>Email Blast</em></strong></a><strong><em>, </em></strong>🐦 <em>Follow </em>CodeBurst<em> on </em><a href="http://bit.ly/codeburst-twitter"><strong><em>Twitter</em></strong></a><em>, view </em>🗺️ <a href="http://bit.ly/2018-web-dev-roadmap"><strong><em>The 2018 Web Developer Roadmap</em></strong></a><em>, and </em>🕸️ <a href="http://bit.ly/learn-web-dev-codeburst"><strong><em>Learn Full Stack Web Development</em></strong></a><em>.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=523bdec328c6" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/v4-create-react-redux-app-structure-with-build-configurations-whats-new-523bdec328c6">v4 Create React + Redux app structure with build configurations. What’s new?</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Moving project’s components/services into packages (the separation of concerns)]]></title>
            <link>https://medium.com/hackernoon/moving-projects-components-services-into-packages-the-separation-of-concerns-1f42661eac6e?source=rss-a27da3214e5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f42661eac6e</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Vasyl Stokolosa]]></dc:creator>
            <pubDate>Thu, 14 Jun 2018 21:16:46 GMT</pubDate>
            <atom:updated>2018-06-19T17:55:24.341Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*E3ilF7NY9nj5EoyqSmQpdQ.png" /></figure><blockquote><a href="https://en.wikipedia.org/wiki/Component-based_software_engineering"><strong>Component-based software engineering</strong> (<strong>CBSE</strong>), also called as <strong>component-based development</strong> (<strong>CBD</strong>), is a branch of software engineering that emphasizes the separation of concerns with respect to the wide-ranging functionality available throughout a given software system.</a></blockquote><p>In this day’s Component-Based Architecture is highly popular, each modern UI framework provides component structure approach. Check out this <a href="https://medium.com/@dan.shapiro1210/understanding-component-based-architecture-3ff48ec0c238">article</a> for pros and cons. What I like the most in CBA is the separation of concerns😎</p><p>Whether starting a small project or having a huge one the separation of concerns is going to be a key point for easy maintenance, testability, reusability. If you are UI engineer you should have probably heard about <a href="https://www.npmjs.com/">npm</a> package manager. This is a good way to move your reusable components, services there.</p><p><strong>Why should I do that? </strong>☝️<br>1. easy to share between teams<br>2. integration in one line - <strong><em>import </em></strong><em>package </em><strong><em>from </em></strong><em>‘package’</em><br>3. maintenance <br>4. testing<br>5. <a href="https://docs.npmjs.com/getting-started/semantic-versioning">semantic versioning</a><br>6. private or public (community may help to improve)</p><p>If you want to have a <a href="https://docs.npmjs.com/private-modules/intro">private packages</a> it is also possible.</p><p>As an example you may check this project.</p><p><a href="https://www.npmjs.com/package/create-react-redux-app-structure">create-react-redux-app-structure</a></p><p>In Dependencies list it has 4 public packages which were checked by open source community and improved 👌 (<a href="https://www.npmjs.com/package/no-internet">no-internet</a>, <a href="https://www.npmjs.com/package/publish-subscribe-js">publish-subscribe-js</a>, <a href="https://www.npmjs.com/package/set-interval">set-interval</a>, <a href="https://www.npmjs.com/package/famulus">famulus</a>).</p><p><strong>How to create npm package?</strong></p><p>Check out official <a href="https://docs.npmjs.com/getting-started/creating-node-modules">doc</a>. <a href="https://rollupjs.org/guide/en">Rollup</a> (module bundler for JavaScript) may help you to create a new standardized format for code modules included in the ES6 revision of JavaScript.</p><p>In addition, to the separation of concerns, I would like to mention “Pattern library” as a way to collect user interface design elements. Check out this <a href="https://boagworld.com/design/pattern-library/">article</a> for more understanding 💪</p><p>Some thoughts are <a href="https://www.funfunforum.com/t/does-anyone-move-projects-shareable-components-services-into-npm-packages/5218">here</a> and there:</p><iframe src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=reddit&amp;url=https%3A//www.reddit.com/r/javascript/comments/8re8ng/does_anyone_move_projects_shareable/&amp;image=https%3A//i.embed.ly/1/image%3Furl%3Dhttps%253A%252F%252Fa.thumbs.redditmedia.com%252Fe6mxbvhJdURxyPmtY-8pikLxy_qgOR5u2btN-aBha98.jpg%26key%3Da19fcc184b9711e1b4764040d3dc5c07" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/61d78de38b6d22e1f7e0b5aae6bb419f/href">https://medium.com/media/61d78de38b6d22e1f7e0b5aae6bb419f/href</a></iframe><p>👏 <strong>Thank you for reading. Suggestions, comments, thoughts are welcome </strong>👍</p><p><strong>If you like this, clap, follow me on </strong><a href="http://medium.com/@shystruk"><strong>medium</strong></a><strong>, </strong><a href="https://twitter.com/shystrukk"><strong>twitter</strong></a><strong>, </strong><a href="https://github.com/shystruk"><strong>github</strong></a><strong> share with your friends </strong>😎</p><h3>Vasyl Stokolosa on Twitter</h3><p>I just published &quot;Moving project&#39;s components/services into packages (the separation of concerns)&quot; #javascript https://t.co/ctddvNivrP</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f42661eac6e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/moving-projects-components-services-into-packages-the-separation-of-concerns-1f42661eac6e">Moving project’s components/services into packages (the separation of concerns)</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Communication between components (universal)]]></title>
            <link>https://medium.com/hackernoon/communication-between-components-7898467ce15b?source=rss-a27da3214e5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7898467ce15b</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-components]]></category>
            <dc:creator><![CDATA[Vasyl Stokolosa]]></dc:creator>
            <pubDate>Wed, 16 May 2018 16:41:31 GMT</pubDate>
            <atom:updated>2018-10-01T16:18:46.934Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x2nSjG5eXAXEDnEZ_jGMyQ.jpeg" /><figcaption>Photo by <a href="https://www.flickr.com/photos/colwynboy/">Colwyn</a> on <a href="https://www.flickr.com/">Flickr</a></figcaption></figure><p>Communication is important, especially neighborhood communication 😎 Let’s collect communication approaches between components.</p><p>I remember a time when I jumped to Angular and while developing I had to find the best way to communicate between components. In Angular we may dispatch events ($emit, $broadcast), in React use Redux etc. Each framework has own approaches, but we may have general solutions no matter of framework, web components. So, let’s collect them.</p><p>We are going to talk about neighborhood communication 😎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p9cZF9VuuIPBLth7v-QrQA.png" /></figure><h4><a href="https://github.com/shystruk/custom-event-js">Custom Events</a></h4><p>Custom Event is a good approach to dispatch events and listen. You should listen event from target <a href="https://developer.mozilla.org/en-US/docs/Web/API/Element">Element</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document">Document</a>, and <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window">Window</a>, but the target may be any object that supports events (such as <a href="https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest">XMLHttpRequest</a>). It does not work in IE but for that we have a Polyfill solution.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16932839705733df0195944222629851/href">https://medium.com/media/16932839705733df0195944222629851/href</a></iframe><p>So, Custom Event Service is going to look like that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ed344e0110d101d92c73e16d6c24914/href">https://medium.com/media/3ed344e0110d101d92c73e16d6c24914/href</a></iframe><p>Communication phase:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1tXmtYggQDHpH9rpcXezmg.png" /></figure><h4><a href="https://github.com/shystruk/publish-subscribe-js">Publish/Subscribe</a></h4><blockquote>The Publish/Subscribe pattern encourage us to think hard about the relationships between different parts of our application.</blockquote><p>Publish/Subscribe pattern saves a TOPIC name and reference to a callback. When you publish the TOPIC it calls the callback.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rZLkJmccJyroNoMYZTWGiQ.png" /></figure><h4>👯 Difference between Custom Event and Pub/Sub</h4><p><em>Callbacks are not subscribed to particular events. Every payload is dispatched to every registered callback.</em></p><h4><a href="https://github.com/shystruk/bind-dom">Watching DOM tree</a></h4><p>Another way to communicate is watching DOM changes. You may observe node element changes (attributes, childList, characterData) and when DOM changes occur observer will invoke a specified callback function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4ccfb8613c5b7ab069b6a994f479ecf/href">https://medium.com/media/e4ccfb8613c5b7ab069b6a994f479ecf/href</a></iframe><p>👏 <strong>Thank you for reading. Suggestions, comments, thoughts are welcome </strong>👍</p><p><strong>If you like this, clap, follow me on </strong><a href="http://medium.com/@shystruk"><strong>medium</strong></a><strong>, </strong><a href="https://twitter.com/shystrukk"><strong>twitter</strong></a><strong>, </strong><a href="https://github.com/shystruk"><strong>github</strong></a><strong> share with your friends </strong>😎</p><h3>Vasyl Stokolosa on Twitter</h3><p>I just published &quot;Communication between components&quot; https://t.co/5eetRdMTj6</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7898467ce15b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/communication-between-components-7898467ce15b">Communication between components (universal)</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JSDoc. JavaScript: The Useful Parts]]></title>
            <link>https://medium.com/hackernoon/jsdoc-javascript-the-useful-parts-58f52f0cc25e?source=rss-a27da3214e5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/58f52f0cc25e</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Vasyl Stokolosa]]></dc:creator>
            <pubDate>Wed, 11 Apr 2018 10:05:54 GMT</pubDate>
            <atom:updated>2018-06-15T21:30:25.738Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QZOOET6bciSu3EsbLAXseA.jpeg" /><figcaption>Photo by <a href="https://www.flickr.com/photos/purplerabbits/">Rowan</a> on <a href="https://www.flickr.com/">Flickr</a></figcaption></figure><blockquote><a href="http://usejsdoc.org/about-getting-started.html">JSDoc</a> 3 is an API documentation generator for JavaScript, similar to Javadoc or phpDocumentor. You add documentation comments directly to your source code, right alongside the code itself.</blockquote><p>I use JSDoc more than 4 years and found it extremely good and useful. Documentation is important to have in a project. It helps you to save time for remembering, teaching newcomers, support. The project may have different types of documentation. As an engineer, the important part of the documentation is code documentation and JSDoc solves that problem as well.</p><h3>Simple example</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2216cb647647f86bf8967ca65b353b9b/href">https://medium.com/media/2216cb647647f86bf8967ca65b353b9b/href</a></iframe><p>From the simple example, you may simply and fast understand what parameter’s types are function takes. You should not look inside the function for that. More often functions, methods are more complicated and it takes time to jump into the function and see what parameter’s types are.</p><h3>Good example</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/229397d7d2dc4b17b4797122b2d97bba/href">https://medium.com/media/229397d7d2dc4b17b4797122b2d97bba/href</a></iframe><p>Here you may find detailed documentation for a module. Just try to go through and if you do not understand what the module does we may have a call ☎️</p><p><a href="https://github.com/shystruk/famulus/blob/master/isValuesUnique.js">shystruk/famulus</a></p><h3><strong>Type annotations (</strong>Type Checking)</h3><p>One of the most powerful features that I like in JSDoc is types checking. It works perfectly in WebStorm. It won’t replace a TypeScript but after you get used to writing JSDoc you will stop be worrying about types and most important you are not needed to waste time on any configuration part.</p><h4>WebStrom</h4><p>So, here you may see that WebStorm highlights which argument is not fitting assignable type. It helps to avoid bugs with types and most importantly save time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*78S209e0DYNEu9SgpbvGeA.png" /></figure><h4>VS Code</h4><blockquote>VS Code allows you to leverage some of TypeScript’s advanced type checking and error reporting functionality in regular JavaScript files. This is a great way to catch common programming mistakes. These type checks also enable some exciting quickfixes for JavaScript, including <em>add missing import</em> and <em>add missing property</em>.</blockquote><p>For VS Code you should add //@ts-check in each file if you want to have that.</p><p><a href="https://code.visualstudio.com/Docs/languages/javascript#_type-checking-and-quick-fixes-for-javascript-files">JavaScript Programming with Visual Studio Code</a></p><p>👏 <strong>Thank you for reading. Suggestions, comments, thoughts are welcome </strong>👍</p><p><strong>If you like this, clap, follow me on </strong><a href="http://medium.com/@shystruk"><strong>medium</strong></a><strong>, </strong><a href="https://twitter.com/shystrukk"><strong>twitter</strong></a><strong>, </strong><a href="https://github.com/shystruk"><strong>github</strong></a><strong> share with your friends </strong>😎</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58f52f0cc25e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/jsdoc-javascript-the-useful-parts-58f52f0cc25e">JSDoc. JavaScript: The Useful Parts</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is void forgotten? JavaScript: The Useful Parts]]></title>
            <link>https://medium.com/hackernoon/is-void-forgotten-javascript-the-useful-parts-2de88901a1e0?source=rss-a27da3214e5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2de88901a1e0</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[is-void-forgotten]]></category>
            <dc:creator><![CDATA[Vasyl Stokolosa]]></dc:creator>
            <pubDate>Thu, 21 Dec 2017 13:39:04 GMT</pubDate>
            <atom:updated>2018-06-15T21:33:38.828Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z3RlLyTIxznbsHQ7DDt-cw.jpeg" /><figcaption>Photo by <a href="https://www.flickr.com/photos/54459164@N00/">Johnson Cameraface</a> on <a href="https://www.flickr.com/">Flickr</a></figcaption></figure><blockquote>In many languages, void is a type that has no values. In JavaScript, void is a operator that takes an operand and return undefined. This is not useful, and it is very confusing. Avoid void. ~ Douglas Crockford. <a href="http://shop.oreilly.com/product/9780596517748.do">JavaScript: The Good Parts</a></blockquote><p>If you agree with that statement I do not want to waste your time, jump out from here and keep saving the world. 😎 If not, let’s discover why void is useful and you should not avoid it.</p><h3>Why void confuses?</h3><p>void 0 === undefined //true 😰 😱 😵</p><p>Why? How? What is void? Is this even JavaScript?</p><p>Answers which I got when asked developers about the void and the main confuse here is that developers forgot or have not known or find strange.</p><p>The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void"><strong>void</strong></a><strong> operator</strong> evaluates the given <em>expression</em> and then returns <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined">undefined</a>. That is all what you need to know about void operator.</p><h3>How void can be useful?</h3><h4>1. Evaluate expression and jump out from a function</h4><p>One time I’v done a code review and found a method like that:</p><pre>function doStuff(a) {<br>    if (a) {<br>        doSomething()       <br>    } else {<br>        doSomethingElse()<br>        return<br>    }</pre><pre>    doSomethingMore()<br>}</pre><p>So, from this method you may see that in case doSomethingElse() we return undefined and jump out from the function. Let’s save one line and make it more readable with void.</p><pre>function doStuff(a) {<br>    if (a) {<br>        doSomething()       <br>    } else {<br>        return void doSomethingElse()<br>    }</pre><pre>    doSomethingMore()<br>}</pre><p>From void description you know that it evaluates doSomethingElse() and return undefined. That exactly what we need 👍</p><h4>2. Check for undefined</h4><p>Old browsers allowed undefined to be re-assigned undefined = &#39;test&#39;. However, this was fixed in 2009 with ECMAScript 5.</p><p><a href="https://es5.github.io/#x15.1.1.3">Annotated ES5</a></p><p>If you need to support old browser e.g. IE8, here is a helper function 😊</p><pre>function isUndefined(value) {<br>    return value === void 0<br>}</pre><h4>3. preventDefault() behavior for a link</h4><p>We all know that a tag without href attribute is not valid, but in HTML5 href attribute is not required, so you can omit.</p><p><a href="https://www.w3.org/TR/2016/REC-html51-20161101/links.html#element-attrdef-a-href">HTML 5.1: 4.8. Links</a></p><p>Somehow, if you need to prevent hrefworks use void.</p><pre>&lt;a href=&quot;javascript: void(0)&quot;&gt;About&lt;/a&gt;</pre><h4>4. Immediately Invoked Function Expressions</h4><p>When using an <a href="https://developer.mozilla.org/en-US/docs/Glossary/IIFE">immediately-invoked function expression</a>, void can be used to force the function keyword to be treated as an expression instead of a declaration.</p><pre>void function IIFE() {<br>    // do something ...<br>}()</pre><h3>Conclusion</h3><p>void is a simple operator and I find it useful. I guess, more developers do not use it because they have not touched it while learning. Of course, if a team find it confused better to discuss. In help, ESLint has the rule (<a href="https://eslint.org/docs/rules/no-void2">no-void</a>). Happy coding! 😎</p><p>👏 <strong>Thank you for reading. Suggestions, comments, thoughts are welcome :)</strong></p><p><strong>If you like this, clap, follow me on </strong><a href="http://medium.com/@shystruk"><strong>medium</strong></a><strong>, </strong><a href="https://twitter.com/shystrukk"><strong>twitter</strong></a><strong>, </strong><a href="https://github.com/shystruk"><strong>github</strong></a><strong> share with your friends </strong>✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2de88901a1e0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/is-void-forgotten-javascript-the-useful-parts-2de88901a1e0">Is void forgotten? JavaScript: The Useful Parts</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Do you still register window event listeners in each component? (React in example)]]></title>
            <link>https://medium.com/hackernoon/do-you-still-register-window-event-listeners-in-each-component-react-in-example-31a4b1f6f1c8?source=rss-a27da3214e5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/31a4b1f6f1c8</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Vasyl Stokolosa]]></dc:creator>
            <pubDate>Wed, 29 Nov 2017 08:15:57 GMT</pubDate>
            <atom:updated>2019-04-22T15:26:14.455Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*JSpJXMCq2veTsUKutpknVg.jpeg" /></figure><blockquote>Each time when you call <strong>addEventListener()</strong> method it adds the specified EventListener- compatible object to the list of event listeners for the specified event type on the EventTarget on which it is called. The event target may be an Element in a document, the Document itself, a Window, or any other object that supports events (such as XMLHttpRequest).</blockquote><p>From that description we may find that each time when you call window.addEventListener(&#39;resize&#39;, callback) to body element object will be added in resize event listeners list.</p><p>In React more often you may see approach like that:</p><pre>componentDidMount() {<br>   window.addEventListener(&#39;resize&#39;, <strong>this</strong>.handleResize)<br>}<br><em><br></em>componentWillUnmount() {<br>   window.removeEventListener(&#39;resize&#39;, <strong>this</strong>.handleResize)<br>}</pre><p>It works, but as we mentioned before, resize events list will grow up as many times as you reuse that component. Eventually, you will have picture like that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*a7WnWc_olxaTiby7_0meqA.png" /></figure><p>Chrome DevTools a flame chart of activity on the main thread.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DayrIspn3OP_tDCTNTk0Jg.png" /></figure><p>Looks not good I would say. What may it cause you? Firstly, it is hard to debug and the code is not scalable. What if you need to do some stuff when each resizes event is firing? Will be hard, right? You need to go to each component where resize event is listening and make changes. Secondly, it may cause you a bad performance.</p><h3>Let’s improve</h3><p>What do we need to have?</p><ol><li>One resize event listener</li><li>Each component should have possibility to listen resize event if needed and when component is unmounted it should not listen</li></ol><p>Sounds like <a href="https://addyosmani.com/resources/essentialjsdesignpatterns/book/#observerpatternjavascript">The Publish/Subscribe</a> pattern may help here.</p><blockquote>This is where the objects in a system may subscribe to other objects and be notified by them when an event of interest occurs. ~ <a href="http://twitter.com/addyosmani">Addy Osmani</a></blockquote><p>Let’s create an object where we can subscribe, unsubscribe and publish:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/203e480df3286fa4bfb1fec3e242df96/href">https://medium.com/media/203e480df3286fa4bfb1fec3e242df96/href</a></iframe><p>Have a look at Publish/Subscribe UMD package for better usage:</p><p><a href="https://www.npmjs.com/package/publish-subscribe-js">publish-subscribe-js</a></p><p>Then, we need to have a place where we listen resize event and publish to each subscriber when the event is fired.</p><p>First, let’s create a global object which we are going to share across application and setresizeEvent property.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8f26e3d4e99a7b2af875c9713ba5822/href">https://medium.com/media/d8f26e3d4e99a7b2af875c9713ba5822/href</a></iframe><p>Listen to window events when DOM is ready.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9436065471c6a6c933ac9c21c97a64f3/href">https://medium.com/media/9436065471c6a6c933ac9c21c97a64f3/href</a></iframe><p>So, we created subscriber/publisher, listen resize event in one place for whole application and publish to each subscriber when the event is fired. What is left? Right, let’s subscribe to the event from a component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0f8de7a5a287af1ccf2da038774dd35/href">https://medium.com/media/a0f8de7a5a287af1ccf2da038774dd35/href</a></iframe><p>That’s it :)</p><p>You may use subPub for each window event listener. In result we have clear window resize event listeners list and code are more scalable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*NkHMauu2rFom45dEgz5p9g.png" /></figure><p>Find full code example here (page Resize_SubPub) :</p><p><a href="https://www.npmjs.com/package/create-react-redux-app-structure">create-react-redux-app-structure</a></p><p><strong>Thank you for reading. Suggestions, comments, thoughts are welcome :)</strong></p><p><strong>If you like this, clap, follow me on </strong><a href="http://medium.com/@shystruk"><strong>medium</strong></a><strong>, </strong><a href="https://twitter.com/shystrukk"><strong>twitter</strong></a><strong>, </strong><a href="https://github.com/shystruk"><strong>github</strong></a><strong> share with your friends </strong>✌️</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fdde502%2F&amp;image=https%3A%2F%2Fucarecdn.com%2F57662ddc-da7c-407b-afcb-cb45184b2705%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/d25dd15e8727342107fbe0b6d67b030e/href">https://medium.com/media/d25dd15e8727342107fbe0b6d67b030e/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31a4b1f6f1c8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/do-you-still-register-window-event-listeners-in-each-component-react-in-example-31a4b1f6f1c8">Do you still register window event listeners in each component? (React in example)</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[clearIntervals() when user has a nap (React in example with Page Visibility API)]]></title>
            <link>https://codeburst.io/clearintervals-when-user-has-a-nap-3bf8010c986b?source=rss-a27da3214e5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bf8010c986b</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Vasyl Stokolosa]]></dc:creator>
            <pubDate>Mon, 27 Nov 2017 08:07:39 GMT</pubDate>
            <atom:updated>2018-06-15T21:34:39.860Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*SgRhMFkcXmgYII0muNWy_A.jpeg" /></figure><p>Do you still perform unnecessary tasks when the webpage is not visible? The setInterval() method will continue calling the function until clearInterval() is called, or the window is closed. Do you think that all your setIntervals is needed when the user has a nap?</p><p>Now you may find in the web heavy, complex applications (platforms, mail agents etc.) which need bring to user fresh data without refreshing the page, notifications, timers. User wants to see and interact with live page, page which will talk to her/him. The simplest way to achieve that is to ask a server about new data with intervals (<em>a</em> <em>better way to use </em><a href="https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API"><em>WebSockets</em></a>)<strong>.</strong></p><p>Let’s imagine that we have a huge complex platform with a lot of users and traffic is huge. We want to make less load on the server. Stop, I do front end, should I care about the server traffic, server loading, have less requests if it is possible? Yes, you have to! To make an unneeded request you not only load the server but load <a href="https://developer.mozilla.org/en-US/docs/Glossary/Call_stack">call stack</a>, so page will work slowly. Even Facebook stops playing video when you switch to another tab.</p><h3>How we can setInterval better?</h3><p>As we want to improve performance and clear, set interval when we need to more clear, let create a constructor which helps us to solve this problem. This will help us to have one instance of the interval and call clear set interval.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6497a68f7a4af46c7bfffe1dcd190ce/href">https://medium.com/media/d6497a68f7a4af46c7bfffe1dcd190ce/href</a></iframe><p>I have an interval where I make HTTP request for getting amount of new users each 5 sec. and render them on UI.</p><pre>let newUsers_Interval = new Interval(getAmountNewUsers, 5000)</pre><pre>newUsers_Interval.start()</pre><h3><strong>Should we make this requests when the user has a nap?</strong></h3><p>Let’s think.</p><p>I change a number of the users each 5 sec. This is the not main part of the application with which user interacts and follow. Can I stop showing new numbers and show the last amount of users when user come back to the page? Yes, I can. Let’s do that.</p><p>We need to have another interval or listener which will be checking if the user does not interact with a page.</p><h3>How to check if user has a nap?</h3><p><a href="https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API">Page Visibility API</a> will help you to achieve that as well.</p><blockquote>The API is particularly useful for saving resources by giving developers the opportunity to not perform unnecessary tasks when the webpage is not visible.</blockquote><p>So, what we need to do, is to start and stop intervals when page is visible or not.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc280b8c6eed8d0fee74dd3b40fe2e6c/href">https://medium.com/media/bc280b8c6eed8d0fee74dd3b40fe2e6c/href</a></iframe><p>Find full code example here (page Page_Visibility_API) :</p><p><a href="https://www.npmjs.com/package/create-react-redux-app-structure">create-react-redux-app-structure</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*Vgrc88ZyK_Z-kqF1rA_aYg.gif" /><figcaption>Demo</figcaption></figure><p>Another solution is listening document click, scroll events and compare dates when user last time interacts with page and when we want to stop making a requests.</p><p>First, let’s create another interval which will be checking if user does not interact with a page some time. 15 minutes is fine. As you may see, here we compare two dates as we describer before. startDate we set when the page is first loaded and reset it on document click event. <a href="https://gist.github.com/shystruk/df6206e69b4ed775e325db7c96bce23b"><em>all code together</em></a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a17877df14d1974101984f439373d1f/href">https://medium.com/media/6a17877df14d1974101984f439373d1f/href</a></iframe><p>If you are building extensions for Chrome. Have a look at <a href="https://developer.chrome.com/extensions/tabs">Chrome Tabs API</a> <a href="https://developer.chrome.com/extensions/tabs#event-onActivated">onActivated </a>listener.</p><blockquote>Fires when the active tab in a window changes.</blockquote><pre>chrome.tabs.onActivated.addListener(function callback)</pre><p>For additional help, have a look at this package. No more variable needed for clearInterval() :)</p><p><a href="https://www.npmjs.com/package/set-interval">set-interval</a></p><p><strong>Thank you for reading. Suggestions, comments, thoughts are welcome :)</strong></p><p><strong>If you like this, clap, follow me on </strong><a href="http://medium.com/@shystruk"><strong>medium</strong></a><strong>, </strong><a href="https://twitter.com/shystrukk"><strong>twitter</strong></a><strong>, </strong><a href="https://github.com/shystruk"><strong>github</strong></a><strong> share with your friends </strong>✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bf8010c986b" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/clearintervals-when-user-has-a-nap-3bf8010c986b">clearIntervals() when user has a nap (React in example with Page Visibility API)</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How create-react-redux-app-structure helps you to start a project faster]]></title>
            <link>https://medium.com/hackernoon/how-create-react-redux-app-structure-helps-you-to-start-a-project-faster-cf564c64689c?source=rss-a27da3214e5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf564c64689c</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Vasyl Stokolosa]]></dc:creator>
            <pubDate>Thu, 23 Nov 2017 08:57:48 GMT</pubDate>
            <atom:updated>2018-09-24T07:46:01.343Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cra-Ej2KqxYifqVSGN_LLQ.png" /></figure><blockquote><a href="https://github.com/shystruk/create-react-redux-app-structure">See the code on GitHub</a>. <a href="https://www.npmjs.com/package/create-react-redux-app-structure">Learn more on npmjs.com</a></blockquote><p>I prefer to create a project from the scratch, it helps you to learn, investigate and just understand how tool which you want to add works. New tools come to life more and more often and it is not too easy and fast to start a new project. For example, I decided that React+Redux fits my needs very well, so I started application based on it. I want to use ES6, async/await and more. To run all this stuff I need to configure Wepback, Babel, also Gulp/Grunt will help. So, to make this all to run will take much time. That is why, I decided to prepare and share App Structure for starting project faster with build configurations.</p><h3>What can we find here?</h3><h4>Server</h4><p>The server runs on <a href="http://expressjs.com/">Express </a>framework. To start the server run node index.js from the root folder.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d8a1d0099e7cbfbf9aa27ff4f9a8c6d/href">https://medium.com/media/4d8a1d0099e7cbfbf9aa27ff4f9a8c6d/href</a></iframe><p>Files are separated into folders, so if you do not need Node server just remove the index.js file and the server folder.</p><p>As we are running the server we need to deliver static files .html, .css, .js, images. So for that, we are listening root folder ./ and deliver index.html for two routes that we have.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec74835cba46ef019ecdb62df008aab7/href">https://medium.com/media/ec74835cba46ef019ecdb62df008aab7/href</a></iframe><h4>React + Redux</h4><p>Check out the folders structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*-2xgDrfMfPeEXNVv9xYNcQ.png" /><figcaption>Created with help of <a href="https://creately.com/">https://creately.com</a></figcaption></figure><ul><li><a href="https://redux.js.org/docs/basics/Actions.html"><strong>actions </strong></a>- are payloads of information that send data from your application to your store</li><li><strong>components </strong>-<strong> </strong>folder has <strong>dumb </strong>folder where <a href="https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0">dumb or presentational</a> components stored and <a href="https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0">smart or container</a> components also store here</li><li><strong>pages</strong> - pages based on routes</li><li><a href="https://redux.js.org/docs/basics/Reducers.html"><strong>reducers</strong></a><strong> </strong>-<strong> </strong>specify how the application’s state changes in response</li><li><a href="https://hashnode.com/post/5-best-libraries-for-making-ajax-calls-in-react-cis8x5f7k0jl7th53z68s41k1"><strong>resources </strong></a>-<strong> </strong>HTTP request files for each component</li><li><strong>services </strong>-<strong> </strong>reusable global services, e.g. Alert, Notification service</li></ul><p>For more details, you can jump into any folder and check files inside.</p><p>Inside <strong>pages </strong>folder you may find App.jsx file. It takes all pages and connect() React Redux store with the <a href="https://reacttraining.com/web/api/withRouter">withRouter</a> higher-order component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a84ecefbedc0c7fe62c769961d2bb13/href">https://medium.com/media/7a84ecefbedc0c7fe62c769961d2bb13/href</a></iframe><h4>Store</h4><p>The store is created in the app/store.js file. You may see that in production process we do not add redux-logger to middleware.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d5288453af23fd45418f5b0b7957846/href">https://medium.com/media/0d5288453af23fd45418f5b0b7957846/href</a></iframe><h3>Build Configurations</h3><h4>Scripts</h4><p>Have a look at scripts in package.json .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a962f17abaa0c4377524662474b83e65/href">https://medium.com/media/a962f17abaa0c4377524662474b83e65/href</a></iframe><p>You may see three build types <strong>dev, prod, staging. </strong>dev build we run Webpack and Gulp concurrently as they are not dependent on each other.</p><h4>Webpack</h4><p>For production and staging builds we need to minify files and set the process environment to production , so for that, we are using <strong>webpack-merge</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8002107735ea4112ff851ae0a709157d/href">https://medium.com/media/8002107735ea4112ff851ae0a709157d/href</a></iframe><h4>CDN</h4><p>If you want to support CDN for static files (js, css, images, fonts) you are welcome. Specify in config.json file <strong>assetHost </strong>URL<strong> </strong>value for the build where you want to use CDN. After the build is finished you may see prefix assetHost URL in the root index.html file and .css images/fonts.</p><p>Gulp replace static files:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d17dd2686b2a4a007845221466b49a4d/href">https://medium.com/media/d17dd2686b2a4a007845221466b49a4d/href</a></iframe><p>Grunt images and fonts inside:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a79b1160557c6e3fdf50d9bfe587b76/href">https://medium.com/media/3a79b1160557c6e3fdf50d9bfe587b76/href</a></iframe><p>You can download the <a href="https://github.com/shystruk/create-react-redux-app-structure">repository </a>or install through npm npm i create-react-redux-app-structure and follow instructions. For more information, have a look what’s new in v4.</p><p><a href="https://codeburst.io/v4-create-react-redux-app-structure-with-build-configurations-whats-new-523bdec328c6">v4 Create React + Redux app structure with build configurations. What’s new?</a></p><p>Hope it will help you to start your project faster and easier.</p><p>I would love to have your help. If you have an idea how to improve, change the app structure please submit a pull request or create an issue.</p><p><strong>Thank you for reading. Suggestions, comments, thoughts are welcome :)</strong></p><p><strong>If you like this, clap, follow me on </strong><a href="http://medium.com/@shystruk"><strong>medium</strong></a><strong>, </strong><a href="https://twitter.com/shystrukk"><strong>twitter</strong></a><strong>, </strong><a href="https://github.com/shystruk"><strong>github</strong></a><strong> share with your friends </strong>✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf564c64689c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/how-create-react-redux-app-structure-helps-you-to-start-a-project-faster-cf564c64689c">How create-react-redux-app-structure helps you to start a project faster</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>