<?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[BucharestJS - Medium]]></title>
        <description><![CDATA[BucharestJS is a developer group for anyone interested in Javascript. All skill levels are welcome. You can find us on Meetup.com/BucharestJS, Facebook.com/Groups/BucharestJS and Twitter.com/BucharestJS. - Medium]]></description>
        <link>https://medium.com/bucharestjs?source=rss----985a14b72308---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>BucharestJS - Medium</title>
            <link>https://medium.com/bucharestjs?source=rss----985a14b72308---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 06:26:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/bucharestjs" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Adding state management with Redux in a CRA + SSR project]]></title>
            <link>https://medium.com/bucharestjs/adding-state-management-with-redux-in-a-cra-srr-project-9798d74dbb3b?source=rss----985a14b72308---4</link>
            <guid isPermaLink="false">https://medium.com/p/9798d74dbb3b</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[server-side-rendering]]></category>
            <dc:creator><![CDATA[Andrei Duca]]></dc:creator>
            <pubDate>Sun, 28 Jan 2018 11:37:26 GMT</pubDate>
            <atom:updated>2018-03-01T08:02:34.788Z</atom:updated>
            <content:encoded><![CDATA[<h4>Or how to initialize your Redux store on the server, then pick it up and hydrate it on the client.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8yz3hkO3ynHV2qYGARynJg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/b18TRXc8UPQ?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Artem Sapegin</a> on <a href="https://unsplash.com/search/photos/react-code?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><em>This is part 2 of my </em><strong><em>CRA+SSR</em></strong><em> series:</em></p><ol><li><a href="https://medium.com/bucharestjs/upgrading-a-create-react-app-project-to-a-ssr-code-splitting-setup-9da57df2040a">Upgrading a create-react-app project to SSR + code splitting</a></li><li>Adding state management with Redux in a CRA + SSR project</li></ol><p>I personally like Redux because it uses a single object to represent the entire state of the application. This single object is also composable, so you can split its management into smaller, independent bits. I also find it useful to have a one-way data flow, so when I click a button in one place, I trigger a chain of events, ending with the update of the UI based on the new state, maybe even in another place of the app, without having to pass props and execute callbacks all around.</p><p><em>If you’re not too familiar with Redux and how it works, I suggest you read </em><a href="https://medium.com/@gyeon/redux-vs-flux-a31a02faccf3"><em>this quick article</em></a><em> for a birds-eye view, or </em><a href="https://code-cartoons.com/a-cartoon-intro-to-redux-3afb775501a6"><em>go into much more detail and even find how it’s different than other libraries</em></a><em>.</em></p><p>What we’ll cover in this article:</p><ol><li>Adding Redux on the client</li><li>Adding Redux on the server</li><li>Rehydrating the client store from the server</li></ol><h4>First: Client side</h4><p>Let’s install Redux and its helpers:</p><pre>yarn add redux react-redux redux-thunk</pre><p>We need to create a reducer in <strong>/src/store/appReducer.js</strong>, aka a pure function taking two arguments (the previous state, and an action/modifier object) and returning the new state as an immutable object.</p><pre>const initialState = {<br>    message: null,<br>};</pre><pre>export const appReducer = (state = initialState, action) =&gt; {<br>    switch(action.type) {<br>        case &#39;SET_MESSAGE&#39;:<br>            return {<br>                ...state,<br>                message: action.message,<br>            };<br>        default:<br>            return state;<br>    }<br>};</pre><p><em>We’re destructuring the state object here to keep the old properties unchanged, and only replace what we need. In our case, this is not necessarily needed, as we only have the </em><strong><em>message</em></strong><em> property, but in a larger application this is what you typically do.</em></p><p>Let’s also write an <strong>action creator</strong>, that is a function that returns an action object. I usually like to keep things together, so we’ll add this in our reducer file. But feel free to create a separate file if you want to group things differently.</p><pre>export const setMessage = messageText =&gt; ({ type: &#39;SET_MESSAGE&#39;, message: messageText });</pre><p>Now we’ll create our store initializer in <strong>/src/store/configureStore.js</strong>.</p><pre>import {<br>    createStore,<br>    combineReducers,<br>    compose,<br>    applyMiddleware,<br>} from &#39;redux&#39;;</pre><pre>import ReduxThunk from &#39;redux-thunk&#39;</pre><pre>import { appReducer } from &#39;./appReducer&#39;;</pre><pre>// if you&#39;re using redux-thunk or other middlewares, add them here<br>const createStoreWithMiddleware = compose(applyMiddleware(<br>    ReduxThunk,<br>))(createStore);</pre><pre>const rootReducer = combineReducers({<br>    app: appReducer,<br>});</pre><pre><strong>export default function configureStore(initialState = {}) {<br>    return createStoreWithMiddleware(rootReducer, initialState);<br>};</strong></pre><p>We’re wrapping our <strong>createStore</strong> in a function so we can pass the initial state when initializing. This will help us when hydrating the state from the server.</p><p>Now let’s use it in our app. Wrap the main App component in a Redux provider in <strong>/src/index.js</strong>:</p><pre>import React from &#39;react&#39;;<br>import ReactDOM from &#39;react-dom&#39;;<br>import Loadable from &#39;react-loadable&#39;;<br><strong>import { Provider as ReduxProvider } from &#39;react-redux&#39;</strong></pre><pre>import App from &#39;./App&#39;;<br><strong>import configureStore from &#39;./store/configureStore&#39;;</strong></pre><pre><strong>const store = configureStore();</strong></pre><pre>const AppBundle = (<br>    <strong>&lt;ReduxProvider store={store}&gt;</strong><br>        &lt;App /&gt;<br><strong>    &lt;/ReduxProvider&gt;</strong><br>);</pre><pre>window.onload = () =&gt; {<br>    Loadable.preloadReady().then(() =&gt; {<br>        ReactDOM.hydrate(<br>            <strong>AppBundle,</strong><br>            document.getElementById(&#39;root&#39;)<br>        );<br>    });<br>};</pre><p>Next, we’ll display the message in our App. We’ll also set a default message on the client if the initial value is empty.</p><pre><strong>import { connect } from &#39;react-redux&#39;;<br>import { setMessage } from &#39;./store/appReducer&#39;;</strong></pre><pre>class App extends Component {<br>    <strong>componentDidMount() {<br>        if(!this.props.message) {<br>            this.props.updateMessage(&quot;Hi, I&#39;m from client!&quot;);<br>        }<br>    }</strong></pre><pre>    render() {<br>        return (<br>            &lt;div className=&quot;App&quot;&gt;<br>                // ...<br>                <strong>&lt;p&gt;<br>                    Redux: { this.props.message }<br>                &lt;/p&gt;</strong><br>            &lt;/div&gt;<br>        );<br>    }<br>}</pre><pre><strong>export default connect(<br>    ({ app }) =&gt; ({<br>        message: app.message,<br>    }),<br>    dispatch =&gt; ({<br>        updateMessage: (txt) =&gt; dispatch(setMessage(txt)),<br>    })<br>)(App);</strong></pre><p>That’s it! Now run the app with <strong>yarn start</strong> and see the “Hi, I’m from client!” message displayed after the app loads.</p><h4>Next: Server side</h4><p><a href="https://medium.com/bucharestjs/upgrading-a-create-react-app-project-to-a-ssr-code-splitting-setup-9da57df2040a">Remember our <strong>serverRenderer</strong> middleware which renders our app to a string?</a> Let’s modify that a little bit. We’ll wrap it in another function, so we can pass the store from outsite. We’ll also wrap our main App component in a Redux provider, just like on the client.</p><pre>export default <strong>(store) =&gt; </strong>(req, res, next) =&gt; {<br>    // ...<br>    const html = ReactDOMServer.renderToString(<br>        <strong>&lt;ReduxProvider store={store}&gt;</strong><br>            &lt;App /&gt;<br>        <strong>&lt;/ReduxProvider&gt;</strong><br>    );<br>    // ...<br>}</pre><p>Now we need to initialize our store and pass it as a prop when using the renderer middleware in our router (in <strong>/server/index.js</strong>):</p><pre>import serverRenderer from &#39;./middleware/renderer&#39;;<br><strong>import configureStore from &#39;../src/store/configureStore&#39;;</strong></pre><pre><strong>//...</strong></pre><pre><strong>const store = configureStore();</strong><br>router.use(&#39;^/$&#39;, <strong>serverRenderer(store)</strong>);</pre><pre>// ...</pre><p>In a real application, you will want to move this code in a controller, so you decouple the logic of the app from the initialization of the express server. Also, you’ll want some controller actions that hold more complex logic, maybe even based on the request url. In fact, let’s do this now. We’ll move the code for the router initialization and we’ll write an index action that handles the Redux store initialization in <strong>/server/controllers/index.js</strong>:</p><pre>import express from &quot;express&quot;;<br><br>import serverRenderer from &#39;../middleware/renderer&#39;;<br>import configureStore from &#39;../../src/store/configureStore&#39;;<br><br>const router = express.Router();<br>const path = require(&quot;path&quot;);<br><br><br><strong>const actionIndex = (req, res, next) =&gt; {<br>    const store = configureStore();<br>    serverRenderer(store)(req, res, next);<br>};<br><br></strong><br>// root (/) should always serve our server rendered page<br><strong>router.use(&#39;^/$&#39;, actionIndex);</strong><br><br>// other static resources should just be served as they are<br>router.use(express.static(<br>    path.resolve(__dirname, &#39;..&#39;, &#39;..&#39;, &#39;build&#39;),<br>    { maxAge: &#39;30d&#39; },<br>));<br><br><strong>export default router;</strong></pre><p><em>As we moved the code in a subdirectory, please make sure that in the route for static files you add an extra </em><strong><em>‘..’</em></strong><em>, so </em><strong><em>path.resolve()</em></strong><em> will point to the right location.</em></p><p>Our action is just another middleware that will call the <strong>serverRenderer</strong> middleware after the Redux store has been initialized. We can even dispatch an action before calling the renderer.</p><pre><strong>import { setMessage } from &#39;../../src/store/appReducer&#39;;</strong></pre><pre>// ...</pre><pre>const actionIndex = (req, res, next) =&gt; {<br>    const store = configureStore();<br>    <strong>store.dispatch(setMessage(&quot;Hi, I&#39;m from server!&quot;));</strong></pre><pre>    serverRenderer(store)(req, res, next);<br>};</pre><pre>// ...</pre><p>Now we can clean our <strong>/server/index.js</strong> entry point:</p><pre>import express from &#39;express&#39;;<br><strong>import indexController from &#39;./controllers/index&#39;;</strong></pre><pre>const app = express();<strong><br>app.use(indexController);</strong></pre><pre>// start the app<br>// ...</pre><p>Build the app and start the node server. You should see the message rendered on the server before the client app initializes.</p><pre>yarn build &amp;&amp; node server/bootstrap.js</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*jQeH4yRkcppRzzR9_AbxUw.gif" /></figure><h4>Finally: Rehydrate the client store from the server</h4><p>As you may have already noticed, when the client app runs, the store on the client is still empty. As such, the <strong>message</strong> property will be empty, so the code in the <strong>componentDidMount</strong> will set our default message, overwriting the one rendered on the server. We need to sync the state on the client with the one on the server.</p><p>Because we’re already writing code in our HTML on the server, let’s send the data in the same place. We’ll add a placeholder in <strong>/public/index.html</strong>:</p><pre>&lt;div id=&quot;root&quot;&gt;&lt;/div&gt;<br><br><strong>&lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&gt;<br>    window.REDUX_STATE = &quot;__SERVER_REDUX_STATE__&quot;;<br>&lt;/script&gt;</strong></pre><p>Now, let’s replace this on the server with a JSON representation of our data. Update the <strong>serverRenderer</strong>:</p><pre>export default (store) =&gt; (req, res, next) =&gt; {<br>    // ...</pre><pre>    const html = ReactDOMServer.renderToString(<br>        &lt;ReduxProvider store={store}&gt;<br>            &lt;App /&gt;<br>        &lt;/ReduxProvider&gt;<br>    );</pre><pre><strong>    const reduxState = JSON.stringify(store.getState());</strong></pre><pre>    // ...</pre><pre>    return res.send(<br>        htmlData<br>            .replace(<br>                &#39;&lt;div id=&quot;root&quot;&gt;&lt;/div&gt;&#39;,<br>                `&lt;div id=&quot;root&quot;&gt;${html}&lt;/div&gt;`<br>            )<br>            .replace(<br>                &#39;&lt;/body&gt;&#39;,<br>                extraChunks.join(&#39;&#39;) + &#39;&lt;/body&gt;&#39;<br>            )<br>            <strong>.replace(&#39;&quot;__SERVER_REDUX_STATE__&quot;&#39;, reduxState)</strong><br>    );<br>}</pre><p>OK, now we’ll pick this up on the client and initialize the store before rendering the app. Update <strong>/src/index.js</strong>:</p><pre><strong>const store = configureStore( window.REDUX_STATE || {} );</strong></pre><pre>const AppBundle = (<br>    &lt;ReduxProvider store={store}&gt;<br>        &lt;App /&gt;<br>    &lt;/ReduxProvider&gt;<br>);</pre><p>Build the app and start the node server one last time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*v-0uDleXEAOY5VY8WcXtHg.gif" /></figure><h4>Going further</h4><p>If you really want to, you can even fetch data on the server from a remote API backend. Just remember that the server will take longer to respond, because it has to wait for the request to complete before doing anything. Also, depending on how much data you have to fetch, your HTML file will increase in size, because you have to include the entire initial state in the response.</p><pre><strong>// src/store/appReducer.js</strong><br>export const setAsyncMessage = messageText =&gt; dispatch =&gt; (<br>    new Promise((resolve, reject) =&gt; {<br>        setTimeout(() =&gt; resolve(), 2000);<br>    })<br>        .then(() =&gt; dispatch(setMessage(messageText)))<br>);</pre><pre>// <strong>server/controllers/index.js<br></strong>const actionIndex = (req, res, next) =&gt; {<br>    const store = configureStore();<br><br>    store.dispatch(setAsyncMessage(&quot;Hi, I&#39;m from server!&quot;))<br>        .then(() =&gt; {<br>            serverRenderer(store)(req, res, next);<br>        });<br>};</pre><p>While this works, I personally discourage its use. The main idea behind SSR is to render the app with a minimum initial state, so the user sees something until the app loads in the browser. Also, client-side applications should only hold the logic (aka data manipulation), while the actual data can be fetched async from whatever remote backend / API source.</p><p>Many production apps prefer this approach: Facebook, Slack etc. They render an <a href="https://developers.google.com/web/updates/2015/11/app-shell">empty application “shell”</a>, then they fetch the data asynchronously and show it when it’s downloaded.</p><p>On <a href="https://snipit.io/">Snipit.io</a>, I personally use this technique as well. The only data I place in the store on the server is wether the user is logged in or not. Based on that, I load a separate UI on the client. Then, only after the app is initialized on the client, I get the data asynchronously from the backend API. Until the data is fetched, the user will see placeholders for the content that will be renderer. This way, the UI loads almost instantly so the entire perceived performance is better.</p><p><em>What do you think about the techniques explained in these articles? Do you find them useful for your project? Let me know in the comments.</em></p><p><em>You can also follow me here on Medium or on Twitter </em><a href="https://twitter.com/andreiduca"><em>@andreiduca</em></a><em> for more stories like this.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9798d74dbb3b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bucharestjs/adding-state-management-with-redux-in-a-cra-srr-project-9798d74dbb3b">Adding state management with Redux in a CRA + SSR project</a> was originally published in <a href="https://medium.com/bucharestjs">BucharestJS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Upgrading a create-react-app project to a SSR + code splitting setup]]></title>
            <link>https://medium.com/bucharestjs/upgrading-a-create-react-app-project-to-a-ssr-code-splitting-setup-9da57df2040a?source=rss----985a14b72308---4</link>
            <guid isPermaLink="false">https://medium.com/p/9da57df2040a</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[code-splitting]]></category>
            <category><![CDATA[server-side-rendering]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Andrei Duca]]></dc:creator>
            <pubDate>Fri, 19 Jan 2018 14:42:11 GMT</pubDate>
            <atom:updated>2018-05-31T16:11:18.258Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>UPDATE:</em></strong><em> This is part 1 of my </em><strong><em>CRA+SSR</em></strong><em> series:</em></p><ol><li>Upgrading a create-react-app project to SSR + code splitting</li><li><a href="https://medium.com/@andreiduca/adding-state-management-with-redux-in-a-cra-srr-project-9798d74dbb3b">Adding state management with Redux in a CRA + SSR project</a></li></ol><p><strong><em>UPDATE 2:</em></strong><em> I’ve created a GitHub repo for these 2 articles:</em></p><p><a href="https://github.com/andreiduca/cra-ssr-code-splitting">https://github.com/andreiduca/cra-ssr-code-splitting</a></p><h4>The problem with CRA</h4><p>Since its inception, <strong>create-react-app</strong> is a great tool for rapidly prototyping React apps, demos and testing different features or techniques. That was, and still is, the main idea behind it. Its creators even encourage developers to look for <a href="https://github.com/facebookincubator/create-react-app#popular-alternatives">alternatives</a> if they want advanced features, like server-side rendering, usage of TypeScript or more customisation, or even eject and fiddle themselves with all the configurations.</p><p>However, many developers are afraid or skeptical to eject, and prefer (myself included) to <a href="https://medium.com/@tuchk4/why-i-love-create-react-app-e63b1be689a3">stay locked in the CRA bubble, either for convenience, declutter of config files, or for always keeping the build tools up to date</a>. That’s why <a href="https://github.com/facebookincubator/create-react-app/issues/2980">many production apps still use the original CRA tools</a>.</p><p>But while the default CRA setup can be OK for small projects, it’s not always enough for larger, more complex applications. Luckily, we can improve things, even without ejecting. Let’s try to do this step by step. This is what we’ll cover:</p><ol><li>Server-side rendering</li><li>Code splitting with react-loadable</li><li>Code splitting on the server</li><li>Taking benefit of webpack’s chunkNames</li></ol><h4>First: Server-side rendering</h4><p>Probably the most complex part of this upgrade is adding SSR. CRA by its own doesn’t offer support for this, and its devs don’t even plan to:</p><blockquote><em>Ultimately server side rendering is very hard to add in a meaningful way without also taking opinionated decisions. We don’t intend to make such decisions at this time. </em>— <a href="https://github.com/facebookincubator/create-react-app/issues/990#issuecomment-257172453">Dan Abramov</a></blockquote><p>But having SSR is something every developer is craving for. So let’s begin!</p><p><em>For the purpose of this article, we’ll use </em><a href="https://expressjs.com/"><em>express.js</em></a><em>:</em></p><pre>yarn add express</pre><p>Create a <strong>/server</strong> folder next to our <strong>/src</strong> folder. CRA’s build tools will not parse and compile anything outside the <strong>src</strong> folder. This is fine, as no code from <strong>server</strong> will be used inside our client app.</p><p>Now we need an entry point for our server app. Create a file at <strong>/server/index.js</strong>:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fsnipit.io%2Fembed%2F4703&amp;dntp=1&amp;url=https%3A%2F%2Fsnipit.io%2Flists%2F1916%2F4703&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=snipit" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/46065d763ad7eb50ae9c7b0fe03c9532/href">https://medium.com/media/46065d763ad7eb50ae9c7b0fe03c9532/href</a></iframe><p>So what’s with that <strong>serverRenderer</strong> thing? That’s an express middleware which will render our html. Our <strong>/server/middleware/renderer.js</strong> file looks like this:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fsnipit.io%2Fembed%2F4704&amp;dntp=1&amp;url=https%3A%2F%2Fsnipit.io%2Flists%2F1916%2F4704&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=snipit" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9e3c3644a70638006be2bd2b83f4328/href">https://medium.com/media/c9e3c3644a70638006be2bd2b83f4328/href</a></iframe><p>There’s one final step here: Node doesn’t speak JSX, so we need to transpile our code with babel. For this, create a <strong>/server/bootstrap.js</strong> file that will tell Node how to interpret our code (we’ll actually use this as an entry point):</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fsnipit.io%2Fembed%2F4705&amp;dntp=1&amp;url=https%3A%2F%2Fsnipit.io%2Flists%2F1916%2F4705&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=snipit" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7a40b621fe8f487c620c99f01a19b32/href">https://medium.com/media/a7a40b621fe8f487c620c99f01a19b32/href</a></iframe><p><em>You will also need to install these additional packages: </em><strong><em>babel-preset-es2015</em></strong><em>, </em><strong><em>babel-preset-react-app</em></strong><em>, </em><strong><em>ignore-styles</em></strong><em>.</em></p><p>That’s it! Now run the server:</p><pre>node server/bootstrap.js</pre><p>You can extend your server app however you want, but the above is the minimum you’ll need for server-side rendering a React app with CRA.</p><p>If your project uses <strong>React Router</strong>, you will also need to capture all paths and apply the <strong>serverRenderer</strong>. To do this, just add another router rule in your server app:</p><pre>// ...</pre><pre>// anything else should act as our index page<br>// react-router will take care of everything<br><strong>router.use(&#39;*&#39;, serverRenderer);</strong></pre><pre>app.use(router);</pre><h4>Next: Code splitting</h4><p>Having just one huge js bundle with everything contained in your app still sucks! You have to download an entire file with all the parts of your app, even if your initial render is small and will only use a couple of components. A better approach is to only load what the user will need immediately, then lazy-load other parts of the app as they are required. So let’s split!</p><p>As described in the <a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#code-splitting">documentation</a>, CRA offers support for code splitting, using dynamic imports. There’s also <a href="https://serverless-stack.com/chapters/code-splitting-in-create-react-app.html">an extensive post on how to create async components</a> in a CRA project. But more conveniently, we can use a higher order component that will simplify our work: <a href="https://github.com/thejameskyle/react-loadable">react-loadable</a>.</p><p>Let’s create <strong>/src/SomeComponent.js</strong> in our CRA app:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fsnipit.io%2Fembed%2F4706&amp;dntp=1&amp;url=https%3A%2F%2Fsnipit.io%2Flists%2F1916%2F4706&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=snipit" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cbf8e7a4037564259b7fe3f02800d26/href">https://medium.com/media/3cbf8e7a4037564259b7fe3f02800d26/href</a></iframe><p>Now let’s make this component async by importing it with react-loadable in our main <strong>App.js</strong>:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fsnipit.io%2Fembed%2F4707&amp;dntp=1&amp;url=https%3A%2F%2Fsnipit.io%2Flists%2F1916%2F4707&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=snipit" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb7860b52f27d482984bd5137b411939/href">https://medium.com/media/eb7860b52f27d482984bd5137b411939/href</a></iframe><p><em>I encourage you to read the react-loadable documentation, as it packs a lot of features, yet keeping the simplicity you see above.</em></p><p>That’s it! Now your app will load the <strong>SomeComponent</strong> module when your <strong>AsyncComponent</strong> will render. The block in the <strong>loading</strong> prop is what gets rendered <em>while</em> the required chunk is downloaded from the server and parsed.</p><p>Notice that CRA created a new file called <strong>0.[hash].chunk.js</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*77Z_ZsvlSuwk4803fo2BOA.png" /></figure><p>If you run the app now with <strong>yarn start</strong>, you’ll see just the main bundle being loaded. After the initial render, another request will retrieve our new chunk. A <strong>loading…</strong> message is displayed until the file is downloaded and parsed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*k8-vK5OhgirhfZgHrMuzow.gif" /></figure><h4>Code splitting on the server</h4><p>To make this work with SSR, we’ll need to make some small adjustments. First, for Node to understand this dynamic <strong>import()</strong>, we’ll need some babel plugins. Add them to our <strong>bootstrap.js</strong> babel-register options:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fsnipit.io%2Fembed%2F4708&amp;dntp=1&amp;url=https%3A%2F%2Fsnipit.io%2Flists%2F1916%2F4708&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=snipit" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd60091002a25541f35233af17f6b11b/href">https://medium.com/media/bd60091002a25541f35233af17f6b11b/href</a></iframe><p>Next, our server app will need to load all modules before rendering, so we don’t get that loading message rendered on the server. We need the actual component. For this, we’ll use a helper from react-loadable which preloads all async components. Update <strong>/server/index.js</strong> like this:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fsnipit.io%2Fembed%2F4709&amp;dntp=1&amp;url=https%3A%2F%2Fsnipit.io%2Flists%2F1916%2F4709&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=snipit" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdc5fd13b5ab79c7193c1171cd6b11d6/href">https://medium.com/media/cdc5fd13b5ab79c7193c1171cd6b11d6/href</a></iframe><p>Also, on the client, let’s use <strong>hydrate</strong> instead of <strong>render</strong>:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fsnipit.io%2Fembed%2F4710&amp;dntp=1&amp;url=https%3A%2F%2Fsnipit.io%2Flists%2F1916%2F4710&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=snipit" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d7a554e394d8cdccb274f239fccb597/href">https://medium.com/media/3d7a554e394d8cdccb274f239fccb597/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*rErIkH471kUa52AOh7Pysg.gif" /></figure><p>Much better! Although, we still see the loading message. This is because the app is downloading only the <strong>main.js</strong> bundle. After the bundle is parsed, the app runs, but our other chunk is not downloaded. So at hydration, our code will request it and it will render the loading message until the download is finished. We don’t want that.</p><p>Instead, we want to identify, at server render, all chunks required, then send them next to the main bundle in the html, then we need to wait for all assets to download before hydrating. Let’s start by identifying the required chunks.</p><h4>Taking benefit of webpack’s chunkNames</h4><p>CRA’s chunks by default are ugly and unpredictable. We can improve this by naming our chunks using a <a href="https://github.com/webpack/webpack/issues/1949">relatively new feature of webpack</a>: chunk names.</p><p>All we need is a comment inside the <strong>import()</strong>:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fsnipit.io%2Fembed%2F4711&amp;dntp=1&amp;url=https%3A%2F%2Fsnipit.io%2Flists%2F1916%2F4711&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=snipit" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c264827aa16338be414ae8a82f465207/href">https://medium.com/media/c264827aa16338be414ae8a82f465207/href</a></iframe><p>The last line tells react-loadable that this component requires the chunk named <strong>myNamedChunk</strong>. Let’s build first:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*JTOHHayi8GRi1Q0KSK29-A.png" /></figure><p>Better. Let’s see what’s in our <strong>/build/asset-manifest.json</strong> file:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fsnipit.io%2Fembed%2F4712&amp;dntp=1&amp;url=https%3A%2F%2Fsnipit.io%2Flists%2F1916%2F4712&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=snipit" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bac9aaacc07492a31c6031317fec4b5/href">https://medium.com/media/4bac9aaacc07492a31c6031317fec4b5/href</a></iframe><p>Great! We see a nice, predictable name being mapped to the actual hashed filename. But how can we know which chunks we actually need to load? In a larger application, we surely don’t want all of them. Luckly (you guessed it) react-loadable comes once more to the rescue. Let’s update our renderer middleware:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fsnipit.io%2Fembed%2F4713&amp;dntp=1&amp;url=https%3A%2F%2Fsnipit.io%2Flists%2F1916%2F4713&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=snipit" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6e0aac70b51a8a3fa483bd7feafaf8e/href">https://medium.com/media/c6e0aac70b51a8a3fa483bd7feafaf8e/href</a></iframe><p>Run the server and refresh the page and you’ll see in the console an array containing all the names of the chunks the server used to render the initial state of the app (except the main bundle). We just need to map this to the actual javascript files:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fsnipit.io%2Fembed%2F4714&amp;dntp=1&amp;url=https%3A%2F%2Fsnipit.io%2Flists%2F1916%2F4714&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=snipit" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/98ff00a3bab419499672403a497ca74a/href">https://medium.com/media/98ff00a3bab419499672403a497ca74a/href</a></iframe><p>Now add them as script tags at the end of the <strong>body</strong>:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fsnipit.io%2Fembed%2F4715&amp;dntp=1&amp;url=https%3A%2F%2Fsnipit.io%2Flists%2F1916%2F4715&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=snipit" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d68ebfacea4af23c552c7519ef23ed98/href">https://medium.com/media/d68ebfacea4af23c552c7519ef23ed98/href</a></iframe><p>One final step, we need to wait for the document to load all assets before hydration. So we change the <strong>index.js</strong> on the client:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fsnipit.io%2Fembed%2F4716&amp;dntp=1&amp;url=https%3A%2F%2Fsnipit.io%2Flists%2F1916%2F4716&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=snipit" width="800" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6cb1f81b80b53edfe311bad9832d7667/href">https://medium.com/media/6cb1f81b80b53edfe311bad9832d7667/href</a></iframe><p>Let’s build one last time and run the server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*rZ08h9FajCvjDLSnXN7fJA.gif" /></figure><p>Notice the required chunk being loaded before the main bundle runs and requests it. So at hydration, we’re sure we have all necessary modules, thus getting rid of the ugly <strong>loading…</strong> message.</p><h4>Summary</h4><p>We’ve come a long way, but we managed to upgrade our simple CRA app to a full SSR + code splitting setup in just a few steps, without ejecting and without using other templates, boilerplates or frameworks.</p><p>I’ve used everything mentioned here on an awesome project I’m currently developing: <a href="https://snipit.io/">Snipit.io</a>, a collaborative tool for saving and organizing code snippets in the cloud. Besides what’s discussed in this article, <a href="https://snipit.io/">Snipit</a> also uses Redux, React Router and Styletron (for styled components). The server app uses a shared session with the backend app, so the server renderer knows if the user is logged in or not and renders components accordingly.</p><p>I’ll probably write another article on how everything works.</p><p>Finally, you can see a complete list with all the files we modified here from a blank CRA app at <a href="https://snipit.io/public/lists/1365/">snipit.io/public/lists/1365</a>. You can also bookmark this list for future reference if you create an account and log in. Do it, it’s free!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9da57df2040a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bucharestjs/upgrading-a-create-react-app-project-to-a-ssr-code-splitting-setup-9da57df2040a">Upgrading a create-react-app project to a SSR + code splitting setup</a> was originally published in <a href="https://medium.com/bucharestjs">BucharestJS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Refactor Node.js Routes with Testable, Functional Concepts like Composition, Currying, and Closures]]></title>
            <link>https://medium.com/bucharestjs/refactor-node-js-28eb2c195dc4?source=rss----985a14b72308---4</link>
            <guid isPermaLink="false">https://medium.com/p/28eb2c195dc4</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[composition]]></category>
            <category><![CDATA[clojure]]></category>
            <category><![CDATA[currying]]></category>
            <category><![CDATA[functional-javascript]]></category>
            <dc:creator><![CDATA[Daniel Dughila]]></dc:creator>
            <pubDate>Thu, 21 Dec 2017 09:58:49 GMT</pubDate>
            <atom:updated>2017-12-22T17:18:40.669Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*fqL2FSCyrHWiosB76p_0Yw.png" /><figcaption>Light Functional JavaScript</figcaption></figure><h4>I love Node.js! It’s very <strong>fast</strong>, <strong>lightweight</strong> and lets you spin up applications with just a few lines of code.</h4><h3>I remember reading about the Node.js callback hell and how there’s no escape from it</h3><p>There’s even a website called the <a href="http://callbackhell.com/">callbackhell.com</a>, lol.</p><p>What’s funny is that most times I don’t even realize how messy my code is until <strong>I try to test it</strong>.</p><p>Because I have no life, I once tried to <strong>retrieve </strong>some of my<strong> gists</strong> from the Github API, <strong>reduce </strong>them to their descriptions and URLs and <strong>sort</strong> them alphabetically by their description field.</p><p>No problem!</p><h4>Here’s the mini express app</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00b21068c01289e9293ecdb18a4edd83/href">https://medium.com/media/00b21068c01289e9293ecdb18a4edd83/href</a></iframe><h4>Here’s the hellish route which handles the gists logic I talked about</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5357f8cc3b04c51db2e0408d9c1b8d37/href">https://medium.com/media/5357f8cc3b04c51db2e0408d9c1b8d37/href</a></iframe><p>Mmmm, I’m not even going to try testing it! I may add tests if you guys like this article and decide <strong>to punish me</strong> by insisting.</p><p>But wait, there must be light at the end of the tunnel. I can’t leave my code untested!</p><h4>Could there be a way to simplify it?</h4><p>What luck, it turns out <strong>functional programming</strong> and good, opinionated programming practices can help</p><p>Let’s refactor this code together!</p><h3>Step one, separation of concern</h3><p>I don’t like the fact that our code <strong>instantiates </strong>the Express route, <strong>pulls</strong> in dependencies and <strong>handles</strong> business logic, all at once. Let’s fix this!</p><p>Voila!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17f1baad98978dc1733c77caaa270df1/href">https://medium.com/media/17f1baad98978dc1733c77caaa270df1/href</a></iframe><p>Express is expressing itself, while we handle our route logic in the <strong>handleGistsRoute</strong> function.</p><h3>Step two, function currying</h3><blockquote>Currying means to break down a function that takes multiple arguments into a series of functions</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9334d4e3ca9512c55a0aa71520880c06/href">https://medium.com/media/9334d4e3ca9512c55a0aa71520880c06/href</a></iframe><p><strong>HandleGistsRoute</strong> results from the <strong>curried</strong> <strong>handleGistsRouteFactory</strong> which accepts a set of <strong>dependencies</strong> and returns another function, ready to receive the <strong>gistsUrl</strong> from its <strong>caller</strong>, the Express route.</p><p>The last function returned by the factory will get<strong> </strong>called by Express with the <strong>req</strong>, <strong>res</strong>, <strong>next</strong> arguments.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/049e840a1bbe104d935db676b1480530/href">https://medium.com/media/049e840a1bbe104d935db676b1480530/href</a></iframe><p>Wow, this will take a while to sip in. Maybe watch this videos about <a href="https://www.youtube.com/watch?v=iZLP4qOwY8I">currying</a>, <a href="https://www.youtube.com/watch?v=CQqwU2Ixu-U">closures</a> and <a href="https://www.youtube.com/watch?v=BMUiFMZr7vk">higher order functions</a> to understand the concepts better.</p><p>Unit tests use the <strong>handleGistsRouteFactory</strong> while the rest of the app uses the actual <strong>handleGists</strong> method, precompiled with its dependencies (saving us the trouble of passing them around).</p><h3>Step three, extracting pure functions</h3><p>Notice that <strong>handleGistsRouteFactory</strong> is now a <strong>pure function</strong> (almost, because it calls next instead of returning output), receiving all its data through parameters (easy to mock in our tests).</p><blockquote>A <strong>pure function</strong> is a <strong>function</strong> where the return value is only determined by its input values, without observable side effects</blockquote><p>My critical eye tells me that we can extract the <strong>description</strong>, <strong>filtering</strong> and <strong>URL generating</strong> logic from our handleGistsRouteFactory.</p><p>This means we can extract the <strong>getDescription</strong>, <strong>sortByName</strong>, <strong>getNextUrlFactory</strong>, and <strong>getNextUrl</strong> PURE functions from our handleGistsRouteFactory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e49b751bed136ae1439b12a61cda2c1a/href">https://medium.com/media/e49b751bed136ae1439b12a61cda2c1a/href</a></iframe><p>We took quite a lot of the <strong>handleGistsRouteFactory</strong> shoulders. The function does not worry about <strong>processing</strong> and <strong>sorting</strong> gists or about <strong>knowing</strong> which URLs to access anymore.</p><p>Already our function looks great. But we can do much better!</p><h3>Step four, async await</h3><p><strong>Async await</strong> is syntactic sugar for promises, allowing us to put more emphasis on <strong>what </strong>the code does instead<strong> </strong>of<strong> how</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab4b629ef6f82b17356d5c918586c1d6/href">https://medium.com/media/ab4b629ef6f82b17356d5c918586c1d6/href</a></iframe><p><strong>HandleGistsRouteFactory</strong> is now 20 lines of code, sweet!</p><p>The engineer in me sees lines 34 and 35 as possible <strong>candidates for recursion</strong>. What if we could get as many gists pages as we wanted?</p><h3>Step five, over engineered recursion</h3><p>If it comes naturally to you, recursion can be a great way to do <strong>declarative</strong> <strong>programming</strong>, which IMO, is a broader paradigm which includes FP as well.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bbfefae98f9f7296f6961921555dc9f2/href">https://medium.com/media/bbfefae98f9f7296f6961921555dc9f2/href</a></iframe><p>We’ve extracted the get gists logic into the async, recursive, over-engineered<strong> getGistsFactory</strong>, just because we can!</p><p>Browse the code for a minute. I think it’s easier to read and <strong>I know</strong> it’s easier to test.</p><h3>Step six, Testing the beast</h3><p>Without further ado, let’s test with <strong>Jest</strong>! Ooo, it rhymes!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/801855bc32793420381b9e313323885e/href">https://medium.com/media/801855bc32793420381b9e313323885e/href</a></iframe><p>That’s it!</p><p>Every method is tested and ready for production.</p><p>I used a <strong>quick</strong> and <strong>fancy</strong> method of <strong>mocking</strong> which you can read about <a href="https://medium.com/@danieldughila/mocking-in-typescript-a97267f7cea9">here</a>.</p><p>The code for this article is on <a href="https://github.com/intojs/refactor-nodejs-routes">Github</a>, please check it out.</p><h4>I hope you enjoyed my article, please clap if you did so others can notice it too!</h4><p>Everything you read is opinionated, <strong>so please comment</strong> and share your ideas!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28eb2c195dc4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bucharestjs/refactor-node-js-28eb2c195dc4">Refactor Node.js Routes with Testable, Functional Concepts like Composition, Currying, and Closures</a> was originally published in <a href="https://medium.com/bucharestjs">BucharestJS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Developers Guide to Redux-like State Management in Angular while Keeping it a Secret]]></title>
            <link>https://medium.com/bucharestjs/the-developers-guide-to-redux-like-state-management-in-angular-3799f1877bb?source=rss----985a14b72308---4</link>
            <guid isPermaLink="false">https://medium.com/p/3799f1877bb</guid>
            <category><![CDATA[rxjs]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[ngrx]]></category>
            <category><![CDATA[angular2]]></category>
            <dc:creator><![CDATA[Daniel Dughila]]></dc:creator>
            <pubDate>Thu, 25 May 2017 10:33:20 GMT</pubDate>
            <atom:updated>2021-01-16T23:09:29.419Z</atom:updated>
            <content:encoded><![CDATA[<h4>With the help of RxJS</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NY5UxO187nMzYgfm2lfYyw.jpeg" /><figcaption>The road to Single State Management</figcaption></figure><p>More and more people are talking about JavaScript state management systems like Redux, MobX or Relay. Almost every article, tutorial or talk out there has something to do with the libraries above.</p><p>Let’s say you join an ongoing Angular project and you say:</p><blockquote>Yes, I want it, I want to get inspired by Redux!</blockquote><p>You google around and find the <a href="https://github.com/ngrx/store">@ngrx/store</a> library which is great and you cannot wait to use it. Then you talk to the team about <strong>not</strong> managing state in controllers, introducing concepts like <strong>actions</strong>, <strong>reducers</strong>, <strong>selectors,</strong> and <strong>immutability</strong>.</p><p>Depending on your team’s momentum, the decision to adopt new technologies can take a while.</p><h3>In the meantime, welcome RxJS!</h3><p>You already have RxJS reactive extensions bundled up in your Angular application. Embracing their power will allow you to use the principles of Redux without having the need to introduce specific terminologies like actions and reducers.</p><p>Redux can be described in three fundamental principles:</p><blockquote>Single source of truth</blockquote><blockquote>State is read-only</blockquote><blockquote>Changes are made with pure functions</blockquote><p>To illustrate all of this, let&#39;s build a small app which <strong>retrieves</strong>, <strong>lists</strong> and <strong>counts</strong> my <a href="https://github.com/intojs">Github repos</a>, sticking to the Redux principles while using RxJS.</p><p>The state of our application will be stored in an object tree within a single store.</p><h3>Modeling our data</h3><p>Our application&#39;s state has a <strong>repos</strong> entity which can be in an <strong>isLoading </strong>state and can have many objects of type <strong>Repo</strong> loaded from Github.<br>Sometimes errors happen which means that our <strong>repos</strong> entity needs a <strong>hasError</strong> property.</p><p><em>There is no need for a </em><strong><em>count</em></strong><em> property because we can derive its value from the length of the repos array.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e199b780e89731dc4b3eabdec8aa1f9/href">https://medium.com/media/7e199b780e89731dc4b3eabdec8aa1f9/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/22f2c834861a47d35fe0c085f4c532d9/href">https://medium.com/media/22f2c834861a47d35fe0c085f4c532d9/href</a></iframe><h3>Creating a store service</h3><p>Having finished modeling our data, let’s create a store service which will hold the applications’ state in a RxJS <strong>BehaviorSubject</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/680927c125024f111b127d6ef3223891/href">https://medium.com/media/680927c125024f111b127d6ef3223891/href</a></iframe><p>The store service exposes an <strong>observe</strong> method which, together with the <strong>distinctUntilChanged</strong> operator returns an observable sequence that contains only distinct contiguous elements empowering the immutable character of our state.</p><p>The second method is called <strong>dispatch </strong>and is in charge of updating our state by calling <strong>next</strong>. The method expects an event of <strong>StoreEvent</strong>. It passes the current state to that event and gets back a fresh new one.</p><p>The store service will be a provider of the store module, being injectable app-wide.</p><h3>Creating events</h3><p>Now that the store is complete, we need events to update it. Each event has a <strong>payload </strong>and a <strong>getNewState</strong> method which holds the reducer logic.</p><p>The <strong>StoreEvent</strong> abstract class ensures that our future events will have consistency and is, in fact, a nice way of implementing the concepts of <strong>actions</strong> and <strong>reducers</strong> without anybody noticing it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e0b16c3fe8241dcdc5a9964fd3b3a5b/href">https://medium.com/media/0e0b16c3fe8241dcdc5a9964fd3b3a5b/href</a></iframe><p>Thinking about the process of getting repos from Github, our application will handle three events: <strong>GetRepos</strong>, <strong>GetReposSuccess</strong>, <strong>GetReposError</strong>.</p><h4>Getting repos</h4><p>The event has no payload, it just needs to set the state&#39;s <strong>isLoading</strong> property to true and return a new copy of it without mutations.</p><h4>Repos have been fetched successfully</h4><p>This event receives the <strong>repos</strong> as a <strong>payload</strong> and it stores them in our state together with setting the <strong>isLoading</strong> and <strong>hasError</strong> properties to <strong>false</strong>.</p><h4>Could not retrieve repos</h4><p>I know Github always works, but, let&#39;s build the error event nonetheless.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abae0fc79920d2391c13fdecdb0c4f05/href">https://medium.com/media/abae0fc79920d2391c13fdecdb0c4f05/href</a></iframe><h3>Creating the repos service</h3><p>At this point, we have set up our infrastructure, having our single source of truth neatly stored away into a <strong>BehavoirSubject</strong> and our events ready to be emitted!</p><p>In order to interact with Github and fetch our data, we need a service.<br>Because our state is decoupled from our components, we can delegate event dispatching to this very service, making it communicate with our store.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bec226a47e4c8f20a2370dba2752c3b3/href">https://medium.com/media/bec226a47e4c8f20a2370dba2752c3b3/href</a></iframe><h3>Consuming the state</h3><p>Now that we have created the service, let&#39;s consume our state and hook everything up at the component level.</p><p>We will inject our store and subscribe to the repos properties.</p><p>The <strong>async pipe</strong> is really handy, making it possible to use the subscription directly at the template level.<br><br>The interesting part consists in using RxJs operators to query our store, just like a front end database.</p><p><em>Notice how we derive the </em><strong><em>total count</em></strong><em> of the repos without having this information directly in our datastore.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38f948d82a25e6fc751e7e78cd102d7c/href">https://medium.com/media/38f948d82a25e6fc751e7e78cd102d7c/href</a></iframe><p>With this said, I hope this article was useful and I can hardly wait to see your comments!</p><p>You can <a href="https://github.com/intojs/redux-like-state-management-in-angular">clone the repo</a> from Github or <a href="https://intojs.github.io/redux-like-state-management-in-angular/">visit the demo</a> page.</p><p>Special thanks to <a href="https://medium.com/u/85593e8ac888">Sabin</a> for inspiration, one of the best engineers i know!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3799f1877bb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bucharestjs/the-developers-guide-to-redux-like-state-management-in-angular-3799f1877bb">The Developers Guide to Redux-like State Management in Angular while Keeping it a Secret</a> was originally published in <a href="https://medium.com/bucharestjs">BucharestJS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On the importance of Babel, jQuery and React Native]]></title>
            <link>https://medium.com/bucharestjs/on-the-importance-of-babel-jquery-and-react-native-5c8d32674ae4?source=rss----985a14b72308---4</link>
            <guid isPermaLink="false">https://medium.com/p/5c8d32674ae4</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[babel]]></category>
            <category><![CDATA[jquery]]></category>
            <dc:creator><![CDATA[Adrian Oprea]]></dc:creator>
            <pubDate>Mon, 22 May 2017 09:39:55 GMT</pubDate>
            <atom:updated>2017-06-23T20:30:20.175Z</atom:updated>
            <content:encoded><![CDATA[<h3>jQuery, Babel, React Native and the importance of making mistakes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GiPAkqemOawoWhYahyCnCw.jpeg" /><figcaption><em>Credits: </em><a href="https://www.flickr.com/photos/nesster/"><em>Jussi</em></a><em> — </em><a href="https://flic.kr/p/4nScvy"><em>RANT, this way</em></a></figcaption></figure><p>Not very long ago, we didn’t have all these generators, scaffolders, bootstraps etc. Not long since we used to include a small library into every project. You got it right, people, I’m talking about jQuery!</p><p>Actually, the article is not about jQuery. The title can be regarded as a clickbait but I had to draw your attention to something important. Consider this article a parallel between jQuery and the web platform’s current state of affairs.</p><p>A couple of days ago, I saw this tweet from Dan Abramov:</p><h3>Dan Abramov on Twitter</h3><p>Babel is the new jQuery.</p><p>I know Dan’s intention was not to offend, and he even mentions this in a later reply. Still, it got me thinking deeper about the importance of some projects to the web community. I even replied on that thread with what is supposed to be the essence of this article.</p><p>Let’s look at jQuery. It was the first library that really made the DOM friendlier to non-programmers. It opened up DOM manipulation to design professionals, junior developers, HTML/CSS developers — yes, there was such a thing. You didn’t have to be a programming wiz to hide and show a text block when clicking on a button.</p><p>Besides making interacting with the DOM a trivial task, it also allowed us to make mistakes. A lot of them — mistakes and people 😎! Some learned important lessons and modern day frameworks started to take shape. People noticed that code started becoming too verbose and everyone wrote JavaScript <strong>Their Way</strong>™. They quickly realised they needed to standardise development, so tools were created to account for that need. This is how JSHint, JSLint and ESLint were born.</p><p>The core idea is that jQuery enabled a whole generation of professionals to ease their way into JavaScript development. Don’t forget that many of us might not have learned how fade-in and fade-out work if we would’ve kept writing HTML and CSS for IE6 — with the validator.w3.org badge in the footer, of course.</p><p>We tend to forget that ES5 was published in 2009 and updated in 2011. It was the first real update since ES3 was standardised, in June 2001 and after work on ES4 was dropped in 2007. We tend to forget that it took until around 2011 for many projects to drop old IEs and migrate to ES5. There are projects out there still running on ES3. People maintain those codebases.</p><p>Fast-forward to 2017, Babel is in a similar position jQuery was, years ago. Glancing over the web platform, today, we see a lot of improvements. There are a lot of things currently being worked out and a hell lot more that have been finalised. Sensors, camera and mic access, phone vibration, File API, LocalStorage and Progressive Web Apps, just to name a few.</p><p>To my knowledge, what Babel did for the web platform is unprecedented. It helped us get rid of shims, shivs, or whatever they call them these days. Babel enabled us to use standards-to-be. It enabled people on the TC39 committee to iterate quicker, and based on real feedback from the community, rather than publishing some brittle specification and hope everyone complies. It saved us from waiting for the next major release to see a fix in the language, or a new feature.</p><p>Today, if you want to use generators, async-await, reflection, you just drop Babel in and start coding. A friend of mine told me that Babel is all about the output, and the trans-compilation. I disagree. I think that Babel is all about the source code. Up to this point, for me, it was like that scarf that goes well with all my other clothes. You know? Like that watch that compliments your dress / suit.</p><p>Once again, just like jQuery, it allowed a whole generation of people, not that into classes, or with decent programming knowledge, to make mistakes and dive into less accessible concepts.</p><p>Of course, it&#39;s worth mentioning that JavaScript has its merits here. Its flexibility and ubiquity allowed many less-capable beings like myself to explore concepts without having to install a compiler, a transpiler, a linter, a linker, a helicopter and two slices of ham to get things working.</p><p>I have nothing against <strong>Other Languages™</strong> but if I have to type 23847 characters and spend 40 minutes configuring an environment just to print &quot;Hello world&quot;, I’ll pass.</p><p>JavaScript is easy: pop-open your browser’s developer tools and write the damn thing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jynZRRMqvxG1ziuBlEYTWw.png" /><figcaption>Hello World — Ninja level</figcaption></figure><p>Looking a bit into the future, I can see that React Native interest is trending upwards. StackOverflow published an <a href="https://stackoverflow.blog/2017/05/16/exploring-state-mobile-development-stack-overflow-trends/">interesting article on their blog,</a> which I recommend you to read. I see React Native like the natural step in the cascade of technologies I mentioned in this article. Of course, it builds on the shoulders of giants. Cordova, Ionic, NativeScript, and the native platforms it supports, they’ve all contributed to its popularity. I see it as the next best thing that came out of our mistakes and learnings from using tools like our heroes, jQuery and Babel. And just like them, React Native will probably open up <em>reserved</em> field, to the many developers without an interest in learning native mobile technologies. This is exactly the kind of “juice” that enables startups to iterate quickly and bring the amazing products we all have installed on our phones.</p><p>Lastly, don’t forget that a couple of years ago, many of us, developers and recruiters alike, thought jQuery was a programming language. Don’t forget we were looking for AngularJS developers with 6 years of experience, in 2011. With that in mind, always stay curious, challenge the rules, break them and most importantly, <strong>learn from your mistakes</strong>!</p><p><em>Like the article? Found it useful? Follow me on </em><a href="http://medium.com/@oprearocks"><em>Medium</em></a><em> / </em><a href="http://twitter.com/@oprearocks"><em>Twitter</em></a><em>.</em></p><p><em>Originally published on </em><a href="https://oprea.rocks/blog/jquery-babel-react-native-and-the-importance-of-making-mistakes/"><em>oprea.rocks</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c8d32674ae4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bucharestjs/on-the-importance-of-babel-jquery-and-react-native-5c8d32674ae4">On the importance of Babel, jQuery and React Native</a> was originally published in <a href="https://medium.com/bucharestjs">BucharestJS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How can developers improve their paycheck.]]></title>
            <link>https://medium.com/bucharestjs/how-can-developers-improve-their-paycheck-61640f4f86cf?source=rss----985a14b72308---4</link>
            <guid isPermaLink="false">https://medium.com/p/61640f4f86cf</guid>
            <category><![CDATA[developer-stories]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[developer-relations]]></category>
            <dc:creator><![CDATA[Developer Nation]]></dc:creator>
            <pubDate>Mon, 15 May 2017 16:52:28 GMT</pubDate>
            <atom:updated>2017-05-15T16:53:37.573Z</atom:updated>
            <content:encoded><![CDATA[<p><em>By Stijn Schuermans</em></p><p>As a software developer, what is the most lucrative opportunity you could be working on? This is a very relevant question to ask. Software skills are generally scarce and good developers are highly coveted. Furthermore, developers are mobile, in the sense that the nature of their trade allows them to work from remote locations quite easily and marketplaces for their services are well established. So which project should you pick?</p><p>There are many reasons why someone might prefer one job over another, but let’s be honest: developers deserve to get paid well, given their important position in the global value chain. For the first time in 12 editions, we asked developers in our survey how much they earn in salaries or contractor fees. The results are in and from the data we learn several insights that can help developers improve their paycheck, and conversely, provide opportunities for organisations to find talent.</p><p>First, there are enormous differences in how much developers in each region and software sector earn. The best earning developers in our survey — those in the top ten percent — often earn tens and sometimes hundreds of times as much as the least well-off, i.e. the bottom decile. Part of this gap is location-driven. We’ll come back to that shortly. This said, we can only conclude that a developer’s skill, knowledge, and reputation do matter. Investing in them will pay off.</p><p><em>Are you interested in finding out more on developer skills and salaries? </em><a href="http://vmob.me/DE3Q17BucharestJS"><em>Take the Developer Economics survey</em></a><em> and help us generate more insights for you to improve your paycheck.</em></p><h3>Developers working in areas with a higher technical complexity generally earn more.</h3><p>Talking of skills, developers who work in areas with a higher technical complexity — and therefore higher barriers to entry and ultimately fewer developers doing it — generally earn more. Developers that work on cloud computing and other backend services report higher salaries than those working on front-end web apps. Machine learning specialists make even more than the backend folks. In Western Europe, for example, the median web developer has a yearly gross salary of $35,400 USD, the median backend developer earns $39,500 and a machine learning developer makes $45,200. This relationship is seen across regions and also at higher wage levels. Web and mobile development are the most commoditised; there is a fairly low barrier to start making simple apps or websites, and these tasks are relatively easily outsourced to other regions.</p><h3>Scarcity of skills drives up the price for developer services.</h3><p>Scarcity of skills drives up the price for developer services. This is also true for new, emerging areas of development, like Augmented and Virtual Reality, or the Internet of Things, but only at the top end of the scale.The best developers in emerging areas earn top dollar, while the bottom half of the developer population makes less than their counterparts in more established sectors. Let’s compare Augmented Reality (AR) with backend developers in North America as an example. The median wage for an AR developer in that region is $71,000 USD, a good bit less than the $79,200 that the median backend developer makes. At the top end, however, AR development is more lucrative. At the 75th percentile, the AR developer is paid $132,300 and the backend developer $122,800. At the very top (90th percentile), the difference is even more pronounced: $219,000 for AR, $169,000 for backend. The reason for this wide range of salaries is that markets like AR/VR or IoT are still commercially underdeveloped. Companies that are early adopters pay large sums for skilled developers, who are scarce. At the same time, less experienced developers are attracted by the hype. Their compensation suffers both from a lack of relevant skill and from a lack of companies that are hiring in the early market.</p><p>Again this pattern repeats across regions. The exception is South Asia. The outsourcing model that drives software development in that region seems to be built on maintaining legacy code and developers there are less involved in emerging innovations (a conclusion that’s also supported by our developer population sizing research).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/0*QFht8WCif9ezteX6.jpg" /></figure><h3>We’re still a long way off a global market for developers!</h3><p>We started this chapter by saying that developers can market their services location-independently if they choose to. However, it’s clear from the data that we’re still a long way off a global market for developers! The median web developer in North America for instance earns $73,600 USD per year. A Western European web developer earns half of that — $35,400 USD — although recent exchange rate shenanigans due to Brexit and the Euro-crisis will have affected that comparison. Web developers in other regions earn again half of that: between $11,700 in South Asia and $20,800 in Eastern Europe. Not just the region of the world you live in matters, but also the country and even the city you call home.</p><p>This opens up opportunities for organisations who will accept remote workers. You can hire a top 10% Eastern European backend developer for less money than the median North American wage in that sector. For developers, it means that brushing up your English skills and looking for opportunities beyond your backyard can be very interesting indeed. Developers who take that leap and seek opportunities that pay to international standards are in the minority. This explains why top wages in emerging regions (Asia, the Middle East, Africa) are so exuberantly high compared to local standards. A Western developer in the top decile earns about three times as much as the median wage in his sector and region. In the emerging world, top wages are seven to ten times the median. The best developers in those regions work for multinationals or sell their services on international marketplaces, while most stay employed locally, at much lower remuneration levels.</p><p>So what’s a developer to do if you want to move up in the world, financially? Invest in your skills. Do difficult work. Improve your English. Look for opportunities internationally. Go for it. You deserve it!</p><p><em>Also find out where you stand compared to other developers in your country/ region by taking the </em><a href="http://vmob.me/DE3Q17BucharestJS"><em>Developer Economics survey</em></a><em> and receiving instant feedback.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61640f4f86cf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bucharestjs/how-can-developers-improve-their-paycheck-61640f4f86cf">How can developers improve their paycheck.</a> was originally published in <a href="https://medium.com/bucharestjs">BucharestJS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Catching global errors in Angular 2]]></title>
            <link>https://medium.com/bucharestjs/catching-global-errors-in-angular-2-8614d9aa298a?source=rss----985a14b72308---4</link>
            <guid isPermaLink="false">https://medium.com/p/8614d9aa298a</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular2]]></category>
            <category><![CDATA[error-handling]]></category>
            <dc:creator><![CDATA[Daniel Popescu]]></dc:creator>
            <pubDate>Thu, 11 May 2017 10:26:19 GMT</pubDate>
            <atom:updated>2017-05-11T10:26:19.474Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*YiJuv6H-I4GVMYyqiatUbw.png" /></figure><p>Angular 2 already has a very good <a href="https://angular.io/docs/ts/latest/api/core/index/ErrorHandler-class.html">error handler</a>. When an error randomly occurs in your code, the Angular’s error handler will catch it and will print the error details in the console. The error details will also include the line number with a link to the source file. In most cases this should be more then enough to help you understand what is happening in your application.</p><h3>Why would I need a custom error handler?</h3><p>You can use a custom error handler to format the error messages that are logged into the browser’s console, to catch custom business errors in your application (Authentication/Authorization errors, HTTP 404, etc.) or maybe you want to also send the errors to you backend server for analytics or other reasons. All of the above are valid use cases of using a custom error handler.</p><h3>Creating a custom error handler</h3><p>Writing your own error handler is straightforward. You will need to extend Angular’s ErrorHandler class and override the handleError method. This method receives a wrapper of the original error as a parameter. You can find the original error in the error.originalError property. The default implementation uses console.error() to print the error details in the browser’s console.</p><p><strong><em>CustomErrorHandler.ts</em></strong></p><pre>import {ErrorHandler} from &#39;@angular/core&#39;;<br><br>export class CustomErrorHandler extends ErrorHandler {<br>    constructor() {<br>        super(false);<br>    }<br><br>    public handleError(error: any): void {<br>        <em>// You can add your own logic here. // It is not required to delegate to the original implementation super.handleError(error);<br>    </em>}<br>}</pre><h3>Extending Angular’s Error Handler</h3><p>If you want to use your own custom handler you will need to somehow replace the one that Angular is using. Fortunately enough, Angular’s awesome DI engine will allows you to provide custom implementations for different classes.</p><p><strong><em>AppModule.ts:</em></strong></p><pre>import {BrowserModule} from &#39;@angular/platform-browser&#39;;<br>import {ErrorHandler} from &#39;@angular/core&#39;;<br>import {AppComponent} from &#39;./app.component&#39;;<br>import {CustomErrorHandler} from &#39;./CustomErrorHandler&#39;;<br><br>@NgModule({<br>    declarations: [AppComponent],<br>    imports: [BrowserModule],<br>    bootstrap: [AppComponent],<br>    providers: [{provide: ErrorHandler, useClass: CustomErrorHandler}]<br>})<br>export class AppModule {<br>    <br>}</pre><p>In the code above take a look at the providers field in the @NGModule decorator. With the above configuration in place, every time Angular’s DI engine will request an instance of ErrorHandler will receive an instance of our custom implementation CustomErrorHandler.</p><h3>Creating custom error classes</h3><p>Sometimes it’s useful to create custom error classes that you can throw in different parts of your application. For example, when the user is doesn’t have access to a specific part of the application you can throw a custom AuthorizationError.</p><h3>Creating the custom error class</h3><p><strong><em>AuthorizationError.ts:</em></strong></p><pre>export class AuthorizationError {<br>    toString() {<br>        return &#39;You are not authorized to view this content!!!&#39;;<br>    }<br>}</pre><h3>Updating the CustomErrorHandler class</h3><p><strong><em>CustomErrorHandler.ts:</em></strong></p><pre>import {ErrorHandler} from &#39;@angular/core&#39;;<br>import {AuthorizationError} from &#39;./AuthorizationError&#39;;<br><br>export class CustomErrorHandler extends ErrorHandler {<br>    constructor() {<br>        super(false);<br>    }<br><br>    public handleError(error: any): void {<br>        if (error.originalError instanceof AuthorizationError) {<br>            <em>console</em>.info(`[CUSTOM ERROR]:::${error.originalError.toString()}`);<br>        } else {<br>            super.handleError(error);<br>        }<br>    }<br>}</pre><h3>Using the new error in your code</h3><p><strong><em>app.component.html:</em></strong></p><pre>&lt;button (click)=<strong>&quot;throwCustomError()&quot;</strong>&gt;<strong>Throw Authorization Error</strong>&lt;/button&gt;</pre><p><strong><em>app.component.ts:</em></strong></p><pre>import {Component} from &#39;@angular/core&#39;;<br>import {AuthorizationError} from &#39;./AuthorizationError&#39;;<br><br>@Component({selector: &#39;app-root&#39;, templateUrl: &#39;./app.component.html&#39;, styleUrls: [&#39;./app.component.css&#39;]})<br>export class AppComponent {<br>    throwCustomError() {<br>        throw new AuthorizationError();<br>    }<br>}</pre><p>Now when you press the Throw Authorization Error button you will see our custom error logging in the browser’s console:</p><p>[CUSTOM ERROR]:::You are not authorized to view this content!!!</p><p>If you look closely at the CustomErrorHandler class, everything that is not of type AuthorizationError will be delegated to the original Angular’s ErrorHandler.</p><p><em>Originally published at </em><a href="https://dpopescu.me/2016/10/21/catching-global-errors-in-angular-2/"><em>dpopescu.me</em></a><em> on October 21, 2016.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8614d9aa298a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bucharestjs/catching-global-errors-in-angular-2-8614d9aa298a">Catching global errors in Angular 2</a> was originally published in <a href="https://medium.com/bucharestjs">BucharestJS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build and Market a Successful UI Kit]]></title>
            <link>https://medium.com/bucharestjs/how-to-build-and-market-a-successful-ui-kit-6a0465358b8?source=rss----985a14b72308---4</link>
            <guid isPermaLink="false">https://medium.com/p/6a0465358b8</guid>
            <category><![CDATA[design]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[bootstrap]]></category>
            <category><![CDATA[ui]]></category>
            <dc:creator><![CDATA[Elena-Cristina Conacel]]></dc:creator>
            <pubDate>Wed, 10 May 2017 19:15:39 GMT</pubDate>
            <atom:updated>2017-05-11T08:40:02.091Z</atom:updated>
            <content:encoded><![CDATA[<h4>The story behind the Paper Kit</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*nL-k3r7wNqlt2Z9U4UnAFw.jpeg" /><figcaption>Paper UI Kit</figcaption></figure><p>The main challenge that me and my team at <a href="http://creative-tim.com/">Creative Tim</a> have faced since day 1 was how to make our hobby an economical way of sustaining ourselves. To do this, we had to learn how to build beautiful UI Kits that people actually want to use and how to get them in front of users. After a few tries and a lot of effort put into it, we have understood a couple of things that we think can help anyone trying to get into this space. <br> <br> During the first couple of months, my partner Alex was in charge of the development for the products. After we started getting traction on some of the kits, we got feedback from our customers saying they wished we released more. So that was the point that I have gotten myself involved directly into the coding for the product. Keep in mind this was my first try. <br> <br> During this article I will try to explain as best as I can my efforts in creating and then finding an audience for one of our most popular kits: the Paper Kit. I will try to give as much details as possible, so the result is like this picture describing how to draw a horse:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*up-BW__Z65szz39oDWcYZw.jpeg" /></figure><p>A couple of years ago I saw a quote on twitter. It goes like this: “Give me six hours to chop down a tree and I will spend the first four sharpening the axe.” It is attributed to Abraham Lincoln. This made a lot of sense for me and really changed my perspective on the way I approach work.<br> <br> I used to be a really get-shit-done kind of person, powering through the tasks. Over my years of work I have learnt to be more patient, sharpen my axe. How does this translate to developing and UI Kit? Basically, research. Before writing any line of code I have inspected all UI Kits I found on the internet.<br> <br> Markets such as <a href="https://themeforest.net/">ThemeForest</a> and <a href="http://bootstrapbay.com/">BootstrapBay</a> have a great variety of themes. Most of them are built for a specific purpose. They usually do a great job if you are trying to build a specific presentation site. But we wanted to build something that a back-end developer can use with a complex project. So we shifted my attention towards real complex sites like <a href="https://www.airbnb.com/">Airbnb</a>, <a href="http://uber.com/">Uber</a>, <a href="https://twitter.com/">Twitter</a>, <a href="https://www.fiftythree.com/">Paper53</a> etc. What elements do they use? What design do they prefer?</p><h3>The elements</h3><p>After going through a lot of sites with different purposes: presentation, portfolio, social, we came up with the list of the elements that are the core:</p><ul><li>buttons</li><li>inputs</li><li>checkbox/radio</li><li>navigation</li><li>dropdown</li><li>progress bars/sliders</li><li>menus</li><li>typography</li><li>images</li><li>notifications</li><li>labels</li><li>carousel</li></ul><p>These cover over 90% of the functionality you need to build a page.</p><h3>Design and Development</h3><p>One of the biggest trends in design at the moment were Material and the iOS flat look. I really liked those, but they weren’t my style. I wanted to build something playful, fun, easy to follow. I went on a lot of mediums for designers, like <a href="https://dribbble.com/">Dribbble</a> and <a href="https://www.behance.net/">Behance</a>. But I eventually settled on the design of some really cool sites that I used myself: <a href="http://www.fiftythree.com/paper">Paper 53</a> and <a href="https://www.headspace.com/">Headspace</a>. I thought they looked great and they had a really calming effect when you navigated them.<br> <br> So I created a colour palette with 6 colours, to cover the basic classes for <a href="http://getbootstrap.com/">Bootstrap</a>. All backgrounds are trying to resemble sheets of paper and the animations are meant to imitate the movements of a piece of paper. For the fonts I went with a free font offered by Google Fonts. It’s called <a href="https://fonts.google.com/specimen/Montserrat">Montserrat</a>. <br> <br> A kit can be very useful but often people don’t understand how to use it. So I created 3 example pages: a <a href="http://demos.creative-tim.com/paper-kit/register">Login</a>, a <a href="http://demos.creative-tim.com/paper-kit/profile">Profile</a> and a <a href="http://demos.creative-tim.com/paper-kit/landing-page">Landing Page</a> to show what you can build with it. People could also use them directly when building their projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oikoVdeD-xuBjsy8TaCXJQ.jpeg" /><figcaption>Register Page made with Paper Kit</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YUYN9ULfuNSWPgSezgnOXQ.jpeg" /><figcaption>Profile Page made with Paper Kit.</figcaption></figure><p>The development meant creating SASS files for every components. These Sass files were compiled to CSS and added after Bootstrap. So, someone who already has a Bootstrap project can just add the custom files and get the new design. The Javascript modifications were minimal since we only played with the default animations for some of the default elements in Bootstrap.<br> <br> After developing the elements, we tested them on all browser and device screens. A great tool to do this is <a href="http://ami.responsivedesign.is/">this</a>. And the final part of adding the images. I got in touch with some of my fav artists on Paper 53 and asked them if it is ok to use their drawings. And they were happy to do so :)<br> <br> The good news is that making all the former preparations led to a total development time of 3weeks. Iuhuu!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*flJWOawW-0HAjGjXQ7KUAQ.png" /></figure><h3>Promotion</h3><p>When everything was ready, we have posted the kit on Paper Kit. We have also shared the kit with a couple of friends so they could let us know if they found any bugs we missed. When everything got the green light, we did some inbound email marketing campaigns announcing the kit (to the users already subscribed on Creative Tim). The feedback was positive so we reached out to some communities. We got great responses on Hacker News, Product Hunt, Reddit. Even more, some picked it up and used it for their own work. Take example Chris Pena, who did a <a href="https://www.youtube.com/watch?v=1bDJjbiHG-0">video tutorial</a> with it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S82VmwJMXhuTeiG3KF7W8w.png" /><figcaption>Paper Kit offered as a free download on Creative Tim.</figcaption></figure><p>Since most of the items we used to create the kit were open-source we thought it was only fair we also release it for everyone for free. So we created <a href="https://github.com/creativetimofficial/paper-kit">a repo on GitHub</a> and everyone can contribute to it.</p><h3>Maintenance</h3><p>After lauching it, we discovered new things we had to take care of.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RVAinr8gEsE4Neds1wsVkA.jpeg" /></figure><p>The best way for us to sustain our activity moving forward was making a <a href="https://www.creative-tim.com/product/paper-kit-pro">PRO version</a> that users will be able to pay for. So we looked back to the features we overlooked when we first made the plan for the kit. We took those elements and built a bigger pack. The product was a hit and a lot of the people that used the free kit were happy to upgrade and develop their products even more easily.<br> <br> This gave us the time to also develop a dashboard with the same design. This integrates nicely for the back-end. So, if you are building your presentation and the part that the user interacts with using the Paper kit; the <a href="https://www.creative-tim.com/product/paper-dashboard">Paper Dashboard</a> makes for a great admin. We have also open-sourced it and received positive reviews.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*UYNN6BOvBFxDwXsUCxxH6Q.jpeg" /><figcaption>Paper Dashboard</figcaption></figure><p>In the future, we plan on creating more versions for the product. The Sketch is already available and we are also building the PSD version. We have started creating the Angular version, this is one of the biggest request from our users. And we are looking into ReactJS, VueJS, etc.</p><p>If you are interested in collaborating with us, send me an email at cristina@creative-tim.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a0465358b8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bucharestjs/how-to-build-and-market-a-successful-ui-kit-6a0465358b8">How to Build and Market a Successful UI Kit</a> was originally published in <a href="https://medium.com/bucharestjs">BucharestJS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>