<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Trim Agency &#187; javascript</title>
	<atom:link href="http://old.trimagency.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://old.trimagency.com</link>
	<description></description>
	<lastBuildDate>Mon, 29 Jun 2026 06:32:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>Environment Variables in Webpack</title>
		<link>http://old.trimagency.com/environment-variables-in-webpack/</link>
		<comments>http://old.trimagency.com/environment-variables-in-webpack/#comments</comments>
		<pubDate>Sun, 29 Jan 2017 20:23:07 +0000</pubDate>
		<dc:creator><![CDATA[Dom Miller]]></dc:creator>
				<category><![CDATA[Team Trim]]></category>
		<category><![CDATA[Today I Learned]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[webpack]]></category>

		<guid isPermaLink="false">http://trimagency.com/?p=2492</guid>
		<description><![CDATA[<p>Diving into webpack module loader can often seem like a confusing and daunting task. Luckily, setting environment variables is rather straight forward. At the top of your webpack.config.js file define your environment variables like so: Then in the plugins array use DefinePlugin method to define global variables configured at compile time: Re-compile and now your [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://old.trimagency.com/environment-variables-in-webpack/">Environment Variables in Webpack</a> appeared first on <a rel="nofollow" href="http://old.trimagency.com">Trim Agency</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Diving into webpack module loader can often seem like a confusing and daunting task.<br />
Luckily, setting environment variables is rather straight forward.</p>
<p>At the top of your webpack.config.js file define your environment variables like so:</p>
<pre class="brush: jscript; title: ; notranslate">
/**
 * Example Constants
 */
const ENV = process.env.ENV = process.env.NODE_ENV = 'development';
const API_URL = process.env.API_URL = 'http://localhost:3000';
const METADATA = {
  API_URL: API_URL,
  ENV: ENV
};
</pre>
<p>Then in the plugins array use DefinePlugin method to define global variables configured at compile time:</p>
<pre class="brush: jscript; title: ; notranslate">
/**
 * Make Webpack Constants Available Globally
 */
   new webpack.DefinePlugin({
     'ENV': JSON.stringify(METADATA.ENV),
     'API_URL': JSON.stringify(METADATA.API_URL),
     'process.env': {
       'ENV': JSON.stringify(METADATA.ENV),
       'NODE_ENV': JSON.stringify(METADATA.ENV),
       'API_URL' : JSON.stringify(METADATA.API_URL),
     }
   }),
</pre>
<p>Re-compile and now your variables will be globally available.</p>
<p>The post <a rel="nofollow" href="http://old.trimagency.com/environment-variables-in-webpack/">Environment Variables in Webpack</a> appeared first on <a rel="nofollow" href="http://old.trimagency.com">Trim Agency</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://old.trimagency.com/environment-variables-in-webpack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Immutable Objects using Object.assign</title>
		<link>http://old.trimagency.com/immutable-objects-using-object-assign/</link>
		<comments>http://old.trimagency.com/immutable-objects-using-object-assign/#comments</comments>
		<pubDate>Sat, 21 Jan 2017 20:01:12 +0000</pubDate>
		<dc:creator><![CDATA[Dom Miller]]></dc:creator>
				<category><![CDATA[Today I Learned]]></category>
		<category><![CDATA[immutable]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[object]]></category>

		<guid isPermaLink="false">http://www.trimagency.com/?p=2430</guid>
		<description><![CDATA[<p>Is immutability important? Mutating data can produce code that’s hard to read and error prone. But we can avoid this mess using vanilla javascript&#8217;s ES6 feature Object.assign! Let&#8217;s look at the problem&#8230;. When we changed obj2&#8217;s key property, it also changed obj1&#8217;s key property. No bueno! The solution: As you can see we changed obj2&#8217;s [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://old.trimagency.com/immutable-objects-using-object-assign/">Immutable Objects using Object.assign</a> appeared first on <a rel="nofollow" href="http://old.trimagency.com">Trim Agency</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Is <em>immutability</em> important? Mutating data can produce code that’s hard to read and error prone. But we can avoid this mess using vanilla javascript&#8217;s ES6 feature Object.assign!</p>
<p>Let&#8217;s look at the problem&#8230;.</p>
<pre class="brush: jscript; title: ; notranslate">
var obj1 = { key: 'some value' };

var obj2 = obj1;
obj2.key = 'another value';

console.log( obj1 === obj2) // true
console.log( obj1.key ) // 'another value'

</pre>
<p>When we changed obj2&#8217;s key property, it also changed obj1&#8217;s key property. No bueno!<br />
The solution:</p>
<pre class="brush: jscript; title: ; notranslate">
var obj1 = { key: 'some value' };

var obj2 = Object.assign( {}, obj1, { key: 'another value' });

console.log( obj1 === obj2) // false
console.log( obj1.key ) // 'some value'
console.log( obj2.key ) // 'another value'

</pre>
<p>As you can see we changed obj2&#8217;s key property and it left obj1&#8217;s state intact! Now that&#8217;s immutable!<br />
Object.assign takes objects as its parameters and passing in an empty object as the &#8216;target&#8217; keeps our &#8216;source&#8217; objects intact. </p>
<p>Object.assign is widely supported by desktop and mobile browsers, please check <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign">Mozilla</a> for more info.</p>
<p>The post <a rel="nofollow" href="http://old.trimagency.com/immutable-objects-using-object-assign/">Immutable Objects using Object.assign</a> appeared first on <a rel="nofollow" href="http://old.trimagency.com">Trim Agency</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://old.trimagency.com/immutable-objects-using-object-assign/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
