<?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 Valerii Sorokobatko on Medium]]></title>
        <description><![CDATA[Stories by Valerii Sorokobatko on Medium]]></description>
        <link>https://medium.com/@tuchk4?source=rss-79d461c2745a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*SlTjBhdNh8C14I0YtplUcw.jpeg</url>
            <title>Stories by Valerii Sorokobatko on Medium</title>
            <link>https://medium.com/@tuchk4?source=rss-79d461c2745a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 06:33:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tuchk4/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[Open Source and Community ❤️]]></title>
            <link>https://medium.com/@tuchk4/open-source-and-community-%EF%B8%8F-dbe412fd90a0?source=rss-79d461c2745a------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbe412fd90a0</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[community]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[love]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Valerii Sorokobatko]]></dc:creator>
            <pubDate>Tue, 05 Dec 2017 12:49:20 GMT</pubDate>
            <atom:updated>2017-12-05T12:49:20.573Z</atom:updated>
            <content:encoded><![CDATA[<p>Open Source is a great thing that we have. Open Source projects Maintainers do a lot of hard work each day and I very much appreciate it. I want to say “Thanks!” to all the contributors who make the developer’s lives easier and saves time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BPj6yEiT_SJudampUGNjwQ.png" /><figcaption>Open Source community</figcaption></figure><p>If you need some features that are not implemented in the package <br>you use — don’t start to develop your own solutions. In many cases this is not justified. At first — try to suggest features to Maintainers via Github. The community always provides positive reaction on cool and useful suggestions. If not — you should think about it again. There is a big chance that you also would not need these features 😉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_JGOk3HoGusF72CZGRb7dQ.png" /><figcaption>Improve. Contribute. Suggest.</figcaption></figure><p>Always remember, as an OSS (Open Source Software) developer — <br>you will provide a lot of help to developers all over the world!<br>Be responsible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbe412fd90a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Alicante 2017: Why I Love Create React App]]></title>
            <link>https://medium.com/@tuchk4/react-alicante-2017-why-i-love-create-react-app-ed2670b03cc3?source=rss-79d461c2745a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed2670b03cc3</guid>
            <category><![CDATA[conference]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Valerii Sorokobatko]]></dc:creator>
            <pubDate>Fri, 29 Sep 2017 15:32:26 GMT</pubDate>
            <atom:updated>2017-12-05T12:50:12.395Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SDC1-5od0a78EQgOUyEEKQ.png" /></figure><p>Hello! My name is Valerii Sorokobatko and this story is about my lighting talk at the <a href="http://reactalicante.es/">React Alicante 2017</a> conference.</p><p>I have an article <a href="https://medium.com/@tuchk4/why-i-love-create-react-app-e63b1be689a3">Why I Love Create React App</a> where I wrote about:</p><ul><li>Why I love Create React App</li><li>Why I don’t want to eject</li><li>My experience using Create React App</li><li>Tips and Tricks</li><li><a href="https://github.com/tuchk4/awesome-create-react-app">Awesome Create React App</a></li></ul><p>Today I don’t have enough time to speak about all of that. I will not speak about Create React App features in details or discuss other similar tools because it is just tools in the hands of the developers. I am going to speak about <strong>the times before Create React App</strong> and <strong>how Create React App saves our time</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mp5KCB68SpWqRBqOCHuRAg.png" /></figure><p>We started to use Webpack a while ago. There were times when each team was looking for <strong>Senior Webpack Developers</strong>. It’s documentation was not very good. I had to read sources to understand some features and how to configure the way I needed it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wDySqwvgPt8Pv9o1FncqgQ.png" /></figure><h3>Tools we used</h3><ul><li>Webpack</li><li>babel</li><li>PostCSS</li></ul><h4><strong>Webpack</strong></h4><p>In many situations there are the same configs in several applications and I didn’t understand why it worked correctly on one but didn’t work on another.</p><h4>Babel</h4><p>There were no borders. We could use all unstable features because they looked cool. Features like decorators, functional-bind, and do-expressions. Then our code started to become zombie like with <strong>dead syntax features</strong>.</p><h3>We Should</h3><ul><li>Constantly read all documentations</li><li>Configure all tools</li><li>Search google to find useful plugins</li><li>Setup environments</li><li>Optimize production build</li></ul><h3>Improve Developer Experience</h3><ul><li>Beautiful output build log</li><li>New and old bundle size differences</li><li>Environment variables injecting</li></ul><h3>About problems</h3><p>It most cases developers should do this only one time and for the application development phase. Problems comes when there are more than 1 application.</p><p>We have <strong>5 teams</strong> and <strong>30+</strong> React Applications. I have always sought to ensure that all applications have the same webpack config, same babel presets, and the same way to use CSS. Why? Because it is much easier to contribute and support all applications and it is easier to migrate from one application to another.</p><p>Also this applies to code and application architectures but today we will not speak about this.</p><p>To keep the same configs between applications we should sync it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LFfS5TuR736pl2ap7YdR2g.png" /><figcaption>Sync configuration between applications</figcaption></figure><p>It is really hard to sync it all manually. There are a lot of business tasks and development where there is not enough time for technical improvements.</p><p>Then we started to use npm to share configurations between applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tWlGE5x7-vplDSorK-DqCw.png" /><figcaption>Share configuration between application using npm</figcaption></figure><p>But</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hPBzFmdraKnbe1qJPBdywQ.png" /><figcaption>The problem :)</figcaption></figure><p>If we look at the timeline we can see that we spent a lot of time on configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rvixe-PGmV_tJ_8IbhLgbw.png" /><figcaption>Time allocation</figcaption></figure><p>Create React App makes our time more useful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-jWCamLji9RgfCd4cOrMLA.png" /><figcaption>Improved time allocation</figcaption></figure><h3>I ❤ Create React App</h3><h4>There are a lot of analogs… Why Create React App?</h4><p>It is a tool from React developers. It is like having one stack. I think that no one could develop tools for React applications, configure bundler, code transpiler, or test runner better than React Developers :)</p><h4>An Incredible Fast Developing Tool</h4><p>As the user of Create React App I am sure that I will receive all new stable features as fast as possible.</p><p>There are a lot of interesting feature requests and really huge flow of ideas from the community. The community is really large and growing.</p><p>There are also a lot of third-party tools for Create React App. For example <a href="https://github.com/rthor/cra-generate">CRA generate: Scaffold a React component</a>.</p><h4>Easy to use</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RkrZjS0UiQbBEgTOQ-AeHw.png" /></figure><p>Or use yarn</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HAQLV3PTO4V7ljyI0k5TJw.png" /></figure><p>When I heard first time about Create React App it seemed to me that the name was strange. For me It looked like <em>“Call to Action”. </em>I understood the idea when I found out about <a href="https://yarnpkg.com/lang/en/docs/cli/create/">yarn create</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QW6lAQUOrUtos9yWsPYf6w.png" /></figure><h3><strong>Features out of the box</strong></h3><p>This is short and not full list of features our of the box:</p><ul><li><a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md">Excellent documentation and community</a></li><li><a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build">Optimized production build</a></li><li><a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-development-environment-variables-in-env">Environment setup using .env files</a></li><li><a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#displaying-lint-output-in-the-editor">Linter — ESLint</a></li><li><a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#running-tests">Test runner Jest</a></li><li><a href="https://github.com/facebookincubator/create-react-app/pull/1101">Runtime error box</a></li><li><a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#supported-language-features-and-polyfills">Supports a superset of the latest JavaScript standard + polyfills</a></li><li><a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#offline-first-considerations">Offline-first caching strategy</a></li><li><a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#code-splitting">Code Splitting with Dynamic import</a></li><li>and so on</li></ul><h4>Updating development stack with a single line change</h4><p>It was the easiest way to migrate from webpack v1 to webpack v2. Without manual config patching :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QfISrmD4wprAi1d02qz-ow.png" /><figcaption>Updating development stack with a single line change.</figcaption></figure><p>Also I always advice to add <a href="https://www.npmjs.com/package/prettier"><strong>prettier</strong></a> + <a href="https://www.npmjs.com/package/lint-staged"><strong>lint-staged</strong></a> + <a href="http://husky/"><strong>husky</strong></a> to keep code always beautiful without manual style fixes and skip all cases when Continuous Integration fails because of there is no semicolon. To understand more about this stack watch <a href="https://www.youtube.com/watch?v=GLdH9SMG97o">“Make Linting Great Again”</a> by <a href="https://medium.com/u/5829a67c85f9">Andrey Okonetchnikov</a> at <a href="https://medium.com/u/fbee8513ba0d">React Amsterdam</a>.</p><h3>Create React App is not the boilerplate</h3><p>Create React App bootstraps an application. All <em>scripts</em> and <em>configs</em> are managed by <a href="https://www.npmjs.com/package/react-scripts">react-scripts</a> package. So just update react-scripts version to receive new updates and feature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oLCrVFkixxWuxNBobl0GFw.png" /><figcaption>before eject</figcaption></figure><p>Create React App is not the boilerplate until <a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-eject">eject</a>…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Lo2O02aMIJAmy-dfhpQFw.png" /><figcaption>npm run eject</figcaption></figure><blockquote>If you aren’t satisfied with the build tool and configuration choices, you can eject at any time. This command will remove the single build dependency from your project.</blockquote><blockquote>Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.</blockquote><p>I don’t suggest to eject application even if you need some custom feature. I’m convinced that 99% that is needed has already been implemented.</p><p>After ejection — you will not be able to receive updates. And this is a one-way operation. Once you eject, you can’t go back!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1hKViJsniv4YwKj9ERsb4w.png" /><figcaption>after eject</figcaption></figure><p>If there are not implemented features in Create React App like CSS Modules or decorators — for me it is better to sacrifice them in favor of receiving new react-scripts updates.</p><p>I don’t want to eject becasue:</p><ul><li>I want to receive Create React App updates</li><li>I don’t want to see a lot of the dependencies at my package.json that are not used directly from code</li><li>I always try to keep application as clean as possible. I don’t want to see extra configs and extra code that never changes.</li><li>After ejection we will still have problem with syncing configuration between applications.</li><li>Fixed development stack. Developers will use only <a href="https://tc39.github.io/process-document/">stage-3 </a>features (release candidates).</li></ul><h3>The result of using Create React App</h3><p>Before I wrote about tools we used, what should we do and how we try to improve DX. With Create React App this list becomes a much shorter. Because of Create React App we started to investigate CSS in JS solutions and now we are in love with them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WjlazyJ7Xtg8fGR8R2ZyAQ.png" /><figcaption>The result of using Create React App</figcaption></figure><h3>The End</h3><p>At the end I will not speak about Create React App. I want to speak about <a href="https://medium.com/@tuchk4/open-source-and-community-%EF%B8%8F-dbe412fd90a0">Open Source and Community</a> ❤️.</p><p>Open Source is a great thing that we have. Open Source projects Maintainers do a lot of hard work each day and I very much appreciate it. I want to say “Thanks!” to all the contributors who make the developer’s lives easier and saves time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BPj6yEiT_SJudampUGNjwQ.png" /><figcaption>Open Source community</figcaption></figure><p>If you need some features that are not implemented in the package <br>you use — don’t start to develop your own solutions. In many cases this is not justified. At first — try to suggest features to Maintainers via Github. The community always provides positive reaction on cool and useful suggestions. If not — you should think about it again. There is a big chance that you also would not need these features 😉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_JGOk3HoGusF72CZGRb7dQ.png" /><figcaption>Improve. Contribute. Suggest.</figcaption></figure><p>Always remember, as an OSS (Open Source Software) developer — <br>you will provide a lot of help to developers all over the world!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed2670b03cc3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rockey. Motivation and Requirements]]></title>
            <link>https://medium.com/@tuchk4/rockey-motivation-and-requirements-f787d1ed61e0?source=rss-79d461c2745a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f787d1ed61e0</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[css-in-js]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Valerii Sorokobatko]]></dc:creator>
            <pubDate>Fri, 02 Jun 2017 13:02:56 GMT</pubDate>
            <atom:updated>2017-09-30T17:44:01.620Z</atom:updated>
            <content:encoded><![CDATA[<p>At first I suggest to read these articles about CSS in JS approach and its advantages.</p><ul><li><a href="https://hackernoon.com/i-swore-never-to-use-css-in-js-here-are-6-reasons-why-i-was-wrong-541fe3dfdeb7">“I swore never to use CSS in JS, here are 6 reasons why I was wrong”</a> by <a href="https://medium.com/u/5711e47dae14">Tal Bereznitskey</a></li><li><a href="https://medium.com/seek-blog/a-unified-styling-language-d0c208de2660">“A Unified Styling Language”</a> by <a href="https://medium.com/u/d7225e72eea">Mark Dalgleish</a></li></ul><p>The story began when I started to use <a href="https://github.com/acdlite/recompose">recompose</a> by <a href="https://medium.com/u/6025bd347b9a">Andrew Clark</a> and decided that I want to compose CSS rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*qEusa1qgNLqZvAuAIj3qzw.png" /><figcaption>CSS in JS enhancers for recompose</figcaption></figure><p>And it should work according to this logic:</p><ul><li>Should create separated CSS class for each CSS enhancer. When change CSS class values via devtools — changes should be applied for all components that were composed with same enhancer.</li><li>Should not produce a lot of higher order components.</li><li>Should work fast! I ❤ Performance.</li></ul><p>Recompose helps us to re-use a lot of code and make features sharable between components. At our team we have universal React components library built with recompose and we can compose component with specific features for each application. This is good way to control bundle size.</p><p>If we need new feature for component — in most cases we will implement new enhancer instead of new higher order component. But the problem was that we didn’t know how to be with CSS code related for specific component enhancer. For example component <em>Button</em> has enhancer <em>raised() </em>that provide CSS rules that should be applied if flag <em>raised</em> exists in props.</p><p>It would be really ugly and not usable if each enhancer has it is own CSS file. At first the file structure would be large and with a lot of CSS with very minimum content.</p><p><em>“CSS in JS”</em> approach helps us.</p><blockquote>Sharing such components is zero dependency with no need to add a &lt;link&gt; tag to a css file.</blockquote><p>To implement <em>“CSS in JS”</em> enhancer for recompose I tried a lot of existing CSS in JS solutions to implement CSS enhancer for recompose. But none made me happy. With some libraries it is not possible. With some libraries there was worst performance. So to reach this feature I decided to develop prototype lib called <a href="https://github.com/tuchk4/rockey">rockey</a>.</p><blockquote>By the way! <strong>Rockey</strong> — is the name of my dog</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*t8wz9j72Xk_vSI5EcbhNRg.jpeg" /><figcaption>Hello! My name is Rockey! 🐶</figcaption></figure><p>It doesn’t matter for user and user experience if application was implemented with CSS in JS approach or not. But CSS in JS approach affects on Developer Experience and as the result — developers will ship new releases more faster and new features will be easier to implement.</p><p>There is list of requirements and features that should mostly improve DX (at least from my point of view).</p><blockquote>Now <a href="https://github.com/tuchk4/rockey">rockey</a> has it own CSS parser (<a href="https://github.com/tuchk4/rockey/tree/master/packages/rockey-css-parse">rockey-css-parse</a> and <a href="https://tuchk4.github.io/rockey-css-parse-repl/">REPL</a>) and Stylesheet class to work with styles in runtime. But maybe in nearest release I will swap them with existing solution (maybe). For example with <a href="https://github.com/cssinjs/jss">JSS</a> by <a href="https://medium.com/u/7c635fc6907">Oleg Slobodskoi</a> or <a href="https://github.com/threepointone/glamor">glamor</a> by <a href="https://medium.com/u/e970465f2c1e">Sunil Pai</a>. It depends if it possible to implement all requirements and performance numbers.</blockquote><p>Requirements list (Table of Contents):</p><ul><li>I would like to use Template Literals to write CSS in JS</li><li>I would like to influence on components generated class name</li><li>I would like to use fast and small library</li><li>I would like to write dynamic CSS</li><li>Should be no problems with CSS order</li><li>I would like to work correct extending</li><li>I would like to split component into different looks</li><li>I want to use Component Based selectors</li><li>I want to work with readable Class Names</li><li>Should work fast without babel or prepack</li><li>Experimental feature — Dynamic CSS based on component events</li></ul><h3>CSS in JS library requirements</h3><p>Without explanation:</p><ul><li>Supports Server Side Rendering</li><li>Supports <strong>*</strong>Native (at least React Native)</li><li>Should be compatible with <a href="https://github.com/styled-components/polished">polished</a> by <a href="https://medium.com/u/908fb8fea30c">Max Stoiber</a>.</li></ul><h4>I would like to use Template Literals to write CSS in JS</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*LCLhn6nq82w5KOkTa6b4bg.png" /></figure><ul><li>Much faster to write code. No needs to write quotes, comas and use camelCase if write CSS as JSON.</li><li>Much more used way.</li><li>Possible to copy-paste code from CSS files or snippets from <a href="https://medium.com/u/d53dd768d047">Stack Overflow</a> or other sites :)</li></ul><h4>I would like to influence on components generated class name</h4><p>At least for development environment. Sometimes it is hard to work in devtools when all CSS classes has fully generated names.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*ADvQerazuuXIZ-munjZN_g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*P_NmjPfqxqfhMWv4zCkL3g.png" /><figcaption>Right example if more readable</figcaption></figure><h4>I would like to use fast and small library</h4><p>Small library is better then large library if the provided features are the same.</p><p>Fast library is better then slow library. It performance is more priority then size.</p><p>There is React application with different CSS in JS approaches: <a href="https://tuchk4.github.io/css-in-js-app/#/">https://tuchk4.github.io/css-in-js-app</a>/</p><p>It is not the real benchmark but it shows the differents between CSS in JS libraries and approaches under the same conditions. The accent was made on dynamic CSS that depends on component props.</p><h4>I would like to write dynamic CSS</h4><p>For example it is very easy to implement grid system. Just write one JS functions instead of tons of CSS rules like <em>col-1, col-2, col-6 </em>and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*yMlY_PZNeV3YizUvkIf2Zw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*Iji1ZQkQWGxW3os7ocIOrg.png" /><figcaption>Instead of tons of CSS class names — write one JS function</figcaption></figure><blockquote>It is possible to implement CSS grid system with SaSS functions that will generate all needed CSS classes but I am JS developer and I don’t know how to do it with SaSS.</blockquote><p>There are a lot useful cases for such dynamic CSS:</p><ul><li>access application theme</li><li>access components props</li><li>defined styles if <em>value</em> is not empty for form elements</li><li>access any env variable like view port size, window width, current url and so on.</li></ul><h4>Should be no problems with CSS order</h4><p>Because CSS rules are injected into the DOM as soon as component is rendered there could be problems with CSS rules order.</p><h4>I would like to work correct extending</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*cPyGZIGNTR9PksJpQ4p36g.png" /></figure><p>I would like SupperButton component to be rendered with 3 classes — <em>Button-{{ hash }}</em>, <em>PrimaryButton-{{ hash }} </em>and <em>SuperButton-{{ hash }}</em>. This will make comfortable work in devtools — if change CSS values for parent components<em> —</em> it will also affect on all child components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ffo1QHsZtTd7FxfVcd8-tQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Og-IhSDnAb8IZxAFH_fhlg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*cOu2wXkCq6_m6RPQSkNtsA.gif" /></figure><h4>I would like to split component into different looks</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*qZnsNgpU8l_72p6_lMgXNA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*F7qhPLZzNKV0gc1p1Ru0lg.png" /></figure><p>Why I would like to have this feature?</p><p>At first because this is awesome and improve DX when developing components.</p><p>At second — easy way to implement feature without higher order component. Most component features could be implemented as additional component property or as Higher Order Component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*1fTxpzgkEO-xwdfpUsGB4A.png" /><figcaption>Which way?</figcaption></figure><p>There is the approach that helps to make more correct decision what approach use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I3NtriJYie9ILtMAoiLCSg.png" /></figure><ul><li><em>ripple</em> — could be used in any state. So it should be used as prop.</li><li><em>disabled</em> — could be used in any state. So it should be used as prop.</li><li><em>success</em> — could NOT* be used along with <em>warning</em> and <em>primary</em>. So it should be implemented as Higher Order Component.</li><li>and so on.</li></ul><p>If there is no ❌ — feature should be implemented as <em>prop</em>. If there is a least one ❌ — feature should be implemented as Higher Order Component.</p><p>Feature “Split component into different looks” helps us a lot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Vc5Ato_XtnL_HndsInj64g.png" /></figure><p>And note that dynamic CSS rule for <em>disabled </em>and <em>raised </em>props at Button component should work for PrimaryButton and SuccessButton.</p><h4>I want to use Component Based selectors</h4><p>Main goal — keep code as clean as possible.</p><p>According to beast practice — keep all components name uniq or anonymous. So if component has uniq name — it is good point to use such name at CSS code.</p><ul><li>I don’t want to write complex logic to choose correct classnames according to current props and mix it with components logic.</li><li>I don’t want to set <em>className</em> prop for each component manually.</li><li>I want to write structure of components and pass only props that affects on components logic behaviour (event handlers, values, data, flags and so on).</li><li>I want to use real components names for CSS rules instead of classes. Means that if I have component &lt;Card/&gt; — I want to use its name as CSS selector. If I have component &lt;PrimaryCard/&gt; — I want to use its name as CSS selector.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*x0tp6Zp4fedMcWmpqQm2Og.png" /><figcaption>Component Bases selectors for CSS</figcaption></figure><h4>I want to work with readable Class Names</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aOrnGaErGtRF5ZCq22bFeg.png" /></figure><h4>Should work fast without babel or prepack</h4><p>I love babel and prepack. But I don’t install and setup additional plugins for library. I just want to keep “getting started” step as simple as possible.</p><p>And actually <a href="https://medium.com/@valeriy.sorokobatko/why-i-love-create-react-app-e63b1be689a3">I love Create React App</a> and don’t want to eject :) So it is not possible (at for now) to use custom babel plugin.</p><p>Babel plugins (or prepack) improve performance only for static CSS rules. But dynamic CSS (when CSS code depends on component props) improve DX mostly and plugins will not work for this case.</p><h4>Experimental feature — Dynamic CSS based on component events</h4><p>Write dynamic CSS that triggers along with events handlers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*i384PVdmARuTc1Bc3Z89kQ.png" /></figure><p>Examples:</p><ul><li><a href="https://www.webpackbin.com/bins/-Ki22k9ewZ6gh3Rw87d-">Input styles for specific value</a></li><li><a href="https://www.webpackbin.com/bins/-Ki1G10UY-sXlden2XSS">Div background depends on mouse X and Y</a></li></ul><h3>CSS or Inline styles?</h3><p>Its enough to use <a href="https://github.com/acdlite/recompose/blob/master/docs/API.md#mapprops">mapProps</a> and <a href="https://github.com/acdlite/recompose/blob/master/docs/API.md#withprops">withProps</a> to make enhancers that provides additional styles. But I don’t want to use inline styles as main approach for styling. <a href="https://medium.com/u/7c635fc6907">Oleg Slobodskoi</a> wrote at <a href="https://medium.com/@oleg008/high-performance-dynamic-styles-db28c873940">“High Performance Dynamic Styles”</a> and I completely agree.</p><blockquote>Inline Styles have a number of limitations by design:</blockquote><blockquote>1. You can’t share an inline style declaration between multiple elements.<br>2. You need to apply them directly to a specific element.</blockquote><p>Also it is not comfortable to work with inline styles — not possible to change styles for all same type elements and <em>Elements</em> panel at devtools is not readable. And it is not cool to write inline styles for <em>:hover, :active, ::before </em>and other pesudo classes.</p><h3>Awesome CSS in JS</h3><p>Meet awesome CSS in JS — <a href="https://github.com/tuchk4/awesome-css-in-js">tuchk4/awesome-css-in-js</a></p><p>Feel free to suggest awesome link and other information.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f787d1ed61e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS in JS. Rockey.]]></title>
            <link>https://medium.com/@tuchk4/css-in-js-rockey-890ebbbd16e7?source=rss-79d461c2745a------2</link>
            <guid isPermaLink="false">https://medium.com/p/890ebbbd16e7</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[css-in-js]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[styling]]></category>
            <dc:creator><![CDATA[Valerii Sorokobatko]]></dc:creator>
            <pubDate>Thu, 20 Apr 2017 12:26:03 GMT</pubDate>
            <atom:updated>2017-04-21T09:41:41.145Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LXxnTgObmM1esFuvt4CQ8Q.png" /></figure><h4>To cut long story short:</h4><ul><li>Flexible CSS in JS approach</li><li>Repository — <a href="https://github.com/tuchk4/rockey">https://github.com/tuchk4/rockey</a></li><li>React application with implemented different CSS in JS ways <a href="https://tuchk4.github.io/css-in-js-app/#/">https://tuchk4.github.io/css-in-js-app/</a></li></ul><p>Examples:</p><ul><li><a href="https://www.webpackbin.com/bins/-KfkcTYPzpyglHKfmuKh">Card example</a></li><li><a href="https://www.webpackbin.com/bins/-Ki-AMdS7Q0bzkSyZ81f">Warning Card example</a></li><li><a href="https://www.webpackbin.com/bins/-Ki4mYd1WoxNaYl5pH1I">Buttons looks</a></li><li><a href="https://www.webpackbin.com/bins/-Ki22k9ewZ6gh3Rw87d-">Input styles for specific value</a></li><li><a href="https://www.webpackbin.com/bins/-Ki1G10UY-sXlden2XSS">Div background depends on mouse X and Y</a></li></ul><h3>Why do we need CSS in JS?</h3><p>Every developer with whom I told about CSS in JS asked me — why should we do this stuff if it is possible to use usual CSS / Less / Sass?</p><p>CSS in JS approach — is native JS. You don’t need additional tools to use or build it.</p><p>Also I’m tired of large <a href="https://www.npmjs.com/package/classnames"><em>classnames</em></a><em> </em>conditions. Just write dynamic CSS rules (that depends on component props) and keep only business logic code inside component.</p><h4>1. For Components Libraries</h4><p><strong>Or when going to share components between applications</strong>.</p><p>With CSS in JS approach it is more simpler to build components bundle. Just transpile code with babel and that is all.</p><p>Including component to the application immediately includes code and styles. And there is no extra CSS code — each component define only its own styles.</p><p>Means that if you need to include only Button — just import button component and its already defined with styles.</p><p>No needs to include additional CSS files.</p><h4>2. More Simpler Application Configuration</h4><p>This is not a problem to configure bundler but for now this is became very boring. Each time, each application with same configuration. Each time, each application — update all dependencies and configuration if new major release.</p><p>CSS in JS approach available for all bundlers, for each architecture because there is zero configuration. And I am very happy to is this with <a href="https://github.com/facebookincubator/create-react-app">Create React App</a>.</p><h4>3. There is No Custom Loaders</h4><p>I was happy and delighted when started to use webpack and discovered the power of loaders. Such WOW to JS capabilities. I always told with our backend developers and said something like — “Yo! Look and your hulking backend technologies! Using JS you can write in CoffeeScript, TypeScript and JS at one application, require CSS or Less files and then bundle all these modules together!” Such WOW I though. How could I be wrong…</p><p>CSS in JS approach — is native JS.</p><p>As I wrote at <a href="https://medium.com/@tuchk4/why-i-love-create-react-app-e63b1be689a3">“Why I Love Create React App”</a>:</p><blockquote>Always remember that using not usual loaders (like yaml, markdown, dsv loaders etc.), additional plugins and features from drafts and proposals makes your application more complex, maybe with dead syntax features and it is become impossible to migrate from current webpack configuration.</blockquote><blockquote>That is the reason I even do not like webpack CSS loaders. I always try to require only <strong>js</strong> or <strong>json</strong> modules. From my point of view — CSS files are OK only at webpack entry point configuration but not for require.</blockquote><h4>4. More Cleaner File Structure</h4><p>There is no extra CSS / Less / Sass files. All styles inside JS file.</p><p>During last few years I followed experience that each component should have JS and CSS files located at one directory. This approach provide application to be very clear but problems comes when there are a lot of components of you want to share components between applications.</p><h4>5. Easier to Run Tests</h4><p>Don’t need to setup context, mocks or require hooks to load CSS / Less / Sass files.</p><h3>Rockey and Integration with React</h3><p>Api documentation: <a href="https://github.com/tuchk4/rockey/">tuchk4/rockey</a></p><p>Stressless styles for components using JS. Write CSS with functional mixins according to the component structure using components names.</p><h4>Framework Agnostic</h4><p>Rockey could be used in any application.</p><p><a href="https://github.com/tuchk4/rockey/tree/master/packages/rockey">Full Api documentation</a></p><pre>import rockey from &#39;rockey&#39;;<br><br>const rule = rockey`<br>  Button {<br>    color: black;<br><br>    ${rockey.when(props =&gt; props.primary)`<br>      color: blue;<br>    `}<br><br>    Icon {<br>      margin: 5px;<br>    }<br>  }<br>`;<br><br>const classList = rule.getClassList({<br>  primary: true<br>});<br><br>const className = classList.Button;</pre><h4>Small Size</h4><ul><li>rockey — 7kb gzip</li><li>rockey-react — 10kb gzip</li></ul><h4>Uniq Class Names</h4><p>Each time generate uniq class names with randomly generated hash. Same as <a href="https://github.com/css-modules/css-modules">css-modules</a>.</p><h4>Component based selectors</h4><p>Write CSS according your components structure. Use real components names for CSS rules instead of classes.</p><p>Means that if you have component <em>Card — </em>use its name as CSS selector. If you have component <em>PrimaryCard — </em>use its name as CSS selector. Use nested selectors according to components structure.</p><p>Demo: <a href="https://www.webpackbin.com/bins/-KfkcTYPzpyglHKfmuKh">Card and PrimaryCard</a></p><pre>import rockey from &#39;rockey-react&#39;;<br>import look from &#39;rockey-react/look&#39;;</pre><pre>const CardHeader = rockey.div(&#39;CardHeader&#39;)`<br>  font-size: 18px;<br>  font-weight: bold;<br>  padding: 5px;<br>`;</pre><pre>const CardBody = rockey.div(&#39;CardBody&#39;)`<br>  padding: 5px;<br>`;</pre><pre>const { Card, PrimaryCard } = look.div`<br>  Card {<br>    margin: 5px;<br>    border: 1px solid #ccc;<br>    border-radius: 3px;<br>    box-shadow: 1px 1px 3px #ccc;<br>    font-family: &#39;Roboto&#39;, sans-serif;<br>    width: 200px;<br>  }</pre><pre>  PrimaryCard {<br>    CardHeader {<br>      background: rgba(0, 0, 255, .1);<br>      color: #3399ff;<br>    }<br>  }<br>`;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*-Gayu5B-rksOyuBxAjWyVA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*1BHnQcI5eNaTaEe-ME8nNg.png" /><figcaption>Card and PrimaryCard</figcaption></figure><h4>Readable CSS Class Names</h4><p>Each generated classname is clear and readable. The same components renders with same class names. It is very useful and сompatible with browser dev tools — change styles for one component will always apply changes for the rest of the same components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q0qkkBt0xYt0LXjBy-2fzg.png" /></figure><h4>~100% CSS Syntax</h4><p>There is no needs to import specific function to render <em>@media</em>, <em>keyframes</em>, <em>font-faces</em> or pseudo classes like <em>:hover</em> or <em>::after</em>. Support nested and multiple selectors.</p><p>Demo with complex selectors: <a href="https://www.webpackbin.com/bins/-Ki-KJQAQOJEmTECJUoE">Material TextField</a></p><h4>Fast. And Will be More Faster!</h4><p>Rendering CSS string, generating CSS rules and inserting them into DOM is really fast. There is example React application with implemented different approaches: fela / jss / glamor / styled-components / rockey.</p><blockquote>I was really inspired by <a href="https://github.com/styled-components/styled-components">styled-components</a> and want to say great thanks to <a href="https://medium.com/u/908fb8fea30c">Max Stoiber</a>.</blockquote><ul><li>Live: <a href="https://tuchk4.github.io/css-in-js-app/">tuchk4.github.io/css-in-js-app</a></li><li>Github repo: <a href="https://github.com/tuchk4/css-in-js-app">github.com/tuchk4/css-in-js-app</a></li></ul><p>Benchmarks from parsing 10000 generated CSS classes:</p><pre>npm run best-results -- --size 10000</pre><ul><li>Rockey Parse Optimized — 3.325sec</li><li>Rockey Parse — 3.841sec</li><li><a href="https://github.com/postcss/postcss">Postcss</a> with <a href="https://github.com/postcss/postcss-nested">Nested Plugin</a> — 14.204sec</li><li><a href="https://github.com/postcss/postcss-safe-parser">Postcss Safe Parser</a> with <a href="https://github.com/postcss/postcss-nested">Nested Plugin</a> — 16.404sec</li></ul><blockquote>Note that <strong>rockey</strong> and <strong>postcss</strong> were developed for different tasks. Rockey parser configured for specific syntax and will never be able to replace <strong>postcss</strong></blockquote><h4>Class Names</h4><p>rockey uses separated CSS classes for each rule and for each mixin. That is why it is very сompatible with devtools. When change CSS values of parent component via devtools — it will be applied for all children.</p><pre>import rockey from &#39;rockey-react&#39;;</pre><pre>const Button = rockey.button(‘Button’)`<br>  color: black;</pre><pre>${rockey.when(‘LargeButton’, props =&gt; props.large)`<br>    font-size: 20px;<br>  `}<br>`;</pre><pre>const PrimaryButton = Button(&#39;PrimaryButton&#39;)`<br>  color: blue;<br>`;</pre><pre>const SuperButton = PrimaryButton(&#39;SuperButton&#39;)`<br>  color: red;<br>`;</pre><p>Inserted CSS (after component is rendered):</p><pre>.Button-{{ hash }} {<br>  color: black;<br>}</pre><pre>.PrimaryButton-{{ hash }} {<br>  color: blue;<br>}</pre><pre>.SuperButton-{{ hash }} {<br>  color: red;<br>}</pre><pre>.Mixin-LargeButton-{{ hash }}.Button-{{ hash }} {<br>  font-size: 20px;<br>}</pre><p>And for &lt;PrimaryButton large={true}/&gt; <em>className</em> prop will equal .PrimaryButton-{{ hash }} .Button-{{ hash }} .Mixin-LargeButton-{{ hash}} .</p><p>That is why it is very сompatible with devtools. When change CSS values of parent component via devtools — it will be applied for all children.</p><p>If prop <em>large</em> is changed to <em>false</em> — only mixin class will be removed instead of all styles re-calculating. This is another reason why rockey is fast.</p><p>Demos:</p><ul><li><a href="https://www.webpackbin.com/bins/-KflMmHbcVU01PD6h43F">Buttons example</a></li><li><a href="https://www.webpackbin.com/bins/-Ki-Jk6OoMnFSFshKib6">Anonymous Buttons example</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*cOu2wXkCq6_m6RPQSkNtsA.gif" /></figure><h4>Dynamic CSS</h4><p>Demos:</p><ul><li><a href="https://www.webpackbin.com/bins/-Ki-AMdS7Q0bzkSyZ81f">Warning Card example</a></li><li><a href="https://www.webpackbin.com/bins/-KflpZuJTEet-ECpPpWE">Primary and Raised Blocks</a></li></ul><pre>import React from &#39;react&#39;;<br>import rockey from &#39;rockey-react&#39;;<br>import look from &#39;rockey-react/look&#39;;</pre><pre>const CardHeader = rockey.div(&#39;CardHeader&#39;)`<br>  font-size: 18px;<br>  font-weight: bold;<br>  padding: 5px;<br>`;</pre><pre>const CardBody = rockey.div(&#39;CardBody&#39;)`<br>  padding: 5px;<br>`;</pre><pre>const { Card, PrimaryCard } = look.div`<br>  Card {<br>    margin: 5px;<br>    border: 1px solid #ccc;<br>    border-radius: 3px;<br>    box-shadow: 1px 1px 3px #ccc;<br>    font-family: &#39;Roboto&#39;, sans-serif;<br>    width: 200px;</pre><pre>   ${rockey.when(props =&gt; props.warning)`  <br>      CardBody {<br>        background: rgba(255, 0, 0, .7);<br>        color: white;<br>      }<br>    `}<br>  }</pre><pre>  PrimaryCard {<br>    CardHeader {<br>      background: rgba(0, 0, 255, .1);<br>      color: #3399ff;<br>      <br>      ${rockey.when(props =&gt; props.warning)` <br>         background: rgba(255, 0, 0, .9);<br>         color: white;<br>      `}<br>    }<br>  }<br>`;</pre><pre>  CardHeader {<br>    background: rgba(0, 0, 255, .1);<br>    color: #3399ff;<br>      <br>    ${rockey.when(props =&gt; props.warning)` <br>       background: rgba(255, 0, 0, .9);<br>       color: white;<br>    `}<br>   }<br> }<br>`;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*5PfywTFLpR2_XOj5YvVvAw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*pARBMtLApbvwvv-lhcBT4A.png" /><figcaption>Card and PrimaryCard with warning flag</figcaption></figure><h3>Rockey React Features</h3><h4>Flexible Rockey Higher Order Component</h4><pre>import rockey from &#39;rockey-react&#39;;</pre><pre>const Component = rockey(BaseComponent)`<br>  color: green;<br>`;</pre><p>Now <em>Component </em>could used as React component:</p><pre>&lt;Component/&gt;</pre><p>Or extend it and create anonymous child component with additional styles:</p><pre>const Child = Component`<br>  text-decoration: underline; <br>`;</pre><p>By default <em>rockey-react</em> try to use <em>BaseComponent.displayName </em>to generate classname. But sometimes it is more useful to set name manually.</p><pre>const Child = Component(&#39;MySuperChild&#39;)`<br>  text-decoration: underline; <br>`;</pre><p>And same usage for <em>Child</em> component.</p><p>There will be generated two CSS classes for <em>Child:</em></p><p><em>Child </em>component className will be composed of class with its own CSS rules and all parents class names.</p><h4>Shortcuts</h4><p>Available all valid html tags. Create anonymus component from shortcuts:</p><pre>import rockey from &#39;rockey-react&#39;;</pre><pre>const Block = rockey.div`<br>  padding: 5px;<br>  border: 1px solid #000;<br>`;</pre><p>Create named component from shortcuts:</p><pre>import rockey from &#39;rockey-react&#39;;</pre><pre>const Block = rockey.div(&#39;Block&#39;)`<br>  padding: 5px;<br>  border: 1px solid #000;<br>`;</pre><h4>Dynamic CSS — props</h4><pre>import when from &#39;rockey/when&#39;;</pre><p>Write CSS that depends on components props.</p><pre>const Button = rockey.div`<br>   color: black;</pre><pre>   ${props =&gt; props.primary &amp;&amp; `<br>     color: green;<br>   `}<br>`;</pre><p>Or use helper <em>when</em>:</p><pre>const Button = rockey.div`<br>  background: white;</pre><pre>  ${rockey.when(props =&gt; props.primary)`<br>     color: blue;<br>     background: green;<br>  `}<br>`;</pre><p>For more happy development process it is possible to set mixin name:</p><pre>rockey.when(&#39;isPrimary`, props =&gt; props.primary)`<br>  color: blue;<br>`;</pre><h4>Dynamic CSS — Event Handlers</h4><pre>import handler from &#39;rockey-react/handler&#39;;</pre><p>Write CSS mixins that are triggered along with events handlers.</p><p>Demos:</p><ul><li><a href="https://www.webpackbin.com/bins/-Ki22k9ewZ6gh3Rw87d-">Input styles for specific value</a></li><li><a href="https://www.webpackbin.com/bins/-Ki1G10UY-sXlden2XSS">Div background depends on mouse X and Y</a></li></ul><pre>const Input = rockey.input`<br>  font-size: 25px;<br>  border: none;<br>  border-bottom: 2px solid #000;<br>  padding: 0 0 5px 0;<br>  outline: none;<br>  font-family: monospace;</pre><pre>  ${rockey.handler(&#39;onChange&#39;, e =&gt; e.target.value === &#39;rockey&#39;)`<br>    color: green;<br>  `}<br>`;</pre><h3>Component Looks</h3><pre>import look from &#39;rockey-react/look&#39;;</pre><p>Split component into different looks.</p><pre>const { Button, SuccessButton, WarningButton } = look(BaseButton)`<br>  Button {<br>    font-size: 15px;<br>  }<br>  <br>  SuccessButton {<br>    color: green;<br>  }</pre><pre>  WarningButton { <br>    color: red;<br>  }<br>`;</pre><p>First component will set as parent. All next looks will extends first look. All shortcuts also available at look function. For example — look.button.</p><p>Demo: <a href="https://www.webpackbin.com/bins/-KiAH9iRbz0xh5uErz-6">Buttons looks</a></p><pre>import look from &#39;rockey-react/look&#39;;</pre><pre>const { Button, PrimaryButton, SuccessButton } = look.button`<br>  Button {<br>    padding: 5px;<br>    background: none;<br>  }</pre><pre>  PrimaryButton {<br>    color: blue;<br>  }</pre><pre>  SuccessButton {<br>    color: green;<br>  }<br>`;</pre><p>This is the same as:</p><p>Demo:</p><ul><li><a href="https://www.webpackbin.com/bins/-Ki0oy6hS3vdQZluouKZ">Anonymous Buttons Extending</a></li><li><a href="https://www.webpackbin.com/bins/-Ki4zp8QqriEj4VSKgvg">Named Buttons Extending</a></li></ul><blockquote>Difference in these demos only in generated CSS class names</blockquote><pre>const Button = rockey.button`<br>  padding: 5px;<br>  background: none;<br>`;</pre><pre>const PrimryButton = Button`<br>  color: blue;<br>`;</pre><pre>const SuccessButton = Button`<br>  color: green;<br>`;</pre><p>And:</p><p>Demo: <a href="https://www.webpackbin.com/bins/-Ki4mYd1WoxNaYl5pH1I">Buttons static look method</a></p><pre>const Button = rockey.button`<br>  padding: 5px;<br>  background: none;<br>`;</pre><pre>const { PrimaryButton, SuccessButton } = Button.look`<br>  PrimaryButton {<br>    color: blue;<br>  }</pre><pre>  SuccessButton {<br>    color: green;<br>  }<br>`;</pre><pre><br>&lt;PrimaryButton /&gt;<br>// or<br>&lt;Button.PrimaryButton /&gt;</pre><h4>Component Feature Table</h4><p>Most component features could be implemented as component’s prop or as Higher Order Component.</p><pre>&lt;Button primary={true}/&gt;Yo!&lt;/Button&gt;</pre><p>or</p><pre>&lt;PrimaryButton&gt;Yo!&lt;/PrimaryButton&gt;</pre><p>Correct way — depends on you and on your team :) Just use what you like best. But if you use &lt;PrimaryButton/&gt;<em> </em>I will ask: <em>“So same for disabled button? Use </em><em>&lt;DisabledButton/&gt; Higher Order Component? Huh?”.</em> Last one looks really ugly.</p><p>Example with Button component is really simple. In real application there are a lot of much more complex situations and to make more correct decision 0-I use such tables:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BoUtTMBiyK0mvR5NOXrEZA.png" /><figcaption>Component feature table</figcaption></figure><ul><li><em>ripple</em> — could be used in any state. So it should be used as</li><li><em>disabled</em> — could be used in any state. So it should be used as prop.</li><li><em>success</em> — could not be used along with <em>warning</em> and <em>primary</em>. So it should be implemented as Higher Order Component.</li></ul><p>If there is no ❌ — feature should be implemented as props.</p><p>If there is a least one ❌ — feature should be implemented as component.</p><p>According to this table we get these components:</p><pre>&lt;Button disabled ripple raised&gt;<br>   I&#39;m Button<br>&lt;/Button&gt;</pre><pre>&lt;SuccessButton disabled ripple raised&gt;<br>  I&#39;m Button<br>&lt;/SuccessButton&gt;</pre><pre>&lt;WarningButton disabled ripple raised&gt;<br>  I&#39;m Button<br>&lt;/WarningButton&gt;</pre><pre>&lt;PrimaryButton disabled ripple raised&gt;<br>  I&#39;m Button<br>&lt;/PrimaryButton&gt;</pre><p>And rockey look feature helps with this.</p><p>Demo: <a href="https://www.webpackbin.com/bins/-Ki2_Te-1y_OiIbQB5bO">Look: raised Button / PrimaryButton / SuccessButton</a></p><pre>const Button = rockey.button(&#39;Button&#39;)`<br>  font-size: 20px;<br>  padding: 5px;<br>  margin: 5px;<br>  background: white;<br>  border: 1px solid #ccc;</pre><pre>  ${rockey.when(&#39;raised&#39;, props =&gt; props.raised)`<br>    box-shadow: 5px 5px 5px rgba(0, 0, 0, .3);<br>  `}<br>`;</pre><pre>const { PrimaryButton, SuccessButton } = Button.look`<br>  PrimaryButton {<br>    color: blue;<br>  }</pre><pre>  SuccessButton {<br>    color: green;<br>  }<br>`;</pre><p>To keep <em>imports</em> and <em>exports </em>cleaner — all looks available as static attribute at parent component:</p><pre>&lt;PrimaryButton&gt;I&#39;am primary button&lt;/PrimaryButton&gt;<br>// same as<br>&lt;Button.PrimaryButton&gt;I&#39;am primary button&lt;/Button.PrimaryButton&gt;</pre><p>Recompose shortcut</p><p>Currently we use recompose in each React application. Recompose helps to write less code and share features between components. This shortcut helps to save time and code when using rockey + recompose.</p><p>Great thanks to <a href="https://medium.com/u/6025bd347b9a">Andrew Clark</a> for <a href="https://github.com/acdlite/recompose">recompose</a>!</p><pre>import rockempose from &#39;rockey-react/recompose&#39;;<br>import withProps from &#39;recompose/withProps&#39;;</pre><pre>const Line = rockempose.span(<br>  withProps(props =&gt; ({ <br>    long: props.value &amp;&amp; props.value.length &gt; 140 <br>  })<br>)`<br>  font-size: 15px;</pre><pre>  ${when(props =&gt; props.long)` <br>    font-size: 10px;<br>  `}<br>`;</pre><h3>Experimental plans</h3><h4>Render Cache with Service Workers</h4><p>If you had not use or even read about Service Workers — watch this great talk by <a href="https://medium.com/u/f87cd234b9d9">Jake Archibald</a> <a href="https://www.youtube.com/watch?v=cmGr0RszHc8">“Instant Loading: Building offline-first Progressive Web Apps”</a> at Google I/O 2016.</p><p>Idea is to cache rendered CSS rules at Service Worker after application was initialized. After page reload — rockey will insert CSS link:</p><pre>&lt;link rel=&quot;stylesheet&quot; href=&quot;/rockey.css?v1&quot; /&gt;</pre><p>And Service Worker will catch this request and return cached styles.</p><p>Why Service Worker? Why not LocalStorage or IndexedDB? Because when rockey will support Server Side Rendering — CSS files could be generated at server and then just applied at client.</p><p>One of the main point is that developers should not think about how this works. This should work out of the box and could be disabled if needed.</p><h4>Rockey Browser Extension</h4><p>This is the shortest features list that could be added to the extension:</p><ul><li>Change theme values without page reload</li><li>Number of created and used components</li><li>Number of undefined refs</li><li>Number of undefined refs and unused animations</li><li>Number of inserted CSS rules</li><li>Manipulate with Service Worker cache</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*HDrn-RvQtsDMtO3GjhRGsQ.png" /></figure><h3>Conclusion</h3><p>I can not put all what I want to talk about CSS in JS and rockey in one article.</p><p>This is a very new approach and library and not all features are implemented yet. Feel free to <a href="https://github.com/tuchk4/rockey/issues/new">file issue or suggest feature</a> to help me to make rockey better.</p><p>Upcoming plans:</p><ul><li>Make disadvantages list as shorter as possible</li><li>Medium post <em>“Rockey Under the Hood”</em>. Topic about how rockey works — how to make batch CSS rules insert, how to parse and auto optimize parser, how dynamic CSS works.</li><li>Medium post <em>“Rockey — tips and tricks”. </em>There are too lot of tips and tricks that I want to share with you.</li><li><em>“Components kit”</em> — library with easiest way to develop React components using <a href="https://github.com/tuchk4/rockey">rockey</a> and <a href="https://github.com/acdlite/recompose">recompose</a>.</li></ul><h3>All used examples</h3><ul><li><a href="https://www.webpackbin.com/bins/-KfkcTYPzpyglHKfmuKh">Card example</a></li><li><a href="https://www.webpackbin.com/bins/-Ki-AMdS7Q0bzkSyZ81f">Warning Card example</a></li><li><a href="https://www.webpackbin.com/bins/-KflpZuJTEet-ECpPpWE">Primary and Raised Blocks</a></li><li><a href="https://www.webpackbin.com/bins/-KflMmHbcVU01PD6h43F">Buttons example</a></li><li><a href="https://www.webpackbin.com/bins/-Ki-Jk6OoMnFSFshKib6">Anonymous Buttons example</a></li><li><a href="https://www.webpackbin.com/bins/-Ki4mYd1WoxNaYl5pH1I">Buttons look</a></li><li><a href="https://www.webpackbin.com/bins/-Ki2_Te-1y_OiIbQB5bO">Button / PrimaryButton / SuccessButton with raised mixin</a></li><li><a href="https://www.webpackbin.com/bins/-Ki0oy6hS3vdQZluouKZ">Anonymous Extending: raised Button / PrimaryButton / SuccessButton</a></li><li><a href="https://www.webpackbin.com/bins/-Ki-KJQAQOJEmTECJUoE">Material TextField</a></li><li><a href="https://www.webpackbin.com/bins/-Ki22k9ewZ6gh3Rw87d-">Input styles for specific value</a></li><li><a href="https://www.webpackbin.com/bins/-Ki1G10UY-sXlden2XSS">Div background depends on mouse X and Y</a></li><li><a href="https://www.webpackbin.com/bins/-KflkDbSVrccxSkAAFZq">Animated divs</a></li><li><a href="https://www.webpackbin.com/bins/-Kflsy2FIkQy4n27qeLc">Themed Buttons</a></li><li><a href="https://www.webpackbin.com/bins/-KiAH9iRbz0xh5uErz-6">look shortcuts</a></li><li><a href="https://www.webpackbin.com/bins/-Ki0oy6hS3vdQZluouKZ">Anonymous Buttons Extending</a></li><li><a href="https://www.webpackbin.com/bins/-Ki4zp8QqriEj4VSKgvg">Named Buttons Extending</a></li><li><a href="https://www.webpackbin.com/bins/-Ki4mYd1WoxNaYl5pH1I">Buttons static look method</a></li><li><a href="https://www.webpackbin.com/bins/-Ki2_Te-1y_OiIbQB5bO">Look: raised Button / PrimaryButton / SuccessButton</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*MLBT3C57Emb0G9R6CFSFrA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*9k4n1SVAlvTqcYu1EawKtw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*YeapgSbKpsuUwXeMSHZOtA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=890ebbbd16e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I love Create React App]]></title>
            <link>https://medium.com/@tuchk4/why-i-love-create-react-app-e63b1be689a3?source=rss-79d461c2745a------2</link>
            <guid isPermaLink="false">https://medium.com/p/e63b1be689a3</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[create-react-app]]></category>
            <dc:creator><![CDATA[Valerii Sorokobatko]]></dc:creator>
            <pubDate>Tue, 24 Jan 2017 00:46:15 GMT</pubDate>
            <atom:updated>2017-01-24T01:22:28.731Z</atom:updated>
            <content:encoded><![CDATA[<p>Create React App is a great React app starter and runner.</p><ul><li><a href="https://github.com/facebookincubator/create-react-app">Create React App GitHub</a></li><li><a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md">Create React App User Guide</a></li><li><a href="https://github.com/tuchk4/awesome-create-react-app">Awesome Create React App</a>. Feel free to file issue or suggest articles, videos and other useful resources via Pull Requests.</li></ul><p>Before Create React App I always copy-paste <strong>webpack</strong> <strong>config</strong> and other <strong>*rc</strong> files from previous applications to each new application or even playground.</p><p>Create React App provides simple cli command to create application with the initial project structure, install dependencies and configure <em>package.json</em> scripts (run / build / test).</p><pre>npm install -g create-react-app<br><br>create-react-app my-app<br>cd my-app/<br>npm start # yarn start</pre><p>And there are no configuration. Developers can’t configure webpack, babel presets until <a href="https://github.com/facebookincubator/create-react-app#converting-to-a-custom-setup">ejection</a>.</p><blockquote>If you’re a power user and you aren’t happy with the default configuration, you can “eject” from the tool and use it as a boilerplate generator.</blockquote><blockquote>Running npm run eject copies all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. Commands like npm start and npm run build will still work, but they will point to the copied scripts so you can tweak them. At this point, you’re on your own.</blockquote><h3>Why I don’t want to eject my application</h3><p>This is a one-way operation. Once you eject, you can’t go back! And I never run eject at my application because:</p><h4>I want to receive create-react-app updates</h4><p>For example Create React App team decided to switch to <a href="https://webpack.js.org/guides/migrating/">webpack 2</a> to support tree-shaking and a lot of other awesome features. It will be possible by just updated create-react-app version instead of updating my webpack configs.</p><p>Or Create React App team will release the <a href="https://github.com/facebookincubator/create-react-app/issues/670">Plugin System</a> feature. I will be glad to use it and even create my own plugins. But if I had already ejected application — I will have to migrate back to Create React App.</p><h4>I don’t want to see a lot of the dependencies at my package.json</h4><p>Maybe this is not a problem but it is annoying me when I see all the <em>babel*, eslint* </em>and <em>webpack*</em> dependencies at package.json.</p><h4>Extra configs and extra code</h4><p>I always try to keep application as clean as possible. After ejection there are additional <em>scripts </em>and<em> config </em>directory . So after ejection there are ~10 new files with 50–200 lines of code at each file and in most cases only ~5 lines will be changed to add unsupported out of the box feature.</p><h4>Back to the roots</h4><p>After ejection and editing the configs I should copy-paste them to other applications because in most cases application’s configs (webpack loaders and plugins, babel presets) are the same.</p><h3>I love Create React App because</h3><h4>Tool from React developers</h4><p>No one can develop tool and configure bundler, code transpiler and test runner better then React developers :)</p><h4>There are no configuration and no extra files at my app structure</h4><p>As I wrote before — I always try to keep my application clean. So I am glad NOT to see webpack.config, scripts directory and additional dependencies at my package.json :)</p><h4>Updating development stack with a single line change</h4><h3>Dan Abramov on Twitter</h3><p>Feels nice to get three months&#39; worth of bugfixes and improvements to build tooling with a single line change.</p><h4>Fixed development stack</h4><p>Means that developers will use only <a href="https://tc39.github.io/process-document/">stage-3 </a>features (release candidates). Possible result of using draft features is:</p><h3>Dan Abramov on Twitter</h3><p>@tuchk4 Imagine the horror of building / maintaining an app that relies on dead syntax features five years from now.</p><h4>Incredible fast developing tool</h4><p>As the user of Create React App I am sure that I will receive all new stable features as fast as possible.</p><p>Also there are lot of interested feature requests from maintainers and community. For example:</p><ul><li><a href="https://github.com/facebookincubator/create-react-app/issues/670">Plugin System</a></li><li><a href="https://github.com/facebookincubator/create-react-app/pull/1101">Runtime overlay</a></li><li><a href="https://github.com/facebookincubator/create-react-app/issues/645">A global CLI for running a single component</a>.</li><li><a href="https://github.com/facebookincubator/create-react-app/issues/215">Proposal: ‘configurator’ field in package.json</a></li><li><a href="https://github.com/facebookincubator/create-react-app/issues/1343">Support different env configs</a></li><li>and so on. and so on.</li></ul><p>Some of them are already closed or released but I just want to show that there is a huge flow of ideas. There are even third-party tools for Create React App ecosystem like <a href="https://github.com/rthor/cra-generate">CRA generate: Scaffold a React component</a>.</p><h3>My experience using Create React App</h3><p>Because of Create React App we stopped to use <a href="https://github.com/css-modules/css-modules">CSS Modules</a>, <a href="http://react-toolbox.com/#/">React Toolbox</a> and some libs that should be at webpack externals.</p><blockquote>By the way — <a href="https://github.com/react-toolbox/react-toolbox-themr">react-toolbox-themr</a> providing an easy integration with Create React App</blockquote><p>And I still don’t want to eject!</p><p>Instead of CSS Modules I started to use <a href="https://github.com/threepointone/glamor">glamor</a> or <a href="https://github.com/Khan/aphrodite">aphrodite</a>. There is the similar tool — <a href="https://github.com/FormidableLabs/radium">Radium</a>, but I don’t want to use <em>style </em>attribute for component styling.</p><h4>Loading from the global folders</h4><p>I can’t work with code that require modules from parent directories:</p><pre>const dateUtils = require(&#39;../../../utils/date&#39;);</pre><p>Usually with webpack this is resolved by <a href="https://webpack.github.io/docs/configuration.html#resolve-modulesdirectories">resolve.modulesDirectories</a> configuration. As we already know — there is no webpack configuration at Create React App application but there there two solutions.</p><p>Official solution: create node_modules at src directory - <a href="https://github.com/facebookincubator/create-react-app/issues/1065">src/node_modules as official solution for absolute imports #1065</a>.</p><p>Another way — use NODE_PATH env variable. It is a directory name to be resolved to the current directory as well as its ancestors, and searched for modules. More details at node official documentation <a href="https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders">&quot;Loading from the global folders&quot;</a>.</p><p>Use <a href="https://github.com/kentcdodds/cross-env">cross-env</a> to set environment variables across platforms.</p><pre>&quot;scripts&quot;: {<br>  &quot;start&quot;: &quot;cross-env NODE_PATH=src/scripts react-scripts start&quot;<br>}</pre><p>Or if you use .env config - just add NODE_PATH variable:</p><pre>NODE_PATH=src/scripts</pre><h4>Environment configs</h4><p>Create React App support <em>.env </em>out of the box (via <a href="https://github.com/motdotla/dotenv">dotenv</a>). So just create <em>.env</em> at the root and run application. Make sure to add <em>REACT_APP_ </em>prefix to each variable. More info at official documentation — <a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables">Adding Custom Environment Variables</a> and <a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-development-environment-variables-in-env">Adding Development Environment Variables In </a><a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-development-environment-variables-in-env">.env</a></p><h4>Multiple environment configs</h4><p>Sometimes it is very useful to split configs by environments (api entry points, services keys and so on). For example my <em>dev.env</em>:</p><pre>REACT_APP_GOOGLE_CLIENT_ID = XXX-YYY-ZZZ.apps.googleusercontent.com<br>REACT_APP_API_PROTOCOL = http:<br>REACT_APP_API_HOST = localhost:3000</pre><pre>NODE_PATH = src/scripts<br>PORT = 9001</pre><p>And my <em>prod.env</em>:</p><pre>REACT_APP_GOOGLE_CLIENT_ID = ZZZ-YYY-XXX.apps.googleusercontent.com<br>REACT_APP_API_PROTOCOL = https:<br>REACT_APP_API_HOST = api.my-applicaton.com</pre><pre>NODE_PATH = src/scripts</pre><p>Right now it is possible by installing <a href="https://github.com/motdotla/dotenv">dotenv</a> and updating npm scripts:</p><pre>&quot;scripts&quot;: {<br>  &quot;start&quot;: &quot;node -r dotenv/config ./node_modules/.bin/react-scripts start dotenv_config_path=dev.env&quot;,<br>  &quot;build&quot;: &quot;node -r dotenv/config ./node_modules/.bin/react-scripts build dotenv_config_path=prod.env&quot;<br>}</pre><p>Also there is the Create React App feature request with implemented Pull Request — <a href="https://github.com/facebookincubator/create-react-app/issues/1343">Support different env configs</a>.</p><blockquote>Read different .env configs according to current command (start / test / build). dev.env for start and test. prod.env for build. If custom config does not exist — read env variables from <em>.env</em> file.</blockquote><p>So if you like this feature — provide feedback at <a href="https://github.com/facebookincubator/create-react-app/issues/1343">Issue thread</a>.</p><h4>Change the dev server port</h4><p>I can’t run application at 3000 port because we use Google Auth and few years ago it was configured for development at localhost:9001–9005 ports.</p><p>Add PORT env variable. Use <a href="https://github.com/kentcdodds/cross-env">cross-env</a> to set environment variables across platforms.</p><pre>&quot;scripts&quot;: {<br>  &quot;start&quot;: &quot;cross-env PORT=9001 react-scripts start&quot;<br>}</pre><p>If you use .env config - just add PORT variable:</p><pre>PORT=9001</pre><h4>Change webpack config — add plugins and change entry point</h4><p>I have two situation when I have to do this:</p><ol><li>Add <a href="https://github.com/NekR/offline-plugin">Webpack Offline Plugin</a>.</li><li>Publish single component as the separated build. (Seems related to <a href="https://github.com/facebookincubator/create-react-app/issues/796">How to publish components without ejecting #796</a>)</li></ol><p>At the first view seems that this is not possible without ejection. But there is the workaround. Anyway I don’t suggest to use this often. I am pretty sure that a lot of features are reachable with default Create React App configuration.</p><p>Always remember that using not usual loaders (like yaml, markdown, dsv loaders etc.), additional plugins and features from drafts and proposals makes your application more complex, maybe with dead syntax features and it is become impossible to migrate from current webpack configuration.</p><blockquote>That is the reason I even do not like webpack css-loaders. I always try to require only js or json modules. From my point of view — css files are OK only at webpack entry point configuration but not for require function.</blockquote><p>Add <em>build:custom</em> to <em>npm-scripts</em>:</p><pre>&quot;scripts&quot;: {<br>  &quot;build:custom&quot;: &quot;node scripts/webpack&quot;<br>}</pre><p>And then create <em>scripts/webpack.js</em>:</p><pre>const webpack = require(&#39;react-scripts/node_modules/webpack&#39;);<br>const craWebpackConfig = require(&#39;react-scripts/config/webpack.config.prod&#39;);<br>const OfflinePlugin = require(&#39;offline-plugin&#39;);<br><br>const config = {<br>  ...craWebpackConfig,<br>  plugins: [<br>     ...craWebpackConfig.plugins,<br>     new OfflinePlugin()<br>  ],<br>  entry: [<br>    craWebpackConfig.entry[0], // pollyfils<br>    path.resolve(&#39;src&#39;, &#39;awesome-component.js&#39;)<br>  ],<br>  output: {<br>    ...craWebpackConfig.output,<br>    path: path.resolve(&#39;pf-build&#39;)<br>  }<br>};</pre><pre>webpack(config).run(function(err, stats) {<br>  if (err !== null) {<br>    console.log(&#39;done&#39;);<br>  } else {<br>    console.log(err);<br>  }<br>});</pre><blockquote>There is just webpack config extending, not react-scripts build. There are no beautiful console logs, comparison of the build sizes and other react-scripts build command features.</blockquote><p>There is Create React App feature request — <a href="https://github.com/facebookincubator/create-react-app/issues/1434">Feature request: export scripts (start/test/build) as functions</a> that may help to use beautiful or more correct solution.</p><h4>Custom babel presets and plugins</h4><p>Create React App <a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#can-i-use-decorators">doesn’t support decorator syntax</a> at the moment.</p><p>There are PR <a href="https://github.com/facebookincubator/create-react-app/pull/1357">Adding support for custom babel configuration #1357</a>. If PR is merged then these features will be available:</p><ul><li><a href="https://www.npmjs.com/package/babel-plugin-transform-decorators">Decorators</a></li><li>Features from <a href="https://babeljs.io/docs/plugins/preset-stage-0/">stage-0 preset</a></li><li>Any new babel features and presets</li></ul><p>By default — no custom <em>babelrc</em>. Create it only if needed. But always remember… few paragraphs above.</p><h3>Dan Abramov on Twitter</h3><p>@tuchk4 I&#39;m happy to add decorators after they&#39;ve moved to stage 3</p><h3>Dan Abramov on Twitter</h3><p>@tuchk4 Bind proposal hasn&#39;t been updated in a long time and doesn&#39;t appear to progress. Might not make it at all either.</p><h3>Dan Abramov on Twitter</h3><p>@tuchk4 Imagine the horror of building / maintaining an app that relies on dead syntax features five years from now.</p><p>Despite the fact that I’m the author of Pull Request — I agree with <a href="https://medium.com/u/a3a8af6addc1">Dan Abramov</a>.</p><h3>The end</h3><p><a href="https://github.com/tuchk4/awesome-create-react-app">Awesome Create React App</a> — A collection of awesome things regarding Create React App ecosystem. Feel free to file issue or suggest articles, videos and other useful resources via Pull Requests.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e63b1be689a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Forgekit]]></title>
            <link>https://medium.com/@tuchk4/forgekit-785eb17a9b50?source=rss-79d461c2745a------2</link>
            <guid isPermaLink="false">https://medium.com/p/785eb17a9b50</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Valerii Sorokobatko]]></dc:creator>
            <pubDate>Wed, 07 Dec 2016 14:38:15 GMT</pubDate>
            <atom:updated>2016-12-07T14:38:15.582Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oEQNgJzRs5wF_1ByEt1wYQ.png" /></figure><p>Easier way to develop and manage component’s features and inject them into the components.</p><h4>Motivation</h4><p><a href="https://github.com/acdlite/recompose">recompose</a> had a great influence. It is great library that provide excellent way to lift state into functional wrappers, perform the most common React patterns, optimize rendering performance. Also it is possible to store common functions separately and share them between components. And as the result — component’s source code become much more easier and readable.</p><blockquote>recompose — React utility belt for function components and higher-order components. Think of it like lodash for React.</blockquote><h3>Little theory. What is component feature?</h3><blockquote>Wiki: It is an intentional distinguishing characteristic of a component.</blockquote><p>Component feature — is the new component functionality. And in most cases it provide and depends on new props. For example <em>HighliteFlags</em> feature for &lt;Button/&gt; component - add <em>success</em>, <em>alert</em> and <em>warning</em> bool props and depending on them provide specific styles.</p><h4>The problem</h4><p>Usually all such features are developed and stored inside component and this is the reason for next problems:</p><ul><li>Component code become more and more complex. Even simple component can grow into complex with large collection of available props.</li><li>Hard to develop new features and remove old or not used. To remove feature developer should find and remove large number of lines and then make sure that all other features work correctly.</li><li>Hard to find bugs and fix them. Sometimes there are hotfixes that usually push component to become legacy.</li><li>A lot of <em>copy-paste</em> code. Especially a lot of duplication across components <em>propTypes</em>.</li><li>Hard to share code. Only whole component could be shared with all implemented features. But sometimes needs to share only specific feature between components or even between applications.</li></ul><h4>Component life in images</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*ga4cEEHke1FRZHSfIWFAmQ.png" /><figcaption>1. Birth of the component</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*gwD7g9ZkVGXukCnqomVp2w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*Udq2hQ7t9-KqRsoSLwTSlQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*7dp4t-i1VtIAavRqVLkH3w.png" /><figcaption>2, 3, 4 Component development</figcaption></figure><ol><li>Component is simple and it code is beautiful, simple and readable..</li><li>Developing new component features. Developing at this stage is like breathe the crystal clear air. Component is still virgin.</li><li>Component became complex and its code is much harder and uglier than was before.</li><li>DEATH — bugs, legacy code, spaghetti :( Components look like virus or infection.</li></ol><h4>Solution: develop features separately</h4><p><a href="https://github.com/tuchk4/forgekit">Forgekit</a> suggest to develop and store features separately from components. There are a lot of advantages:</p><ul><li><strong>Responsibility</strong>. Each feature stored at separated file (or module if speak in CommonJS context) and there is code that implements only specific functionality and provide its own <em>propsTypes</em>.</li><li><strong>Sharable</strong>. Features could be shared between components or applications. And don’t even depends on components library. It could work above it.</li><li><strong>Tests</strong>. Easy to write tests because Feature is a pure function.</li><li><strong>Refactoring</strong>. It is more simpler to remove feature import than find and remove large number of related lines of code.</li><li><strong>Refactoring</strong>. Old feature could be swapped with new features.</li><li><strong>Optimization</strong>. Use only needed features. Not used features will not be in the build.</li><li><strong>Feature customization</strong>. Each feature could be customized separately. This is much better than customize whole component.</li></ul><h4>High-level and low-level props</h4><p>In most cases feature depends and provide new props. Props could be split into low-level and high-level props.</p><p>From React <a href="https://facebook.github.io/react/docs/dom-elements.html">DOM Elements</a> documentation:</p><blockquote>React implements a browser-independent DOM system for performance and cross-browser compatibility. We took the opportunity to clean up a few rough edges in browser DOM implementations. In React, all DOM properties and attributes (including event handlers) should be camelCased. For example, the HTML attribute tabindex corresponds to the attribute tabIndex in React. The exception is aria-* and data-* attributes, which should be lowercased.</blockquote><p>So all DOM attributes and <em>children</em> prop are<strong> low-level </strong>props. <strong>High-level</strong> props — are custom props.</p><p>In all cases high-level props always affects on low-level props. That is why most features could be implemented by mapping props before <em>render</em>. And it is better than create higher order component for each feature (this way affects on performance) or develop all features inside component (this way makes code more complex).</p><p>It is looks like props middlewares (or like props micro services). It does not create higher order components for all features — only one hoc for all features. So it does not affect on performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*abdCBwVRDV3H9zYIFjsB4w.png" /></figure><h3>Forgekit feature function</h3><p>Forgekit feature is a pure functions that:</p><ul><li>provide <em>propTypes</em> and <em>defaultProps</em></li><li>takes props as argument and returns new props</li><li>provide its own theme structure (<a href="https://github.com/tuchk4/forgekit/blob/master/docs/theme.md">more about themes</a>)</li></ul><pre>Feature = function(props): newProps<br>Feature.propTypes = {}<br>Feature.defaultProps = {}</pre><h3>Forgekit feature with lifecycle methods</h3><p>Forgekit feature also could be defined as object with two attributes:</p><ul><li><em>props</em> — pure function to map props.</li><li><em>hoc</em> — higher order component. Takes Component as argument and return higher order component.</li></ul><pre>Feature = {<br>  props: function(props): newProps,<br>  hoc: function(<br>          Component: React.Component<br>       ): React.Component<br>}</pre><pre>Feature.propTypes = {}<br>Feature.defaultProps = {}</pre><h3>Forgekit and Recompose</h3><p>As the developer of the Forgekit I am not happy to develop one more library (one more <a href="http://npmjs.com/package/forgekit">npm package</a>). At least because most forgekit features could be implemented with:</p><ul><li><a href="https://github.com/acdlite/recompose/blob/master/docs/API.md#mapprops">recompose/mapProps</a></li><li><a href="https://github.com/acdlite/recompose/blob/master/docs/API.md#withprops">recompose/withProps</a></li><li><a href="https://github.com/acdlite/recompose/blob/master/docs/API.md#setdisplayname">recompose/setDisplayName</a></li><li><a href="https://github.com/acdlite/recompose/blob/master/docs/API.md#lifecycle">recompose/lifecycle</a></li></ul><h3>Forgekit and Recompose differences</h3><p>More information at <a href="https://github.com/tuchk4/forgekit/blob/master/docs/forgekit-and-recompose.md">Github repository: Forgekit and Recompose</a></p><h4>1. Forgekit features provide its own propTypes and defaultProps</h4><p>Forgekit suggest to develop and store features separately from components. Forgekit feature is a pure functions that:</p><ul><li>provide <em>propTypes</em> and <em>defaultProps</em></li><li>takes props as argument and returns new props</li><li>provide its own theme structure (<a href="https://github.com/tuchk4/forgekit/blob/master/docs/theme.md">more about themes</a>)</li></ul><p>There are a lot of advantages:</p><ul><li>Responsibility. Each feature stored at separated file (or module if speak in CommonJS context) and there is code that implements only specific functionality and provide its own <em>propsTypes</em>.</li><li>Sharable. Features could be shared between components or applications. And don’t even depends on components library. It could work above it.</li><li>Refactoring. It is more simpler to remove feature import than find and remove large number of related lines of code.</li><li>Refactoring. Old feature can be swapped with new features. So <em>propTypes</em> and <em>defaultProps</em> also will be swapped.</li></ul><p>More details at <a href="https://github.com/tuchk4/forgekit/blob/master/docs/feature.md">features api documentation</a>;</p><h4>2. Forgekit merge propTypes and defaultProps</h4><p>This is important. And this is the critical difference for our development flow. We use<a href="https://github.com/storybooks/react-storybook"> React storybook </a>with <a href="https://github.com/storybooks/react-storybook-addon-info">storybook info addon</a> so it is important to collect all available <em>propTypes</em> and show them in the docs.</p><p>But anyway propTypes merging can be implemented with higher order function for <em>recompose</em>.</p><h4>3. Forgekit provide tools for component and feature theming</h4><p>Allows to define theme structure for feature or component. It is used for <em>classNames</em> or <em>style</em> calculating. Support custom themes provided by global CSS or inline styles and other libraries. More information at <a href="https://github.com/tuchk4/forgekit/blob/master/docs/theme.md">Forgkit theme documentation</a>.</p><h4>4. Display name</h4><p>From my point of view — Forgekit provides more readable <em>displayName</em>. Display name is useful for generating error messages and for <a href="https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en">React chrome developers tools</a>.</p><p>Forgekit:</p><pre>&lt;MaterialButton&gt; ...</pre><p>Recompose:</p><pre>&lt;mapProps(mapProps(MaterialButton))&gt; ...</pre><h3>Forgekit advantages</h3><h3>Share common features between components</h3><p>There are features that does not relate to certain component. They could be added into any component.</p><ul><li><em>ClickOutside</em> — Fires when click outside of the component</li><li><em>HighliteFlags</em> — Depends on prop <em>primary</em> / <em>alert</em> / <em>danger</em> / <em>warning</em> — add styles to the component</li><li><em>LoaderOverlay</em> — If <em>loading</em> prop is true — show loader overlay above the component</li></ul><pre>import forgekit from &#39;forgekit&#39;;<br><br>import Button from &#39;components/button&#39;;<br>import Layout from &#39;components/layout&#39;;<br><br>import clickOutside from &#39;features/click-outside&#39;;<br>import highliteFlags from &#39;features/highlite-flags&#39;;<br>import loaderOverlay from &#39;features/loader-overlay&#39;;<br><br><br>export const AppButton = forgekit(<br>  clickOutside, <br>  highliteFlags)(Button);</pre><pre>export const AppLayout = forgekit(<br>  clickOutside, <br>  loaderOverlay)(Layout);</pre><p>There is one common feature — <em>clickOutside</em>.</p><p>Forged components &lt;AppButton/&gt; and &lt;AppLayout/&gt; accepts <em>onClickOutside</em> prop. But <em>onClickOutsided</em> is not duplicated at &lt;Button/&gt; and &lt;Layout/&gt; <em>propTypes</em>. It is automatically added with <em>clickOutside</em> feature.</p><h3>Use only needed features</h3><p>Look at any open source components library — each component has a lot of features and there are a lot of <em>propTypes</em>. For example component &lt;Button/&gt; has features:</p><ul><li><em>ripple</em> — If true, component will have a ripple effect on click.</li><li><em>icon</em> — Value of the icon (See Font Icon Component).</li><li><em>flat</em> — If true, the button will have a flat look.</li><li><em>raised</em> — If true, the button will have a flat look.</li><li><em>onMouseLeave</em> — Fires after the mouse leaves the Component.</li><li><em>inverse</em> — If true, the neutral colors are inverted. Useful to put a button over a dark background.</li></ul><p>A lot of more. With Forgekit it is not possible to use only <em>icon</em> feature. All features implementations will be included to application build.</p><h3>Easier to refactor and support clean code</h3><p>All needed features could be imported from separated modules. This is very helpful when you want to share your component features with another team, another application or just push them to Github and make them open source. Also this provide good way to keep your code cleaner: just create new module and develop new functionality instead of patching existing modules. And same with refactoring — just remove imports if need to clean some old or unused features. This is much easier than remove large number of lines from components code and then make sure that all other features work correctly.</p><ul><li>Easy to remove features — just remove feature import. Instead of removing number of lines from the component.</li><li>Easy to write and understand code — feature is a simple function</li><li>Code responsibility. Each feature — separated module and there is no extra code. Only feature implementation. Very boost code reading and understanding.</li></ul><h3>Feature customization</h3><p>Each feature could be customized. Very similar with Redux middleware customization.</p><pre>import fogekit from &#39;forgekit&#39;;<br><br>import icon from &#39;features/icon&#39;;<br>import highliteFlags from &#39;features/highlite-flags&#39;;<br><br>const Button = (children, ...props) =&gt; &lt;button {...props}&gt;{children}&lt;/button&gt;;<br><br>const customHighliting = highliteFlags({<br>  alert: {<br>    color: &#39;white&#39;,<br>    fontWeight: &#39;bold&#39;<br>    background: &#39;red&#39;<br>  }<br>});<br><br>export default forge(icon, customHighliting)(Button);</pre><h3>Sharing features in open source</h3><p>If there is any open source component’s library that was built with Forgekit — it is simple to contribute because developers does not need to understand its whole structure and work with all library. Just develop feature function with tests and push it. Or even push to own repository.</p><h3>Suggested environment for component development</h3><ul><li>Use <a href="https://github.com/tuchk4/forgekit">Forgekit</a> or <a href="https://github.com/acdlite/recompose">Recompose</a>. Especially for base components.</li><li>User <a href="https://getstorybook.io/">React storybook</a> for documentation.</li><li>Write <em>README.md</em> for each component</li><li>Use Storybook <a href="https://github.com/storybooks/storybook-addon-knobs">knobs addon</a></li><li>Use Storybook <a href="https://github.com/storybooks/react-storybook-addon-info">info addon</a>. Because Forgekit merge features <em>propTypes</em> it work correctly with this addon.</li><li>Use Storybook <a href="https://github.com/tuchk4/storybook-readme">readme addon</a></li><li>Dont forget about <a href="https://en.wikipedia.org/wiki/Feature_creep">Creeping featurism</a> anti-pattern that can ruin your components. With Forgekit it is much more easier to manage comopnents features.</li></ul><h3>Forgekit components library</h3><p>I will contribute to <a href="https://github.com/tuchk4/forgekit-components">Forgekit components library</a>:</p><ul><li>Develop all base components and features for them</li><li>Add styles according to Google Material design</li><li>Components should be easily stylized to any other design without extra styles at application build</li></ul><h3>Nearest plans</h3><p>Create Forgekit <a href="https://github.com/storybooks/react-storybook">react storybook</a> plugin. Main goal — manage <a href="https://github.com/tuchk4/forgekit/blob/master/docs/feature.md">features</a> and <a href="https://github.com/tuchk4/forgekit/blob/master/docs/theme.md">themes</a></p><ul><li>Show used features</li><li>Show available features</li><li>Show component and features documentation</li><li>Components Theme customizations</li></ul><h3>Feedback wanted</h3><p>Forgekit is still in the early stages and even still be an experimental project. Your are welcome to submit issue or PR if you have suggestions! Or write me on twitter <a href="https://twitter.com/tuchk4">@tuchk4</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=785eb17a9b50" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>