In this post I will show how to integrate a simple ngrx sample with the Closure compiler.
I have heard a lot of people talk about ngrx, but I've never actually given it a try until today.
Since I am starting from scratch, I figured it made sense to start with the default ngrx demo application.
The idea behind the demo app is to use ngrx to manage the state of a simple counter.
I took the original code and modified it slightly as seen below:
AppModule is where I configure the StoreModule and set up a simple “Store”.
In AppComponent I set up some basic user interactions to increment/decrement the counter. I also wire up the store API to keep track of counter state.
There is one very important point to make about the store.select api here.
The alternative store.select('counter') API is not compatible with Closure compiler property mangling.
Why not use the string based select API?
After Closure compilation the original “counter” property name has likely been renamed to a shorter name. As a result, “counter”, is no longer a valid name to reference the store.
Sticking to the object notation like I am doing in this sample is safe though since both counter references are renamed “together”.
I have put the code on Github in case you are interested in trying it out.
Build the project by running:
A few notes:
This sample is using the ngrx nightly build since the Angular 4 version is not yet available on npm.