{"id":36867,"date":"2021-06-23T21:42:20","date_gmt":"2021-06-24T01:42:20","guid":{"rendered":"http:\/\/b0xninjaz.net\/kk4kmo\/?p=36867"},"modified":"2021-06-23T21:53:25","modified_gmt":"2021-06-24T01:53:25","slug":"translating-dust-templates-to-jsx-center-regarding-8","status":"publish","type":"post","link":"http:\/\/b0xninjaz.net\/kk4kmo\/?p=36867","title":{"rendered":"Translating Dust templates to JSX  center regarding the ten years (affected by the javaScript fram that is endless"},"content":{"rendered":"<p><title>Translating Dust templates to JSX  center regarding the ten years (affected by the javaScript fram that is endless<\/title><\/p>\n<p>Hello Habr! I am Milo?? from Badoo, and also this is my very first Habr post, initially posted within our technology web log. Hope you enjoy it, and please share and remark when you yourself have any concerns<\/p>\n<p>So??\u00a6 React, amirite.<\/p>\n<p>It starred in the middle of the ten years (affected by the endless JavaScript framework wars), embraced the DOM, surprised everyone else by combining HTML with JavaScript and changed the net development landscape beyond recognition.<\/p>\n<p>Dozens of accomplishments, without even being truly a framework.<\/p>\n<p>Like it or hate it, React does one task very well, which is HTML templating. As well as  a healthier ecosystem, it is maybe maybe maybe  perhaps not difficult to realise why it became the most popular and influential JavaScript libraries, if you don&#8217;t typically the most popular certainly one of all.  <\/p>\n<h2>yeah, he said he *hates* javascript frameworks??\u00a6can you think that?<\/h2>\n<p> Right right right   Here within the Cellphone internet group, we don??\u2122t follow any strict JS frameworks &#8211; or at the least, any popular people &#8211; so we work with a mix of legacy and technologies that are modern. Although that really works well we wanted to alleviate this by reducing the number of ?\u00abmanual?\u00bb updates, increasing our code reuse and worrying less about memory leaks for us, manipulating DOM is usually hard, and.<\/p>\n<p>After some research, respond ended up being considered the best option and we also chose to opt for it.<\/p>\n<p>We joined up with Badoo in the center of this method. Having bootstrapped and labored on React projects previously, I happened to be conscious of its advantages and disadvantages in training, but migrating an adult application with billions of users is a very different challenge|challenge that is wholly various.<!--more--> <\/p>\n<p>Respond mixes HTML with JavaScript in a structure known as JSX. Though it seems like a template language, JSX is in fact simply  a syntax, or syntactic sugar in the event that you will, for React calls, really similar-looking to HTML.<\/p>\n<p>Our own HTML files had been well organised, &amp; most of  our rendering had been done since just as template.render() . Just how could we retain this purchase and ease of use while moving to respond? If you ask me, technical problems apart, one concept ended up being apparent: change our current telephone calls with JSX rule.<\/p>\n<p>After some planning that is initial provided it a spin and wrapped up a command-line tool that executes two easy things:<\/p>\n<ol>\n<li>Reads templates referenced in UI (JavaScript) file<\/li>\n<li>Substitute render( this is certainly template calls because of  the HTML content<\/li>\n<\/ol>\n<p>Needless to say, this could just go us halfway, because we might still need  to alter the html page manually. Taking into consideration  the amount and wide range of our templates, we knew that the most useful approach  could be one thing automatic. The first concept sounded  not difficult ??\u201d and it can be implemented if it can be explained.<\/p>\n<p>After demoing the first device to teammates, the feedback that is best   had been  there is certainly a parser available  for the templating language we used. This means than we could with regular expressions, for example that we could parse and translate code much easier. That??\u2122s whenever   knew that   work!<\/p>\n<p>Lo and behold, after a few times an instrument  came into existence to transform Dust.js HTML-like templates to JSX React rule. We used Dust,  however with a broad option of parsers, the method ought to be comparable for translating any kind of popular templating language.<\/p>\n<p> For lots  more details that are technical skip  towards the Open-source part below. We utilized tools like Esprima to parse JS rule, and a PEG.js parser generator to parse Dust templates.  within the really easiest of terms,  it is about translating this kind of template rule:<\/p>\n<p> to its JSX rule equivalent:<\/p>\n<p> See side-by-side comparison right here.<\/p>\n<h2> following this, our procedure had been pretty straightforward that is much. We immediately converted our templates from 1 structure to some other, and every thing worked as you expected ( many thanks, automatic evaluation).  To start  with, we preserved our old render( this is certainly template API   modifications separated.<\/h2>\n<p> needless to say, using this approach you nevertheless end up getting templates  rather than ???proper??? React components. The benefit that is real when you look at  the reality  that it is much easier,  if you don&#8217;t trivial,   to respond from templates which are currently JSX, generally by merely wrapping a template rule in a function call.<\/p>\n<p>It might seem:  you will want to compose templates that are new scratch rather? The brief response is that   absolutely nothing incorrect   old templates ??\u201d we merely had many of  them. In terms of rewriting them and dealing towards real componentisation, that??\u2122s a story that is different.<\/p>\n<p>Some might argue that the component model is merely another trend  that might pass,   why agree to it? It??\u2122s hard to anticipate, but one possible response is that  you don??\u2122t need certainly to. Until you find <a href=\"https:\/\/besthookupwebsites.net\/escort\/chico\/\">escort service in chico<\/a> the format that works best for your team if you iterate quickly, you can try out different options, without spending too much time on any of them. That??\u2122s certainly one of the core concepts   at Badoo.<\/p>\n<p> Aided by  the rise of ES7\/8\/Next, Elm and factor,  and undoubtedly TypeScript and comparable solutions, rule  that was once *.js is becoming increasingly more indistinguishable from JavaScript, and therefore trend seems  like  it is set  . Rather than being overrun by it, have you thought to make use of that   benefit?<\/p>\n<h2>Start supply<\/h2>\n<p> When you look at  the character  of doing a very important factor well, we??\u2122ve built these tools that are internal a few components:<\/p>\n<ol>\n<li>dust2jsx ??\u201d package  accountable for real Dust to JSX interpretation<\/li>\n<li> ratt (React All the plain things) ??\u201d command line device for reading\/writing files on disk. In charge of including referenced templates, and makes use of dust2jsx internally to transform rule<\/li>\n<\/ol>\n<p>We??\u2122ve even open-sourced these tools ??\u201d  make sure to always check them down, and also other open-source materials on our GitHub web page. Please add or simply just keep us a remark them useful if you find.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Translating Dust templates to JSX center regarding the ten years (affected by the javaScript fram that is endless Hello Habr! I am Milo?? from Badoo, and also this is my very first Habr post, initially posted within our technology web log. Hope you enjoy it, and please share and remark when you yourself have any <a class=\"read-more\" href=\"http:\/\/b0xninjaz.net\/kk4kmo\/?p=36867\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/b0xninjaz.net\/kk4kmo\/index.php?rest_route=\/wp\/v2\/posts\/36867"}],"collection":[{"href":"http:\/\/b0xninjaz.net\/kk4kmo\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/b0xninjaz.net\/kk4kmo\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/b0xninjaz.net\/kk4kmo\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/b0xninjaz.net\/kk4kmo\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=36867"}],"version-history":[{"count":1,"href":"http:\/\/b0xninjaz.net\/kk4kmo\/index.php?rest_route=\/wp\/v2\/posts\/36867\/revisions"}],"predecessor-version":[{"id":36868,"href":"http:\/\/b0xninjaz.net\/kk4kmo\/index.php?rest_route=\/wp\/v2\/posts\/36867\/revisions\/36868"}],"wp:attachment":[{"href":"http:\/\/b0xninjaz.net\/kk4kmo\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=36867"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/b0xninjaz.net\/kk4kmo\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=36867"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/b0xninjaz.net\/kk4kmo\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=36867"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}