{"id":11502,"date":"2021-07-27T13:11:11","date_gmt":"2021-07-27T13:11:11","guid":{"rendered":"http:\/\/capitolmall.mk\/?p=11502"},"modified":"2021-07-27T13:20:56","modified_gmt":"2021-07-27T13:20:56","slug":"translating-dust-templates-to-jsx-center-regarding-2","status":"publish","type":"post","link":"https:\/\/capitolmall.mk\/translating-dust-templates-to-jsx-center-regarding-2\/","title":{"rendered":"Translating Dust templates to JSX  center regarding the ten years (affected by the endless JavaScript fram"},"content":{"rendered":"<p><title>Translating Dust templates to JSX  center regarding the ten years (affected by the endless JavaScript fram<\/title><\/p>\n<p>Hello Habr! i am Milo\u0161 from Badoo, and also this is my Habr that is first post originally posted inside our technology weblog. Hope you enjoy it, and please share and remark for those who have any queries<\/p>\n<p>So\u2026 React, amirite.<\/p>\n<p>It starred in the center of the ten years (suffering from the endless JavaScript framework wars), embraced the DOM, surprised everyone else by blending HTML <a href=\"https:\/\/besthookupwebsites.org\/escort\/hialeah\/\"><img decoding=\"async\" src=\"https:\/\/top1bisexualplayground.files.wordpress.com\/2017\/12\/tumblr_ouplpexm7w1w22dtko1_500-1.jpg?w=1200\" alt=\"\"><\/a> with JavaScript and changed the internet development landscape beyond recognition.<\/p>\n<p>Dozens of accomplishments, without also being  a framework.<\/p>\n<p>Like it or hate it, React does one task very well, which is HTML templating. Along with  a healthier ecosystem, it is  maybe  perhaps  not difficult to realise why it became probably the most popular and influential JavaScript libraries, if you don&#8217;t the most famous certainly one of all.<!--more-->  <\/p>\n<h2>yeah, he said he *hates* javascript frameworks\u2026can you think that?<\/h2>\n<p>    right  Here into the mobile phone internet group, we don\u2019t follow any strict JS frameworks &#8211; or at the very least, any popular people &#8211; so we make use of mix of legacy and modern technologies. 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 had been considered the choice that is best and then we chose to opt for it.<\/p>\n<p>We joined up with Badoo in the exact middle of this technique. Having bootstrapped and labored on React projects previously, I became conscious of its advantages and disadvantages in training, but migrating an adult application with vast sums of users is an entirely various challenge|challenge that is completely various. <\/p>\n<p>Respond mixes HTML with JavaScript in a structure known as JSX. If you will, for React calls, very similar-looking to HTML although it looks like a template language, JSX is actually just a syntax, or syntactic sugar.<\/p>\n<p>Our own HTML files had been well organised, &#038; most of y our rendering had been done since just as template.render() . Just how could we retain this purchase and simpleness while going to respond? If you ask me, technical problems apart, one concept had been apparent: change our current telephone calls with JSX rule.<\/p>\n<p>After some planning that is initial offered it   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 template.render() calls because of  the HTML content<\/li>\n<\/ol>\n<p> needless to say, this will just go us halfway, because we might nevertheless need certainly  to change the html page manually. Taking into consideration  the amount and wide range of our templates, we knew that the most readily useful approach will be one thing automatic.   concept sounded not difficult \u2014 and if it could be explained, it could be implemented.<\/p>\n<p>After demoing   device to teammates, the most readily useful feedback   ended up being that there surely is a parser readily available  for the templating language we used. Which means that people could parse and convert rule a lot easier than we&#8217;re able to with regular expressions, as an example. That\u2019s whenever i truly knew that this will work!<\/p>\n<p>Lo and behold, after a few times  an instrument  had become to transform Dust.js HTML-like templates to JSX React rule. We utilized Dust, however with an extensive  accessibility  of parsers, the method must certanly be comparable for translating some other popular language that is templating.<\/p>\n<p> For   more details that are technical skip to your Open-source part below. We utilized tools like Esprima to parse JS rule, and a PEG.js parser generator to parse Dust templates. Into 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 was pretty much simple. We immediately converted our templates in one structure to a different, and every thing worked  needlessly to say ( many thanks, automatic screening). To start with, we preserved our old render( that is template API   changes isolated.<\/h2>\n<p>Needless to say, with this particular approach you nevertheless end up getting templates  rather than \u201cproper\u201d React components. The genuine advantage is within  the undeniable fact  that it is much easier,  if perhaps not trivial,   to respond from templates which are currently JSX, generally by merely wrapping a template rule in a function call.<\/p>\n<p>You may think: have you thought to compose templates that are new scratch rather? The quick response is that there is nothing incorrect with this old templates \u2014 we just had plenty of  them. In terms of rewriting them and dealing towards true componentisation, that\u2019s a different story.<\/p>\n<p>Some might argue that the component model is merely another trend which may pass, so just  why agree to it? It\u2019s hard to anticipate, but one feasible response is which  you don\u2019t  need to. Until you find 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\u2019s certainly one of the core concepts   at Badoo.<\/p>\n<p> Aided by  the rise of ES7\/8\/Next, Elm and factor, as well as TypeScript and solutions that are similar rule which was once *.js is becoming increasingly more indistinguishable from JavaScript, and therefore trend appears  like it is set  .  As opposed to being overrun by it,  have actually you considered to make use of that   benefit?<\/p>\n<h2>Start supply<\/h2>\n<p> When you look at  the character of performing the one thing well, we\u2019ve built these interior tools in a few components:<\/p>\n<ol>\n<li>dust2jsx \u2014 package  accountable for real Dust to JSX interpretation<\/li>\n<li> ratt (respond all the stuff) \u2014 command line device for reading\/writing files on disk.  In charge of including referenced templates, and utilizes dust2jsx internally to transform rule<\/li>\n<\/ol>\n<p>We\u2019ve even open-sourced these tools \u2014 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 endless JavaScript fram Hello Habr! i am Milo\u0161 from Badoo, and also this is my Habr that is first post originally posted inside our technology weblog. Hope you enjoy it, and please share and remark for those who have any queries So\u2026 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[429],"tags":[],"_links":{"self":[{"href":"https:\/\/capitolmall.mk\/wp-json\/wp\/v2\/posts\/11502"}],"collection":[{"href":"https:\/\/capitolmall.mk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/capitolmall.mk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/capitolmall.mk\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/capitolmall.mk\/wp-json\/wp\/v2\/comments?post=11502"}],"version-history":[{"count":1,"href":"https:\/\/capitolmall.mk\/wp-json\/wp\/v2\/posts\/11502\/revisions"}],"predecessor-version":[{"id":11503,"href":"https:\/\/capitolmall.mk\/wp-json\/wp\/v2\/posts\/11502\/revisions\/11503"}],"wp:attachment":[{"href":"https:\/\/capitolmall.mk\/wp-json\/wp\/v2\/media?parent=11502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/capitolmall.mk\/wp-json\/wp\/v2\/categories?post=11502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/capitolmall.mk\/wp-json\/wp\/v2\/tags?post=11502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}