<?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 Roi Giladi on Medium]]></title>
        <description><![CDATA[Stories by Roi Giladi on Medium]]></description>
        <link>https://medium.com/@roygiladix?source=rss-cbffa4fa380e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0ja7cYs2RKSLXKQ-8wVmPg.jpeg</url>
            <title>Stories by Roi Giladi on Medium</title>
            <link>https://medium.com/@roygiladix?source=rss-cbffa4fa380e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 21:42:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@roygiladix/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[How To Build a Web Application with Stencil, Web Components and Redux — Part 1]]></title>
            <link>https://medium.com/@roygiladix/how-to-build-a-web-application-with-stencil-web-components-and-redux-2b30fd6842c8?source=rss-cbffa4fa380e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b30fd6842c8</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[web-components]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[stenciljs]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Roi Giladi]]></dc:creator>
            <pubDate>Fri, 20 Jul 2018 19:47:21 GMT</pubDate>
            <atom:updated>2018-07-31T09:32:29.837Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://roygil.github.io/stencil-books-app/">Demo</a> &amp; <a href="https://github.com/royGil/stencil-books-app">Code</a></p><p>This tutorial is much more focused on demonstrating how to actually write a full working web app with <strong>Stencil </strong>then about the library itself.</p><p>I’ve found <a href="https://stenciljs.com/docs/introduction/">Stencil Docs</a> to be so straightforward and easy to understand that it will be a waste of time to rewrite explanations all over again…</p><p><em>I will cover the basics though so you don’t need any previous knowledge to jump right in!</em></p><p>If you do want a more general, details-orientated tutorial about Stencil (and Web Components) then check out the following resources:</p><ul><li><a href="https://www.joshmorony.com/building-a-pwa-with-stencil-an-introduction-to-stencil/">Building a PWA with Stencil</a></li><li><a href="https://www.codementor.io/ayushgupta/vanilla-js-web-components-chguq8goz">HTML Web Components using Plain JavaScript</a></li><li><a href="https://medium.com/@gilfink/why-im-betting-on-web-components-and-you-should-think-about-using-them-too-8629396e27a">Why I’m Betting on Web Components (and You Should Think About Using Them Too</a></li></ul><h3>What is Stencil?</h3><p>Stencil is a library that extends the native custom-elements API and simplify the whole process of writing fast and powerful web components.</p><p>What so special about it is that it’s actually a <strong>compiler</strong> so everything you do with it will eventually compile back to a native API so you can use your components anywhere without the need to import yet another library into your projects!</p><p><em>The official docs contains a short </em><a href="https://stenciljs.com/docs/introduction"><em>introduction</em></a><em> so check it out!</em></p><h3>Writing Our First Components</h3><p>Stencil is focused heavily on creating reusable web-components but that doesn’t mean we can’t write full web apps entirely with it.</p><p>The truth is that there is actually a wide set of tools (like out of the box SSR, prerendering and a simple router) that can be used together to build powerful and fast apps.</p><p>Today we’ll create an app that will allow us to search books via google’s books API and save those that looks interesting (check the demo above)</p><p>Let’s code! 🚀</p><p>We will take advantage of a starter app provided by Stencil so we can avoid a lot of boilerplate.</p><pre>npm init stencil // pick &quot;app&quot; starter<br>npm run start</pre><p>I’m not going to examine the starter app as it is pretty obvious what’s happening there, just note that after you’ll start the app, stencil will watch your working directory and every file that has a class decorated with <strong><em>@Component</em></strong> will automatically be registered as a custom element (more on that later).</p><p>Now, we want to have 2 pages in our app, one for searching books and another to display the list of the books we’ve saved.</p><p>First we have to install the router</p><pre>npm install @stencil/router --save</pre><p>then edit the <strong>app-root </strong>component to</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d45f9b64d94cdb04524d0299197a85e7/href">https://medium.com/media/d45f9b64d94cdb04524d0299197a85e7/href</a></iframe><p>Every component in stencil is decorated with a <strong>Component </strong>decorator that takes two properties:</p><ol><li><strong>tag </strong>the html tag that represents the component (which gets registered as a custom-element by Stencil)</li><li><strong>styleUrl </strong>that takes a path to a css file related to the component (note that there is also a <a href="https://stenciljs.com/docs/add-ons">plugin</a> to support sass).</li></ol><p><strong><em>For the sake of keeping this tutorial short, I’ve put all the css in one global file you can find </em></strong><a href="https://github.com/royGil/stencil-books-app/blob/master/src/global/app.css"><strong><em>here</em></strong></a></p><p>Then, much like in React, our component will have a render function that returns JSX. <br>We then wrap our whole app inside a <strong>stencil-router</strong> tag, add 2 links with <strong>stencil-router-link</strong> and two<strong> stencil-route</strong> components which based on the current url will render the component specified in the <strong>component</strong> <strong>attribute</strong>.</p><p>Now we have to actually write the components for the pages, we’ll start with <strong>app-home</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7293ebb1a4e07c248ec6c3b76fb5b9fd/href">https://medium.com/media/7293ebb1a4e07c248ec6c3b76fb5b9fd/href</a></iframe><p>All we do here is rendering two components:</p><p><strong>search-box</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6be00312b4403b3705631c5e8ddc1175/href">https://medium.com/media/6be00312b4403b3705631c5e8ddc1175/href</a></iframe><p>Here we are using another decorator provided by Stencil called <strong>State </strong>which is used to manage the internal state of our component (internal since it cannot be modified/accessed from outside of the component).</p><p>So all this component does right now is just a typical two-way data binding — whenever the input element changes, the <strong>onInput</strong> event calls <strong>handleChange</strong> which then updates the internal <strong>value </strong>property.<br>We also call the <strong>search </strong>function when the button is clicked (we will write the actual API call in a second).<br>Note that whenever a <strong>State</strong> property changes, the <strong>render </strong>function<strong> </strong>runs again.</p><p><em>onInput is the equivalent of onChange/ng-model/v-model in react/angular/vue</em></p><p><strong>books-list</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c22e110fd556e2219ed7aacd72ba2598/href">https://medium.com/media/c22e110fd556e2219ed7aacd72ba2598/href</a></iframe><p>Here we are using yet another decorator called <strong>Prop </strong>which is exactly the same as<strong> State </strong>with the difference that it <strong>can</strong> be modified/accessed from outside of the component (in the next chapter we’ll see how it can be useful)</p><p>This component is currently responsible only for rendering an array of books (that will get populated with the results of an API call we’ll make in a second).</p><p>Since components are pretty much the standard this days, it’s recommended (regardless of a framework) that you try as much as possible to separate logic from presentation in your components.<br>So we’ll try to follow that rule by using redux (not always the perfect solution but I wanted to demonstrate how to use it)</p><h3>Adding Redux</h3><p><em>If you are not familiar with the concept of redux, just google it up and then continue (</em><a href="https://dev.to/hemanth/explain-redux-like-im-five"><em>here</em></a><em> is a good introduction)</em></p><pre>npm i redux @stencil/redux redux-thunk<br>// redux-thunk is a middleware for making asynchronous actions in redux.</pre><p>The team behind Stencil created a small library we will use to connect redux to our app, it’s very simple and you can <a href="https://github.com/ionic-team/stencil-redux">check the source</a> to better understand what it does.</p><p>We’ll start by creating a very typical redux store.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef35d05cbfb2cce866eb978944ee4dc6/href">https://medium.com/media/ef35d05cbfb2cce866eb978944ee4dc6/href</a></iframe><p>multiple actions responsible for searching books</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a13470430f17860f1868621c7725f449/href">https://medium.com/media/a13470430f17860f1868621c7725f449/href</a></iframe><p>and a simple reducer</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/acdc33c2d7a9de7b5a7790d0a88f2ffc/href">https://medium.com/media/acdc33c2d7a9de7b5a7790d0a88f2ffc/href</a></iframe><p>Awesome, now lets add it to our app!</p><p>Like React, Stencil provides several <a href="https://stenciljs.com/docs/component-lifecycle"><strong>life cycles</strong></a><strong> </strong>that we can take advantage of in our components.</p><p>We’ll initialize our store in the root component’s <strong>componentWillLoad </strong>life cycle which gets called once before the first render and is where we can do stuff before anything else happens.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/92c63f917da03db9dcdc8ab80c7f5adc/href">https://medium.com/media/92c63f917da03db9dcdc8ab80c7f5adc/href</a></iframe><p>We start by importing the <strong>Prop </strong>decorator, <strong>Store </strong>type (this is a TypeScript thing, you can ignore/google it) and the <strong>configureStore </strong>function we’ve created earlier.</p><p>We are then met with another new Stencil’s concept called <strong>context </strong>which is just a global object which can be used to store global variables that you can bind to components in your app (by installing stencil/redux a <strong>store</strong> context is automatically available for us).</p><p>Now that our store is ready, lets bring it our components.</p><p>We’ll start with the <strong>search-box </strong>component. Once again, we’ll bind the <strong>store context</strong> to our component and initialize things in the <strong>componentWillLoad</strong> life cycle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4914fe6b026ba80bc3740e3a19e7ab75/href">https://medium.com/media/4914fe6b026ba80bc3740e3a19e7ab75/href</a></iframe><p><em>Note that </em><em>stencil/redux provides another type called </em><strong><em>Action</em></strong><em>.</em></p><p>I assume that you are familiar with the <strong>mapDispatchToProps</strong> function but if not then this is just a function that connects actions to our store and then maps them to properties of our component (that’s just a redux thing…).</p><p>You can confirm that it is working by opening the Network tab in the devtools and search something!</p><p>Now that we have data to work with, we can pass it to the <strong>books-list </strong>component.</p><p>Remember how earlier we’ve used the <strong>Prop</strong> decorator instead of <strong>State</strong>?<br>This can help us keep our components agnostic about the source of the data they render which is good for <a href="https://en.wikipedia.org/wiki/Separation_of_concerns"><strong>separation of concerns</strong></a><strong> </strong>(an important design pattern in software development).</p><p>So instead of getting the data inside the <strong>books-list </strong>component, we’ll pass it from the parent (<strong>app-home</strong>)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69ea9dcaf9b4ab6fb93e00b8505875d2/href">https://medium.com/media/69ea9dcaf9b4ab6fb93e00b8505875d2/href</a></iframe><p>Note that we have 2 new decorators here:</p><p><strong>Element</strong> —<strong> </strong>has one purpose and it is to get a reference for the actual DOM element this component renders.</p><p><strong>Watch </strong>— also has one purpose which is to run the decorated function whenever there is a change to a property’s value (the <em>books</em> property in this case).</p><p>So what’s happening here is that we are mapping <strong>books.items </strong>from our redux store to the <strong>books </strong>property in our component and whenever it changes, the <strong>updateList </strong>runs and updates the <strong>books </strong>property of the <strong>books-list </strong>component.</p><p>You might have noticed that we’ve used <strong>componentDidLoad </strong>and not <strong>componentWillLoad </strong>here,<strong> </strong>the reason is that <strong>mapStateToProps </strong>will cause <strong>updateList </strong>to run before the component has rendered for the first time hence this.el.querySelector(&#39;books-list&#39;) will return <em>null </em>and an error will be thrown.</p><p>If you haven’t tried already — open the app, search something and you’ll see the results on the screen!</p><p>In the 2nd part we’ll write the rest of the app (the ability to save/remove books) but note that until now we’ve covered the most important concepts of Stencil:</p><ul><li><strong>Decorators</strong></li><li><strong>Life Cycles</strong></li><li><strong>Context</strong></li><li><strong>Routing</strong></li><li><strong>Two-way data binding</strong></li><li><strong>Integration with Redux</strong></li></ul><p>If you are feeling comfortable enough, I encourage you to try and build the save/remove functionality yourself.</p><p>Hope that was useful, the next part will be available soon!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b30fd6842c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Meteor With React And Webpack]]></title>
            <link>https://medium.com/@roygiladix/meteor-with-react-and-webpack-77cf30022fce?source=rss-cbffa4fa380e------2</link>
            <guid isPermaLink="false">https://medium.com/p/77cf30022fce</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[2018]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[meteor]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Roi Giladi]]></dc:creator>
            <pubDate>Sun, 29 Apr 2018 02:01:35 GMT</pubDate>
            <atom:updated>2018-05-12T00:46:22.160Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Last updated on April 29, 2018.</strong></p><p>This is a step by step tutorial of setting up a meteor application using react, webpack and jest (with enzyme)</p><p>For this tutorial I have used:</p><ul><li>Meteor 1.6.1</li><li>Webpack 4.6.0</li><li>React 16.3.2 (with react-hot-loader)</li><li><a href="https://github.com/ardatan/meteor-webpack">ardatan:webpack</a></li><li>Jest 22.4.3</li></ul><p>Lets start by creating our application folder</p><pre>meteor create --bare app</pre><pre>// using --bare will generate only the necessary files that are required by meteor.</pre><p>Since we are going to use webpack as our compiler, we can get rid of meteor’s default compiler packages.</p><pre>meteor remove ecmascript es5-shim static-html</pre><p>At this point, we cant really do anything in our application so lets fix that by adding webpack</p><pre>meteor npm install --save-dev webpack webpack-dev-middleware webpack-hot-middleware webpack-meteor-externals html-webpack-plugin css-loader style-loader</pre><pre>// and the following packages which connect webpack with meteor<br>meteor add ardatan:webpack ardatan:webpack-dev-middleware</pre><p>babel</p><pre>meteor npm install babel-core babel-loader babel-preset-env babel-preset-react babel-preset-stage-2</pre><p>and react</p><pre>meteor npm install react react-dom react-hot-loader</pre><p>Running the application now will throw an error:</p><pre>Error: Cannot find module &#39;/home/roy/app/webpack.config.js&#39;</pre><p>lets fix that:</p><p>Create a webpack.config.js file:</p><pre>// webpack.config.js</pre><pre>const webpack = require(&#39;webpack&#39;);<br>const HtmlWebpackPlugin = require(&#39;html-webpack-plugin&#39;);<br>const meteorExternals = require(&#39;webpack-meteor-externals&#39;);</pre><pre>const clientConfig = {<br>    entry: &#39;./client/main.js&#39;,<br>    module: {<br>      rules: [<br>        {<br>          test: /\.(js|jsx)$/,<br>          exclude: /node_modules/,<br>          use: [&#39;babel-loader&#39;]<br>        },<br>        {<br>          test: /\.css$/,<br>          use: [ &#39;style-loader&#39;, &#39;css-loader&#39; ]<br>        }<br>      ]<br>    },<br>    plugins: [<br>      new HtmlWebpackPlugin({<br>          template: &#39;./client/main.html&#39;<br>      }),<br>      new webpack.HotModuleReplacementPlugin()<br>    ],<br>    resolve: {<br>      extensions: [&#39;*&#39;, &#39;.js&#39;, &#39;.jsx&#39;]<br>    },<br>    output: {<br>      path: __dirname + &#39;/dist&#39;,<br>      publicPath: &#39;/&#39;,<br>      filename: &#39;bundle.js&#39;<br>    },<br>    devServer: {<br>      contentBase: &#39;./dist&#39;,<br>      hot: true<br>    },<br>    externals: [<br>      meteorExternals()<br>    ]<br>};</pre><pre>const serverConfig = {<br>    entry: [<br>        &#39;./server/main.js&#39;<br>    ],<br>    target: &#39;node&#39;,<br>    externals: [<br>      meteorExternals()<br>    ]</pre><pre>};</pre><pre>module.exports = [clientConfig, serverConfig];</pre><p>and a .babelrc file:</p><pre>// .babelrc</pre><pre>{<br>  &quot;presets&quot;: [<br>    &quot;env&quot;,<br>    &quot;react&quot;,<br>    &quot;stage-2&quot;<br>  ],<br>  &quot;plugins&quot;: [&quot;react-hot-loader/babel&quot;]<br>}</pre><p>Don’t forget to create server/main.js, client/main.js,client/main.html* and a .meteorignore file, so we can prevent meteor from loading unnecessary files</p><pre>// .meteorignore</pre><pre>*<br>!.meteor/<br>!node_modules/<br>!webpack.config.js</pre><p><em>*Note that main.html must contain simple head and body tags</em></p><p>It’s working, we can now run our app and it will be bundled by webpack!<br><em>(If you see an error related to the</em><em>require-from-string package, just install it)</em></p><p>We can now add a simple react component</p><pre>// client/ui/app.js</pre><pre>import { hot } from &#39;react-hot-loader&#39;<br>import React, { Component } from &#39;react&#39;</pre><pre>class App extends Component {</pre><pre>render () {<br>    return (<br>      &lt;div&gt;Hello World&lt;/div&gt;<br>    )<br>  }<br>}</pre><pre>export default hot(module)(App)</pre><p>and render it to the page</p><pre>// client/main.js</pre><pre>import React from &#39;react&#39;<br>import ReactDOM from &#39;react-dom&#39;<br>import { Meteor } from &#39;meteor/meteor&#39;</pre><pre>import App from &#39;./ui/app&#39;</pre><pre>Meteor.startup(() =&gt; {<br>  ReactDOM.render(<br>    &lt;App /&gt;,<br>    document.getElementById(&#39;root&#39;)<br>  )<br>})</pre><p><em>Everything should work perfectly by now, contact me or leave a comment below if not.</em></p><p>Lastly, lets add jest and enzyme so we can test our application.</p><pre>npm install --save-dev jest enzyme enzyme-adapter-react-16</pre><p>then create a setup file which is required by enzyme</p><pre>// tests/testsSetup.js</pre><pre>import * as enzyme from &quot;enzyme&quot;<br>import Adapter from &quot;enzyme-adapter-react-16&quot;</pre><pre>enzyme.configure({ adapter: new Adapter() });</pre><p>and instruct jest to use it.</p><pre>// jest.config.js</pre><pre>module.exports = {<br>  setupFiles: [&quot;&lt;rootDir&gt;/tests/testsSetup.js&quot;]<br>}</pre><p>That’s all you need! Lets write our first test now:</p><pre>// client/ui/app.test.js</pre><pre>import React from ‘react’<br>import { shallow } from ‘enzyme’<br>import App from ‘./app.js’</pre><pre>test(‘&lt;App /&gt; should render a Hello World div’, () =&gt; {<br>  const app = shallow(&lt;App /&gt;)</pre><pre>  expect(app.text()).toBe(‘Hello World’)<br>})</pre><p>Lastly, in your package.json add “test”: “jest” and run npm test</p><p>if everything was done correctly, the test should pass :)</p><p>If you did everything written above but still get an error please contact me or leave a comment below.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77cf30022fce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Meteor and React in 2018]]></title>
            <link>https://medium.com/@roygiladix/meteor-and-react-in-2018-391c81fcd753?source=rss-cbffa4fa380e------2</link>
            <guid isPermaLink="false">https://medium.com/p/391c81fcd753</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[meteor]]></category>
            <dc:creator><![CDATA[Roi Giladi]]></dc:creator>
            <pubDate>Fri, 27 Apr 2018 02:22:10 GMT</pubDate>
            <atom:updated>2018-04-29T13:04:51.851Z</atom:updated>
            <content:encoded><![CDATA[<p>When I first tried react in meteor It was hard finding up-to-date resources about the best practices out there for things like: webpack integration, testing, routing and redux among others.</p><p>This tutorial’s goal is to glue together all the pieces I have found about using react in meteor and to serve as a good starting point for new (but not only) developers who try out meteor in 2018.</p><p>This is what is gonna be covered:</p><p><a href="#20c0"><strong>Webpack integration</strong></a></p><p><a href="#5522"><strong>Testing with jest</strong></a></p><p><a href="#4723"><strong>React-Router vs Flow-Router</strong></a></p><p><a href="#72b9"><strong>Redux</strong></a></p><p><a href="#2773"><strong>Useraccounts for react</strong></a></p><p><a href="#d398"><strong>Recommended packages</strong></a></p><p>I must mention that <a href="https://docs.meteor.com/packages/server-render.html">SSR</a>, <a href="https://docs.meteor.com/packages/dynamic-import.html">Dynamic imports</a> (and <a href="https://github.com/jamiebuilds/react-loadable">React Loadable</a>) are supported out-of-the-box by meteor which means you don’t have to do anything special in order to use them!</p><h3>Webpack</h3><p>Over the years there were several attempts to integrate webpack with meteor. I wont go into details about each one but its good to mention them.</p><ul><li><a href="https://github.com/Urigo/meteor-client-bundler">Meteor Client Bundler</a> — This was actually working great but after trying it in several different ways i fount that it doesn’t <em>feel</em> right for me. It basically just bundles your client code (with meteor’s packages) so that you can use it wherever you’d like (with webpack for example) while running the server via Meteor’s CLI.</li><li><a href="https://github.com/thereactivestack-legacy/meteor-webpack/tree/master/packages/webpack">Meteor-Webpack</a> — This one is also working, but is not maintained anymore (for almost 2 years) so you can’t really use it. What it does is to replace meteor’s default compiler with webpack.</li><li><a href="https://github.com/jcoreio/crater">Crater</a>— I have not tried this project but it is not maintained anymore and probably not what you are looking for.</li></ul><p>All the projects above are interesting but are either not maintained or just doesn’t work with newer versions of meteor and webpack.</p><p>The solution i have found came as a meteor package called <a href="https://github.com/ardatan/meteor-webpack">ardatan:webpack</a><br>It’s just a replacement to meteor’s default compiler which uses webpack.</p><p><strong><em>I made a tutorial specifically for integrating meteor with webpack which you can find </em></strong><a href="https://medium.com/@roygiladix/meteor-with-react-and-webpack-77cf30022fce"><strong><em>here</em></strong></a><strong><em>.</em></strong></p><h3>Testing</h3><p>Follow <a href="https://medium.com/@arcomito/setting-up-jest-enzyme-in-a-meteor-js-and-apollo-project-9ceadbcf2fa3">this</a> tutorial.<br>It will help you understand the whole process of integrating jest and enzyme in meteor.</p><p>But just following the tutorial will probably introduce several configuration problems (as of the time of writing this tutorial):</p><ol><li>Setting up the .babelrc file as the tutorial suggests will cause meteor compiler to throw errors (if your application is running on the background)</li></ol><p>instead of</p><pre>{<br> “presets”: [“es2015”, “react”]<br>}</pre><p>use this</p><pre>{<br> “env”: {<br>   “test”: {<br>     “presets”: [“es2015”, “react”]<br>    }<br>  }<br>}</pre><p>This way, meteor will not try to load those presets when running the application. <br><em>Note: You’ll have to do this only if you are using meteor’s default compiler (i.e: not with webpack)</em></p><p>2. Configuring enzyme’s adapter is not included in the tutorial, so here is how to do it:</p><ul><li>Install the adapter</li></ul><p>npm install --save-dev enzyme-adapter-react-16</p><ul><li>Create a setup file for the tests</li></ul><pre>// tests/testsSetup.js</pre><pre>import * as enzyme from &quot;enzyme&quot;<br>import Adapter from &quot;enzyme-adapter-react-16&quot;</pre><pre>enzyme.configure({ adapter: new Adapter() });</pre><p>put that file inside a folder called tests so meteor will not try to load it when you run your application (you can also use a .meteorignore file)</p><ul><li>Configure jest to load the setup file before running the tests</li></ul><pre>// jest.config.js</pre><pre>module.exports = {<br> setupFiles: [&quot;&lt;rootDir&gt;/tests/testsSetup.js&quot;]<br>}</pre><p>3. Mocking meteor packages might be a little bit confusing when you are just starting out, you can find a great tutorial about the topic <a href="https://blog.meteor.com/real-world-unit-tests-with-meteor-and-jest-3d557e84e84a">here</a></p><p>4. Keep in mind that your whole UI testing will be much easier if you avoid doing things like calling Meteor.user() directly in your components. Instead, always try to pass a user object as a prop. <br>This approach will allow you to avoid mocking the user object (you’ll only have to pass it as a prop) and will also help you migrate from meteor easily if needed (you won’t have to change Meteor.user() calls all over your application)</p><h3>React-Router vs Flow-Router</h3><p>Short answer: React-Router(v4).</p><p>The latest version of react-router introduced a new concept of a “decentralized” router. Instead of having one file that controls your routes, in v4 your routes live inside and as part of your UI components.</p><p>This conceptual change has made react-router (in my opinion) a much better candidate for the router (if you prefer the old way, then flow router might be a good choice! check out <a href="https://github.com/VeliovGroup/flow-router">flow-router-extra</a></p><p>Here are some details about the two:</p><p><strong>React Router</strong></p><ul><li>The github repository has almost 30000 stars, maintained by 500+ contributors and has a bigger community support</li><li>Will probably evolve side by side with future versions of react</li><li>Writing your app with react-router will allow you to easily migrate your UI code to a non-meteor project.</li><li>The current version (v4) is using a much more react oriented approach (your routes are part of your components) which is way better for my opinion.</li></ul><p><strong>Flow Router</strong></p><ul><li>The original github repository has has only around 1100 stars and is not maintained anymore by the author.</li><li>Flow-Router-Extra is a fork of the original package which is actively maintained by a great group of guys called <strong>VeliovGroup</strong>.</li><li>Designed specifically for Meteor so you cant use it anywhere else.</li><li>If you prefer the <strong><em>one-file-router </em></strong>paradigm, you’ll have a great experience working with flow-router.<br>It has many cool features while still being straightforward and super easy to use (and learn)</li></ul><h3>Redux</h3><p>The best resource i have found on redux is an article by Aryan Goharzad that was written in 2016 but is still very relevant today.<br>You can find it <a href="https://www.okgrow.com/posts/where-does-redux-fit-in-meteor">here</a></p><h3>Useraccounts for react</h3><p>If this is not the first time you are trying out meteor, I guess that you have tried out the <a href="https://github.com/meteor-useraccounts/core">useraccounts</a> package, if not — it’s a package that automatically generates accounts related forms + gives you a the ability to configure things like custom fields, validation functions, texts and more or less anything related to the forms.</p><p>The problem I was facing and probably many others is that this package depends on blaze and jquery which are both useless when using react which means that our bundle size gets much bigger only to support 1 feature.</p><p>The only thing I have found is the <a href="https://github.com/studiointeract/accounts-ui">std:accounts-ui</a> package which was close but not what i was looking for, it is a react alternative to the accounts-ui package which doesn’t provide all the configuration options that useraccounts offers.</p><p>So I decided to create my own package which you can find <a href="https://github.com/royGil/accounts-react">here</a> (the repo contains a usage guide)<br>Feel free to ask for new features and contribute some code!</p><h3>Recommended packages</h3><p>The following is a list of all the packages that I’m always using in my projects alongside react:</p><ul><li><a href="https://atmospherejs.com/meteor/react-meteor-data">react-meteor-data</a> — Automatically detect changes via meteor’s tracker and re-render components.</li><li><a href="https://github.com/meteor/validated-method">validated-method</a> — Just a better way to define methods</li><li><a href="https://github.com/aldeed/meteor-collection2">collection2</a> — Attach a schema to your mongo collections and automatically validate against them upon insert/update.</li><li><a href="https://github.com/aldeed/simple-schema-js">simpl-schema</a> —Validate objects to ensure they match a schema.</li><li><a href="https://github.com/alanning/meteor-roles">meteor-roles</a> — Define permissions and roles for your users</li><li><a href="https://github.com/vazco/uniforms">uniforms</a> — Generate and validate forms automatically from your schemas.</li></ul><h3>Summary</h3><p>Meteor is awesome, and combining it with react creates a really powerful stack to work with, give it a shot!</p><p><em>I was thinking about a cli tool, something like create-meteor-react-app that you can use to generate a boilerplate with everything written above (with the option the pick only what you need). What do you think? would you be interested in developing such a thing?</em></p><p>Feel free to ask me anything: roygiladix@gmail.com</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=391c81fcd753" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>