{"id":16447,"date":"2017-03-21T12:00:21","date_gmt":"2017-03-21T16:00:21","guid":{"rendered":"http:\/\/webdevstudios.com\/?p=16447"},"modified":"2024-04-15T12:01:25","modified_gmt":"2024-04-15T16:01:25","slug":"javascript-reusable-components-api","status":"publish","type":"post","link":"https:\/\/webdevstudios.com\/2017\/03\/21\/javascript-reusable-components-api\/","title":{"rendered":"JavaScript: Reusable Components and API"},"content":{"rendered":"<p>Over the past year, I have been working very hard to learn JavaScript deeply. I have even purposefully taken the\u00a0approach to learn it outside of the WordPress ecosystem. Why? Because it promotes exploring and learning different techniques that you can then take and apply to WordPress!<\/p>\n<p>The purpose of this post is to try and provide a different approach to building <em>a thing<\/em>. In this case, that <em>thing<\/em>\u00a0will be a modal UI component. Yes, another modal! There are many facets of JavaScript that I love and building UI components is one of them.<\/p>\n<p>It&#8217;s important to note\u00a0what I stated above. We will be looking at a different approach, not a new one. While the example I will be using\u00a0is written in ES2015 there&#8217;s nothing new or groundbreaking about it.\u00a0It just might take a different approach than what you might normally see.<\/p>\n<p>On many of the projects we work on here at WDS, there is almost always a requirement\u00a0to have at least one modal and in some\u00a0cases even multiple modals on the same page. While this may seem simple to implement, there are a lot of questions and observations that should be taken into consideration.<\/p>\n<ul>\n<li>What is going to be the trigger for opening a\u00a0modal?<\/li>\n<li>If there are multiple modals on one page, then we will need multiple, unique triggers.<\/li>\n<li>What will be the close trigger for each of the modals?<\/li>\n<li>What will be the contents of the modals?<\/li>\n<li>Will the content be created on the fly, or\u00a0will it be markup that has already been rendered to the page but is just hidden?<\/li>\n<li>How can we nicely present the modal?<\/li>\n<li>Implementing a nice animation into a modal can be tricky!<\/li>\n<li>Do you need to apply a CSS\u00a0class to another element on the page when the modal is open and the remove it when the modal is closed?<\/li>\n<\/ul>\n<p>In a lot of cases, a typical approach would be to create a JavaScript module or file for the particular project you are working on and code a solution to meet the requirements\u00a0for that project. Then two months later when a new project starts, you follow the same process and re-code something new to meet the requirements of the new project.<\/p>\n<p>What I&#8217;m trying to point out here is that the modal we&#8217;ve ended up writing is not very reusable from project to project. Sure, you might be able to take bits and pieces of code and move them from project to project, but in the end, you are creating a unique solution for each new project.<\/p>\n<p>Let&#8217;s explore a different approach! One that would allow for code reuse across projects.<\/p>\n<h3>Building Reusable Components<\/h3>\n<p>The concept that I&#8217;d like to drive home in this post is to start thinking about building reusable components that are powered by their\u00a0API. I&#8217;ve really learned a lot about this concept by learning\u00a0React and Redux. Feel free to check out the\u00a0experimental <a href=\"https:\/\/github.com\/efuller\/modern-wp-with-react\">WordPress theme I built using React and Redux<\/a>.<\/p>\n<p>You don&#8217;t need to be using any fancy frameworks in order to implement the idea of building reusable components. To be honest, the thought of having\u00a0a UI component such as a modal that has default options you can override and callback functions you can tap into is super exciting!<\/p>\n<p>For this post, we are going to focus on building a modal UI component in vanilla ES2015 that is reusable.\u00a0This isn&#8217;t going to be a full-blown solution,\u00a0but it will hopefully be enough to show the power behind building reusable components that expose an API for powering them.<\/p>\n<p>Since we will be using ES2015, let&#8217;s start by scaffolding out a class that we will use for our component:<\/p>\n\n<p>Next, just like in PHP, the constructor function is going to be run each time the Modal class is instantiated. Our Modal class will take two parameters. The <code>openTrigger<\/code> will be the HTML element that triggers opening the modal and the options parameter will be the options we pass in to override the defaults.<\/p>\n\n<p>You will notice in the code above that we are using <code>Object.assign()<\/code>. This is an exciting new method\u00a0in ES2015 that allows for merging two objects. I would encourage you to read and learn more about <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Object\/assign\">Object.assign()<\/a>.\u00a0Anyways, we are just\u00a0merging the options object being passed in with the default options provided.<\/p>\n<p>For this example, we are going to use a new ES2015 feature called <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Template_literals\">template literals<\/a> to create the markup needed for our modal. Notice how we are able to display variables right inside our template literal strings.<\/p>\n\n<p>Next, we will need a <code>render()<\/code> method that will be\u00a0responsible for putting together the template and attaching it to the DOM. As you can see, we are using a <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/DocumentFragment\">document fragment<\/a> to build out the markup. A document fragment is a minimal document object that isn&#8217;t actually a part of the DOM. It&#8217;s a performant way of composing some markup in memory then attaching it to an element.<\/p>\n\n<p>Now we need open and close methods. These two function will be somewhat similar, but let&#8217;s touch on a few key points.<\/p>\n\n<p>First, both functions check to see if a callback function has been passed in via the Modal options. For the <code>open()<\/code> method the\u00a0callback that is checked for is <code>this.config.onBefore()<\/code> and for the close method the callback checked for is <code>this.config.onAfter().<\/code> If either has been set, it will be called.<\/p>\n<p>Second, we are utilizing a <code>setTimeout()<\/code> function along with arrow functions to add and remove CSS classes that will help us animate in the modal. This perhaps isn&#8217;t the best solution here, but for the sake of this example, it works just fine. You could explore using <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/CSS_Transitions\/Using_CSS_transitions#Detecting_the_start_and_completion_of_a_transition\">transition<\/a> or <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/CSS_Animations\/Using_CSS_animations#Using_animation_events\">animation<\/a>\u00a0events as other possible solutions.<\/p>\n<p>The last function is a simple <code>bindEvents()<\/code> function that&#8217;s sole purpose is to bind the <code>open()<\/code> function to the\u00a0open trigger specified by the user.<\/p>\n\n<p>Now that we have our modal class built out with the basic functionality we can now create a couple of different modals that will work independently of each other.<\/p>\n<p>Here is code that will instantiate two different modals. Each will have a different <code>openTrigger<\/code> parameter as well as different options.<\/p>\n\n<p>First, we are declaring two different button elements that will act as our modal triggers.<\/p>\n<p>Then we &#8216;new-up&#8217; each modal with their respective trigger button, as well as their custom options. Notice how I am writing an anonymous function that will be called in our <code>open()<\/code> and <code>close()<\/code> methods.<\/p>\n<p>Check out this CodePen for a working demo.<\/p>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" src=\"https:\/\/codepen.io\/efuller\/embed\/preview\/YNaWzV?height=300&#038;amp;slug-hash=YNaWzV&#038;amp;default-tabs=js,result&#038;amp;host=http%3A%2F%2Fcodepen.io&#038;amp;embed-version=2#?secret=z9wQhWbZCp\" data-secret=\"z9wQhWbZCp\" title=\"Reusable Modal Component\" scrolling=\"no\" frameborder=\"0\" height=\"300\"><\/iframe><\/p>\n<p>I hope that this post shows the power of creating reusable components. It doesn&#8217;t have to be confined to just JavaScript, as well. No matter what you are coding, it&#8217;s always great to do it with\u00a0the mindset of reusability.<\/p>\n<p>Feel free to leave a comment below to further the discussion!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over the past year, I have been working very hard to learn JavaScript deeply. I have even purposefully taken the\u00a0approach to learn it outside of the WordPress ecosystem. Why? Because it promotes exploring and learning different techniques that you can then take and apply to WordPress! The purpose of this post is to try and <a class=\"more-link\" href=\"https:\/\/webdevstudios.com\/2017\/03\/21\/javascript-reusable-components-api\/\">Read More<span class=\"screen-reader-text\"> JavaScript: Reusable Components and API<\/span><\/a><\/p>\n","protected":false},"author":28,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"jetpack_post_was_ever_published":false,"footnotes":""},"categories":[161,954],"tags":[955,956,650],"coauthors":[1014],"class_list":["post-16447","post","type-post","status-publish","format-standard","hentry","category-api","category-javascript","tag-modal","tag-reusable-components","tag-ui"],"acf":{"blog_hero_image":{"ID":15555,"id":15555,"title":"programming-language","filename":"programming-language.jpg","filesize":124920,"url":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language.jpg","link":"https:\/\/webdevstudios.com\/2016\/08\/02\/why-you-should-learn-another-programming-language\/programming-language\/","alt":"","author":"13","description":"","caption":"","name":"programming-language","status":"inherit","uploaded_to":13495,"date":"2017-02-13 18:53:05","modified":"2017-04-05 19:13:04","menu_order":0,"mime_type":"image\/jpeg","type":"image","subtype":"jpeg","icon":"https:\/\/webdevstudios.com\/wp-includes\/images\/media\/default.png","width":1920,"height":1080,"sizes":{"thumbnail":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-150x150.jpg","thumbnail-width":150,"thumbnail-height":150,"medium":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-300x169.jpg","medium-width":300,"medium-height":169,"medium_large":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-768x432.jpg","medium_large-width":768,"medium_large-height":432,"large":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-1024x576.jpg","large-width":850,"large-height":478,"1536x1536":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-1536x864.jpg","1536x1536-width":1536,"1536x1536-height":864,"2048x2048":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language.jpg","2048x2048-width":1920,"2048x2048-height":1080,"featured-work-lg":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-436x511.jpg","featured-work-lg-width":436,"featured-work-lg-height":511,"featured-work-sm":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-436x241.jpg","featured-work-sm-width":436,"featured-work-sm-height":241,"book-cover":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-235x300.jpg","book-cover-width":235,"book-cover-height":300,"home-hero":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-1350x440.jpg","home-hero-width":1350,"home-hero-height":440,"services-screenshot":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-590x790.jpg","services-screenshot-width":590,"services-screenshot-height":790,"single-blog-featured":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-1920x625.jpg","single-blog-featured-width":1920,"single-blog-featured-height":625,"single-blog-inline":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-850x360.jpg","single-blog-inline-width":850,"single-blog-inline-height":360,"grid-image":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-420x420.jpg","grid-image-width":420,"grid-image-height":420,"logo-train":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-107x60.jpg","logo-train-width":107,"logo-train-height":60,"simple-header":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-1920x191.jpg","simple-header-width":1920,"simple-header-height":191,"full-width":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-1920x1080.jpg","full-width-width":1920,"full-width-height":1080,"fifty-fifty-media":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language-1300x731.jpg","fifty-fifty-media-width":1300,"fifty-fifty-media-height":731,"gform-image-choice-sm":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language.jpg","gform-image-choice-sm-width":300,"gform-image-choice-sm-height":169,"gform-image-choice-md":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language.jpg","gform-image-choice-md-width":400,"gform-image-choice-md-height":225,"gform-image-choice-lg":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2016\/08\/programming-language.jpg","gform-image-choice-lg-width":600,"gform-image-choice-lg-height":338}},"background_choice":{"value":"null","label":"None"},"section_title_type":"h2","section_title_alignment":"left","section_title":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.5 (Yoast SEO v27.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>JavaScript: Reusable Components and API - WebDevStudios<\/title>\n<meta name=\"description\" content=\"Over the past year, I have been working very hard to learn JavaScript deeply. I have even purposefully taken the\u00a0approach to learn it outside of the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webdevstudios.com\/2017\/03\/21\/javascript-reusable-components-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript: Reusable Components and API\" \/>\n<meta property=\"og:description\" content=\"Over the past year, I have been working very hard to learn JavaScript deeply. I have even purposefully taken the\u00a0approach to learn it outside of the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webdevstudios.com\/2017\/03\/21\/javascript-reusable-components-api\/\" \/>\n<meta property=\"og:site_name\" content=\"WebDevStudios\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/webdevstudios\" \/>\n<meta property=\"article:published_time\" content=\"2017-03-21T16:00:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-15T16:01:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webdevstudios.com\/wp-content\/uploads\/2022\/11\/wds-default.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Eric Fuller\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webdevstudios\" \/>\n<meta name=\"twitter:site\" content=\"@webdevstudios\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Eric Fuller\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/webdevstudios.com\\\/2017\\\/03\\\/21\\\/javascript-reusable-components-api\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/webdevstudios.com\\\/2017\\\/03\\\/21\\\/javascript-reusable-components-api\\\/\"},\"author\":{\"name\":\"Eric Fuller\",\"@id\":\"https:\\\/\\\/webdevstudios.com\\\/#\\\/schema\\\/person\\\/878db6564966f58f951521744bd689e4\"},\"headline\":\"JavaScript: Reusable Components and API\",\"datePublished\":\"2017-03-21T16:00:21+00:00\",\"dateModified\":\"2024-04-15T16:01:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/webdevstudios.com\\\/2017\\\/03\\\/21\\\/javascript-reusable-components-api\\\/\"},\"wordCount\":1198,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/webdevstudios.com\\\/#organization\"},\"keywords\":[\"modal\",\"reusable components\",\"UI\"],\"articleSection\":[\"API\",\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/webdevstudios.com\\\/2017\\\/03\\\/21\\\/javascript-reusable-components-api\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/webdevstudios.com\\\/2017\\\/03\\\/21\\\/javascript-reusable-components-api\\\/\",\"url\":\"https:\\\/\\\/webdevstudios.com\\\/2017\\\/03\\\/21\\\/javascript-reusable-components-api\\\/\",\"name\":\"JavaScript: Reusable Components and API - WebDevStudios\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/webdevstudios.com\\\/#website\"},\"datePublished\":\"2017-03-21T16:00:21+00:00\",\"dateModified\":\"2024-04-15T16:01:25+00:00\",\"description\":\"Over the past year, I have been working very hard to learn JavaScript deeply. I have even purposefully taken the\u00a0approach to learn it outside of the\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/webdevstudios.com\\\/2017\\\/03\\\/21\\\/javascript-reusable-components-api\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/webdevstudios.com\\\/2017\\\/03\\\/21\\\/javascript-reusable-components-api\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/webdevstudios.com\\\/2017\\\/03\\\/21\\\/javascript-reusable-components-api\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/webdevstudios.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript: Reusable Components and API\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/webdevstudios.com\\\/#website\",\"url\":\"https:\\\/\\\/webdevstudios.com\\\/\",\"name\":\"WebDevStudios\",\"description\":\"WordPress Design and Development Agency\",\"publisher\":{\"@id\":\"https:\\\/\\\/webdevstudios.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/webdevstudios.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/webdevstudios.com\\\/#organization\",\"name\":\"WebDevStudios\",\"url\":\"https:\\\/\\\/webdevstudios.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/webdevstudios.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/webdevstudios.com\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/wds-amp-logo.png\",\"contentUrl\":\"https:\\\/\\\/webdevstudios.com\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/wds-amp-logo.png\",\"width\":173,\"height\":60,\"caption\":\"WebDevStudios\"},\"image\":{\"@id\":\"https:\\\/\\\/webdevstudios.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"http:\\\/\\\/facebook.com\\\/webdevstudios\",\"https:\\\/\\\/x.com\\\/webdevstudios\",\"http:\\\/\\\/instagram.com\\\/webdevstudios\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/webdevstudios-llc-\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/webdevstudios.com\\\/#\\\/schema\\\/person\\\/878db6564966f58f951521744bd689e4\",\"name\":\"Eric Fuller\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d2a6df7ec1ab12514c4e371cf1274a7b3a2377c5b06f05fae58b82d012b9ecc5?s=96&d=mm&r=g751cf74c33849de9590daf1183364810\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d2a6df7ec1ab12514c4e371cf1274a7b3a2377c5b06f05fae58b82d012b9ecc5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d2a6df7ec1ab12514c4e371cf1274a7b3a2377c5b06f05fae58b82d012b9ecc5?s=96&d=mm&r=g\",\"caption\":\"Eric Fuller\"},\"url\":\"https:\\\/\\\/webdevstudios.com\\\/author\\\/eric\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"JavaScript: Reusable Components and API - WebDevStudios","description":"Over the past year, I have been working very hard to learn JavaScript deeply. I have even purposefully taken the\u00a0approach to learn it outside of the","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webdevstudios.com\/2017\/03\/21\/javascript-reusable-components-api\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript: Reusable Components and API","og_description":"Over the past year, I have been working very hard to learn JavaScript deeply. I have even purposefully taken the\u00a0approach to learn it outside of the","og_url":"https:\/\/webdevstudios.com\/2017\/03\/21\/javascript-reusable-components-api\/","og_site_name":"WebDevStudios","article_publisher":"http:\/\/facebook.com\/webdevstudios","article_published_time":"2017-03-21T16:00:21+00:00","article_modified_time":"2024-04-15T16:01:25+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2022\/11\/wds-default.png","type":"image\/png"}],"author":"Eric Fuller","twitter_card":"summary_large_image","twitter_creator":"@webdevstudios","twitter_site":"@webdevstudios","twitter_misc":{"Written by":"Eric Fuller","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webdevstudios.com\/2017\/03\/21\/javascript-reusable-components-api\/#article","isPartOf":{"@id":"https:\/\/webdevstudios.com\/2017\/03\/21\/javascript-reusable-components-api\/"},"author":{"name":"Eric Fuller","@id":"https:\/\/webdevstudios.com\/#\/schema\/person\/878db6564966f58f951521744bd689e4"},"headline":"JavaScript: Reusable Components and API","datePublished":"2017-03-21T16:00:21+00:00","dateModified":"2024-04-15T16:01:25+00:00","mainEntityOfPage":{"@id":"https:\/\/webdevstudios.com\/2017\/03\/21\/javascript-reusable-components-api\/"},"wordCount":1198,"commentCount":0,"publisher":{"@id":"https:\/\/webdevstudios.com\/#organization"},"keywords":["modal","reusable components","UI"],"articleSection":["API","JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webdevstudios.com\/2017\/03\/21\/javascript-reusable-components-api\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webdevstudios.com\/2017\/03\/21\/javascript-reusable-components-api\/","url":"https:\/\/webdevstudios.com\/2017\/03\/21\/javascript-reusable-components-api\/","name":"JavaScript: Reusable Components and API - WebDevStudios","isPartOf":{"@id":"https:\/\/webdevstudios.com\/#website"},"datePublished":"2017-03-21T16:00:21+00:00","dateModified":"2024-04-15T16:01:25+00:00","description":"Over the past year, I have been working very hard to learn JavaScript deeply. I have even purposefully taken the\u00a0approach to learn it outside of the","breadcrumb":{"@id":"https:\/\/webdevstudios.com\/2017\/03\/21\/javascript-reusable-components-api\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webdevstudios.com\/2017\/03\/21\/javascript-reusable-components-api\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webdevstudios.com\/2017\/03\/21\/javascript-reusable-components-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webdevstudios.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript: Reusable Components and API"}]},{"@type":"WebSite","@id":"https:\/\/webdevstudios.com\/#website","url":"https:\/\/webdevstudios.com\/","name":"WebDevStudios","description":"WordPress Design and Development Agency","publisher":{"@id":"https:\/\/webdevstudios.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webdevstudios.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webdevstudios.com\/#organization","name":"WebDevStudios","url":"https:\/\/webdevstudios.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webdevstudios.com\/#\/schema\/logo\/image\/","url":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2019\/07\/wds-amp-logo.png","contentUrl":"https:\/\/webdevstudios.com\/wp-content\/uploads\/2019\/07\/wds-amp-logo.png","width":173,"height":60,"caption":"WebDevStudios"},"image":{"@id":"https:\/\/webdevstudios.com\/#\/schema\/logo\/image\/"},"sameAs":["http:\/\/facebook.com\/webdevstudios","https:\/\/x.com\/webdevstudios","http:\/\/instagram.com\/webdevstudios","https:\/\/www.linkedin.com\/company\/webdevstudios-llc-\/"]},{"@type":"Person","@id":"https:\/\/webdevstudios.com\/#\/schema\/person\/878db6564966f58f951521744bd689e4","name":"Eric Fuller","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d2a6df7ec1ab12514c4e371cf1274a7b3a2377c5b06f05fae58b82d012b9ecc5?s=96&d=mm&r=g751cf74c33849de9590daf1183364810","url":"https:\/\/secure.gravatar.com\/avatar\/d2a6df7ec1ab12514c4e371cf1274a7b3a2377c5b06f05fae58b82d012b9ecc5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d2a6df7ec1ab12514c4e371cf1274a7b3a2377c5b06f05fae58b82d012b9ecc5?s=96&d=mm&r=g","caption":"Eric Fuller"},"url":"https:\/\/webdevstudios.com\/author\/eric\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3WX6u-4hh","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webdevstudios.com\/wp-json\/wp\/v2\/posts\/16447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webdevstudios.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webdevstudios.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webdevstudios.com\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/webdevstudios.com\/wp-json\/wp\/v2\/comments?post=16447"}],"version-history":[{"count":0,"href":"https:\/\/webdevstudios.com\/wp-json\/wp\/v2\/posts\/16447\/revisions"}],"wp:attachment":[{"href":"https:\/\/webdevstudios.com\/wp-json\/wp\/v2\/media?parent=16447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webdevstudios.com\/wp-json\/wp\/v2\/categories?post=16447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webdevstudios.com\/wp-json\/wp\/v2\/tags?post=16447"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/webdevstudios.com\/wp-json\/wp\/v2\/coauthors?post=16447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}