<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Michael Warneke on Medium]]></title>
        <description><![CDATA[Stories by Michael Warneke on Medium]]></description>
        <link>https://medium.com/@michael.warneke?source=rss-3182934241f3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QjCZrmcM8mCKIEgTbY7D3A.jpeg</url>
            <title>Stories by Michael Warneke on Medium</title>
            <link>https://medium.com/@michael.warneke?source=rss-3182934241f3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 08:57:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@michael.warneke/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to scaffold an Angular 17 project like Nx, but simplified?]]></title>
            <link>https://medium.com/cloudboost/how-to-scaffold-an-angular-17-project-like-nx-but-simplified-1b592089d3fe?source=rss-3182934241f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b592089d3fe</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[nx]]></category>
            <category><![CDATA[angular-17]]></category>
            <category><![CDATA[scaffold]]></category>
            <category><![CDATA[monorepo]]></category>
            <dc:creator><![CDATA[Michael Warneke]]></dc:creator>
            <pubDate>Wed, 08 Nov 2023 03:26:12 GMT</pubDate>
            <atom:updated>2024-01-04T09:23:38.116Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Just the logos of Nx and Angular 17" src="https://cdn-images-1.medium.com/max/700/1*kGQL2m_z_RJkhAlcOY2Ytw.png" /></figure><p>Lots of times I want to create a little Angular project with some basic functionality and the option to extend it into a bigger project later on.</p><p>Nx is great for working with Angular projects and provides a beautiful scaffolding with all the needs to grow into a big project. I like the separation of apps and libraries and the easy way of importing them.</p><p>But sometimes Nx is just an overdose or just not yet ready for using it with new beta releases. Just before the official release of Angular 17 I started a new project and wanted to jump right into upcoming version. To create this with Nx wasn’t easy for me and I gave up as the new Angular 17 RC are not supported by the official Nx release yet. You could tweak around and download a Nx branch which is already in the works for that. But I didn’t want to dig to deep into this and just wanted to start and build with the latest Release Candidate of Angular which I could easily download and install in my environment.</p><p>But on the other hand I also wanted some sort of scaffolding similar to Nx but without all the overhead. So I looked into the Angular CLI to find out how I can get close to it without too much setup. I found a very interesting article from <a href="https://dev.to/this-is-angular/how-to-set-up-an-nx-style-monorepo-workspace-with-the-angular-cli-part-1-16b5">Lars Gyrup Brink Nielsen — How to set up an Nx-style monorepo workspace with the Angular</a> which inspired me on this path to simplify this setup for my needs. Maybe this is of some use for someone else, so I publish it for all of you. The example code can be found at <a href="https://github.com/MichaelWarneke/angular-17-nx-alike-simple">my Github repo</a>.</p><p>This might work with older Angular versions as well, but I haven’t tested it as I only worked through this to get it running with version 17 RC 3.</p><p>The folder structure will be like the below setup which off course can be adjusted as you like. For example if you don’t like the projects folder just name it different in the cli commands.</p><pre>projects<br>  - apps<br>    - my-app<br>    - ...<br>  - libs<br>    - my-libs<br>    - ...<br>angular.json<br>package.json<br>tsconfig.json</pre><p>I created a new workspace without an app like this.</p><pre>ng new test --package-manager yarn --ssr --style scss --strict --create-application false --new-project-root projects/libs --skip-install</pre><p>You can adjust as you like but important is to not create an application with “create-application false” to avoid having the app at the root level. I also used the new project root for my libs folder where I will create most of my “projects”.</p><p>From now on I only used the ng generate commands to add whatever I need to my workspace. Here follows the main app.</p><pre>ng g application my-app --ssr --style scss --prefix app --routing --project-root projects/apps/my-app</pre><p>Important here is the project root which defines and creates the folder structure for my apps. As mentioned above you can adjust the folder structure here as you like. But you need to add the folder structure to all app generator commands as the workspace default project folder is linked to the libs folder below.</p><p>To implement a library, I found the below way which will take to steps for getting close to the Nx way of importing the libraries.</p><pre>ng g library layout --entry-file index --prefix layout --skip-install</pre><p>I don’t have to name the folder as this was induced by the new project root parameter with ng new above. So, all my libraries will end up in projects/libs.</p><p>The second step for the libraries is to make the import easy. In Nx you can import libraries with “@library-name”. I really like that style and you can easily have the same advantage by adding the path to the src folder of the library to the tsconfig.json in your root path.</p><pre>{<br>  &quot;compileOnSave&quot;: false,<br>  &quot;compilerOptions&quot;: {<br>    &quot;outDir&quot;: &quot;./dist/out-tsc&quot;,<br>    &quot;forceConsistentCasingInFileNames&quot;: true,<br>    &quot;strict&quot;: true,<br>    &quot;noImplicitOverride&quot;: true,<br>    &quot;noPropertyAccessFromIndexSignature&quot;: true,<br>    &quot;noImplicitReturns&quot;: true,<br>    &quot;paths&quot;: {<br>      &quot;layout&quot;: [<br>//        &quot;./dist/layout&quot;, // this has to be removed<br>        &quot;./projects/libs/layout/src&quot;<br>      ]<br>    },<br>}</pre><p>In above example the path for “layout” was already set to the “./dist/layout” folder for runtime (This has to be removed to have the library compiled together with the main app). For compilation you can just add the path to the src folder (which includes the index.ts where you export everything from your library) under the existing dist path.</p><p>Now you can import like in this example the Layout Component in the App Component or in any other library like this.</p><pre>import { LayoutComponent } from &#39;layout&#39;;</pre><p>Or if you prefer just add an @layout to the tsconfig and import it like Nx libraries. I would recommend giving them a workspace specific prefix to indicate that these libraries are internally and not something within your npm packages.</p><p>Now if you want to add anything to your libraries just use the project attribute in your ng g commands and it will end up in the right place.</p><pre>ng g c sidenav --project layout</pre><p>For sure there are more possibilities to advance this solution, but for now that how I do it. Feel free to comment below or in my Github repository if you have further ideas or improvements. Happy to come back in a couple of weeks and update this post with new ideas.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b592089d3fe" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cloudboost/how-to-scaffold-an-angular-17-project-like-nx-but-simplified-1b592089d3fe">How to scaffold an Angular 17 project like Nx, but simplified?</a> was originally published in <a href="https://medium.com/cloudboost">CloudBoost</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular Dynamic Forms (Property safe)]]></title>
            <link>https://medium.com/@michael.warneke/angular-dynamic-forms-property-safe-d996f8a8d03f?source=rss-3182934241f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d996f8a8d03f</guid>
            <category><![CDATA[dynamic-form]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[forms]]></category>
            <dc:creator><![CDATA[Michael Warneke]]></dc:creator>
            <pubDate>Wed, 27 Mar 2019 02:56:15 GMT</pubDate>
            <atom:updated>2019-03-27T07:40:45.751Z</atom:updated>
            <content:encoded><![CDATA[<p>Looking for a solution to use dynamic forms but with a kind of abstract module defining the elements in the data and the form model I created following solution based on different examples around the web.</p><p>The problem in any other solution I found was that for creating the dynamic forms it has to be generated a form description in a format with all the necessary information like a key, label, order, options, etc. Then create classes besides the FormControll classes and have some kind of service to put it all together. The official <a href="https://angular.io/guide/dynamic-form">angular dynamic forms</a> descriptions put in some question classes and used a ngSwitchCase in the template to instantiate different form elements. I didn’t like the switch approach as the template can be very messy after lots of different types of form elements and I prefer a directive. Also, I didn’t like the extra classes of questions and the problem to keep a DB data model in sync with the form. Basically, that’s what I was looking for in the beginning to have a kind of super interface or class I can use for my data model and later in the forms as well. This will keep both in sync and if there are changes to the data model it should be updated in the base class from which the form model depends as well.</p><p>But let’s keep it short and here is some code. It was the first time for me to do it on <a href="https://stackblitz.com/edit/mw-angular-dynamic-forms">Stackblitz</a> in combination with <a href="https://github.com/MichaelWarneke/dynamic-forms">Github</a>. That was amazing.</p><h3>Combining FormControl with template description</h3><p>My idea was to get the FormControl class and the template description together. So I just created a FromControlBase class extending FormControl.</p><pre>export class FormControlBase extends FormControl {<br>  controlType: string = ‘’;<br>}</pre><p>The additional controlType should define the different form elements like input, select, datepicker or your own ones.</p><pre>export class FormControlTextbox extends FormControlBase {<br>  controlType = &#39;input&#39;;<br>  type: string = &#39;&#39;;<br>}</pre><p>For example the input text box as above. The additional type can be used for anything or you just add other important attributes (Just make sure they are not part of FromControl). Now there is a FromControl class with extra attributes I need to create the template files and you don’t need the extra description file or question classes like in the official example.</p><h3>Combing data and form model (Property safe)</h3><p>To get the data and form model in sync I would like to derive them both from a superclass with the individual items.</p><pre>export interface ExampleModel {<br>  id: any;<br>  name: any;<br>  date: any;<br>};</pre><p>As this is an interface but you could also define it as an abstract class. The types are all any to allow it to be the proper data type as well as a FormControl. So you could be lazy and just use this interface for all your data fetching or define a class with its types.</p><pre>export class ExampleModelData implements ExampleModel {<br>  id: string | null = null;<br>  name: string | null = null;<br>  date: Date | null = null;<br>}</pre><p>And the same for the form model, but here we use now the individual derived FormControl classes as above.</p><pre>export class ExampleModelForm implements ExampleModel {<br>  id = new FormControlTextbox(&#39;nothing&#39;, [Validators.required]);<br>  name = new FormControlTextbox(&#39;nothing&#39;, [Validators.required]);<br>  date = new FormControlDate(&#39;nothing&#39;, [Validators.required]);<br>}</pre><p>Btw, the constructor from FormControl is still used in this construct. That makes it easy to add all the necessary validators.</p><p>Now I call this kind of “Property safe”. If there are any changes in the attribute names either in the base interface, data class or form class typescript will let you know that (If you run it in strict mode) you have to update the other class/interface as well.</p><p>It’s not typesafe as I couldn’t find a way yet to extend it to check the types of the different classes as well. But the value of FormControl is any anyhow…</p><h3>Using the derived Form control classes</h3><p>The previously mentioned model classes are all you need to create for your individual dynamic forms when implementing the following construct.</p><p>You need some kind of service handling the different types of form element templates like input, select, etc, a base component and the individual templates. For the service, I prefer a directive approach as mentioned above and I got my inspiration from this <a href="https://medium.com/@mail.bahurudeen/create-a-dynamic-form-with-configurable-fields-and-validations-using-angular-6-994db56834da">blog</a> of Bahurudeen.</p><pre>const componentMapper = {<br>  input: DynamicFormInputComponent,<br>  datepicker: DynamicFormDatepickerComponent<br>};</pre><pre>@Directive({<br>  selector: &quot;[dynamicField]&quot;<br>})<br>export class DynamicFieldDirective implements OnInit {<br>  @Input() val: FormControlTextbox | null = null;<br>  @Input() group: FormGroup | null = null;<br>  componentRef: any;</pre><pre>  constructor(<br>    private resolver: ComponentFactoryResolver,<br>    private container: ViewContainerRef<br>  ) {}</pre><pre>  ngOnInit() {<br>    const factory = this.resolver.resolveComponentFactory(<br>      componentMapper[this.val.controlType]<br>    );<br>    this.componentRef = this.container.createComponent(factory);<br>    this.componentRef.instance.val = this.val;<br>    this.componentRef.instance.group = this.group;<br>  }<br>}</pre><p>Basically, this directive will just check the controlType in our form model and associate the template component. In this case, we don’t need the switch method like in the official docs.</p><p>The individual template components are quite simple but can be advanced as requested.</p><pre>@Component({<br>  selector: &#39;dynamic-form-input&#39;,<br>  template: `<br>    &lt;mat-form-field [formGroup]=&quot;group&quot;&gt;<br>    &lt;input <br>      matInput <br>      placeholder=&quot;{{val.key}}&quot;<br>      [formControlName]=&quot;val.key&quot;&gt;<br>    &lt;/mat-form-field&gt;<br>  `,<br>  styles: [`mat-form-field{margin: 10px}`]<br>})</pre><pre>export class DynamicFormInputComponent  {<br>  val: FormControlTextbox | null = null;<br>  group: FormGroup | null = null;<br>  <br>  constructor() {}<br>}</pre><p>A bit more tricky is the base component as there are two problems. As I know you can&#39;t iterate through a FromGroup in the template. And the question is do you have the FormGroup or the data first. The data might come from an async call via a database and has to be set later.</p><p>The iterate problem I solved by creating a list of the form elements from the FormGroup and iterate through that list to create the individual templates.</p><pre>Object.keys(this.form.controls).forEach(key =&gt; {<br>  this.formlist.push({<br>    ...this.form.get(key) as FormControlBase, <br>    key: key <br>  });<br>})</pre><p>The async or not problem I just did a straight forward approach and created an updateData functions which will either be called on ngInit or on a setter of the data input attribute.</p><pre>@Component({<br>  selector: &#39;dynamic-form&#39;,<br>  template: `<br>    &lt;form [formGroup]=&quot;form&quot;&gt;<br>    &lt;ng-container *ngFor=&quot;let val of formlist;&quot; <br>      dynamicField [val]=&quot;val&quot; [group]=&quot;form&quot;&gt;<br>    &lt;/ng-container&gt;<br>    &lt;/form&gt;<br>  `,<br>  styles: []<br>})<br>export class DynamicFormComponent implements OnInit  {<br>  @Input() formModel: any;<br>  _data: any;<br>  @Input() set data(data: any) {<br>    this._data = data;<br>    this.updateData(data);<br>  };<br>  get data() {<br>    return this._data;<br>  }</pre><pre>  form: FormGroup | null = null;<br>  formlist = new Array();</pre><pre>  constructor(private fb: FormBuilder) {}</pre><pre>  ngOnInit() {<br>    this.form = this.fb.group(this.formModel);<br>    this.updateData(this.data);<br>  }</pre><pre>  updateData(data: any) {<br>    if(data &amp;&amp; this.form) {<br>      this.form.patchValue(this.data);<br>      this.formlist = new Array();<br>      Object.keys(this.form.controls).forEach(key =&gt; {<br>        this.formlist.push({<br>          ...this.form.get(key) as FormControlBase, <br>          key: key <br>        });<br>      })<br>    }<br>  }<br>}</pre><p>This foundation a packed up in my code in a separate module and my individual forms can look as simple as below (Just need the ExampleModels as described above as well)</p><pre>@Component({<br>  selector: &#39;hello&#39;,<br>  template: `<br>    &lt;dynamic-form [data]=&quot;data&quot; [formModel]=&quot;formModel&quot;&gt;<br>    &lt;/dynamic-form&gt;<br>  `,<br>  styles: [`h1 { font-family: Lato; }`]<br>})<br>export class FormComponent  {<br>  @Input() name: string = &#39;Not yet&#39;;<br>  data: ExampleModelData;<br>  formModel = new ExampleModelForm();</pre><pre>  constructor () {<br>    this.data = {<br>      id: &#39;1234&#39;, <br>      name: &#39;Hello&#39;, <br>      date: new Date(Date.now())<br>    };<br>  }<br>}</pre><p>Most probably this approach can still be improved and I curious to get your opinions. Maybe it makes sense to pack this in a library for easier access.</p><p>Update: In the code, there is already a version which implements the use of buttons as well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d996f8a8d03f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NGRX and routed data fetching in Angular]]></title>
            <link>https://medium.com/@michael.warneke/ngrx-and-routed-data-fetching-in-angular-1853975b3c7a?source=rss-3182934241f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/1853975b3c7a</guid>
            <category><![CDATA[router]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[ngrx]]></category>
            <dc:creator><![CDATA[Michael Warneke]]></dc:creator>
            <pubDate>Thu, 07 Mar 2019 14:39:13 GMT</pubDate>
            <atom:updated>2019-03-07T14:39:13.580Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a short one explaining my new discovery how to get the item from the store by the supplied id in the URL.</p><p>There are many different ways to get data by routing. Either guards, resolvers or just reading the router URL in the component and fetch it from there.</p><p>I like to keep the components clean and want them just dispatch actions and get the data from the store by selectors. Assuming we have a scenario where a list of things is displayed and on selecting an item the details page pops up. The data is already loaded when the module/feature is created (either lazy or initially on app start). Meaning we have the data already in the store.</p><p>Now comes the trick. Getting the id of the URL (/user/123) can be done by a selector.</p><pre>// NGRX ROUTER<br>export const routerState =   createFeatureSelector&lt;RouterReducerState&lt;RouterStateUrl&gt;&gt;(&#39;router&#39;);</pre><pre>export const selectIdOfRoute = createSelector(<br>  routerState,<br>  state =&gt;<br>   state &amp;&amp;<br>   state.state &amp;&amp;<br>   state.state.params &amp;&amp;<br>   (state.state.params.id as string | null)<br>);</pre><p>The router store for this selector uses the standard serializer as described on the<a href="https://ngrx.io/guide/router-store/configuration"> ngrx docs</a>. If the serializer is not used the selector might look different.</p><p>Then it&#39;s easy to get the selected item observable from the store by a combined selector. In this example, ngrx entity selectors are used as well.</p><pre>export const selectItemState = createFeatureSelector&lt;State&gt;(&#39;items&#39;);</pre><pre>export const selectAllItems = createSelector(<br>  selectItemState,<br>  selectAll<br>);</pre><pre>export const selectAllItemEntities = createSelector(<br>  selectItemState,<br>  selectEntities<br>);</pre><pre>export const selectRoutedItem = createSelector(<br>  selectAllItemEntities,<br>  selectIdOfRoute,<br>  (itemEntities, itemId) =&gt;<br>    itemId ? itemEntities[itemId] : null<br>);</pre><p>Leaves us with the selectRoutedItem selector in the component to display the detailed information.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1853975b3c7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NGRX get data from Firestore (part 2)]]></title>
            <link>https://medium.com/@michael.warneke/https-medium-com-michael-warneke-ngrx-get-data-from-firestore-part-2-e44ef5eff771?source=rss-3182934241f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e44ef5eff771</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[firestore]]></category>
            <category><![CDATA[ngrx]]></category>
            <dc:creator><![CDATA[Michael Warneke]]></dc:creator>
            <pubDate>Thu, 07 Mar 2019 14:17:28 GMT</pubDate>
            <atom:updated>2019-03-07T14:17:28.472Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*KCqFFrw54XMOM_xvuzT_Wg.png" /></figure><p>Part 1 of this blog is <a href="https://medium.com/@michael.warneke/ngrx-get-data-from-firestore-part-1-6f6688946c46">here</a>.</p><p>In this episode, I want to discuss the different possibilities to load data from <a href="https://firebase.google.com/docs/firestore/">Firestore </a>into an NGRX environment using the <a href="https://github.com/angular/angularfire2">angularfire2 </a>library. There are a lot of examples out there which are individually discussed and analysed, but there is no comparison with other procedures and combinations.</p><p>Now after some time coding on the server side, I came back and started working on angular again. And I faced the same problem.</p><p>Searching the web for new inspirations I found following interesting solution which I am gonna use in my next project.</p><p>In this example, the idea is the same as my first solution in part 1. Listening for state changes of the firestore api in an effect class.</p><p>Action Stream:</p><ul><li>IN: Query Effect fetches data from db and updates store with actions handles by the reducer</li><li>OUT: Create, Update and Delete Effect deals with the database. The Query Effect is still listening on changes and updates the store</li></ul><p>But what I don’t like is the fact that when starting the application the effect will trigger “add” actions for all individual items. Let’s say we are loading 1000 items then we will see 1000 triggered actions. That doesn’t look nice especially when using ngrx entity which has the addMany function.</p><p>So I tried to figure out a solution which bundles “added” actions from firestore into a list and fire one action to “addMany”.</p><pre>@Effect()<br>query$: Observable&lt;Action&gt; = this.actions$.pipe(<br>  ofType(AccountApiActionTypes.QUERY),<br>  switchMap(action =&gt; {<br>    console.log(action);<br>    return this.db.getAllAcountsAsStateChanges();<br>  }),<br>  mergeMap((actions: any) =&gt; {<br>    if (actions &amp;&amp; actions.length &gt; 1) {<br>      const addActions = actions.filter((val: any) =&gt; val.type === &#39;added&#39;);<br>      const otherActions = actions.filter((val: any) =&gt; val.type !== &#39;added&#39;);<br>      this.store.dispatch(<br>        new AddedAll(addActions.map(<br>          (item: any) =&gt; {<br>            return {<br>              id: item.payload.doc.id,<br>              ...item.payload.doc.data()<br>            };<br>      })));<br>      return otherActions;<br>    }<br>    return actions;<br>  }),<br>  map((action: any) =&gt; {<br>    return {<br>      type: `[API Account] ${action.type}`,<br>      payload: {<br>        id: action.payload.doc.id,<br>        ...action.payload.doc.data()<br>      }<br>    };<br>  })<br>);</pre><p>So, what the code is doing here is fetching the data state changes from firestore and hand the list over to mergeMap.</p><p>The list gets checked off a size over 1 and the “added” actions get filtered out from the list. On init there will be only added actions when fetching the whole lot from the database.</p><p>Then a separate action is dispatched to trigger the addMany function on the entity and gets the list of all “added” actions mapped into the model.</p><p>Returning the other actions will leave them to the map operator where all the individual actions are returned.</p><p>BUT NO MORE 1000 “added whatever” ACTION CALLS.</p><p>The query idea and most of the code comes from a lesson on AngularFire called <a href="https://angularfirebase.com/lessons/state-changes-angularfire2-with-ngrx/">“AngularFire2 State Changes With NgRx”</a>. There the query action is dispatched in the init function of a component. In my case, I prefer to load the data when the effect is initialised as below.</p><pre>ngrxOnInitEffects(): Action {<br>  return new Query();<br>}</pre><p>Everything stays in the effect class and the component only has to use the selector and dispatch actions on create, modify and delete.</p><p>The dispatch of the AddedAll function in the effect could be setup differently with some rxjs operator and avoid using the store service in the effect. But right now I couldn’t figure it out. If you have any suggestion I appreciate your comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e44ef5eff771" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Responsive plain CSS slide / fade show]]></title>
            <link>https://medium.com/@michael.warneke/responsive-plain-css-slide-fade-show-332a8febdb81?source=rss-3182934241f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/332a8febdb81</guid>
            <category><![CDATA[slider]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[image]]></category>
            <dc:creator><![CDATA[Michael Warneke]]></dc:creator>
            <pubDate>Mon, 21 May 2018 06:20:39 GMT</pubDate>
            <atom:updated>2018-05-21T07:16:12.692Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*bYRtwLyNjvdELkEADWQsPA.gif" /></figure><p>For a current project with plain css / js I needed an image fader animation. There are a lot of examples out there but unfortunately, it was quite hard to find something responsive. That’s why I had to adjust and combine the examples and created my own.</p><p>The html part is quite simple. There is a container and the elements. The elements even got a text wich will be overlayed on top of the image.</p><pre>&lt;div id=”slide-container”&gt;<br> &lt;div id=”slide-first-element”&gt;<br>  &lt;img class=”slide-image” src=”./images/01.jpg”&gt;<br>  &lt;p class=”slide-text”&gt;Beautiful&lt;/p&gt;<br> &lt;/div&gt;<br> &lt;div id=”slide-element-2&quot;&gt;<br>  &lt;img class=”slide-image” src=”./images/02.jpg”&gt;<br>  &lt;p class=”slide-text”&gt;Amazing&lt;/p&gt;<br> &lt;/div&gt;<br> &lt;div id=”slide-element-3&quot;&gt;<br>  &lt;img class=”slide-image” src=”./images/03.jpg”&gt;<br>  &lt;p class=”slide-text”&gt;Incredible&lt;/p&gt;<br> &lt;/div&gt;<br>&lt;/div&gt;</pre><p>The first element has to be treated different than the other elements to be ready for responsiveness. When the images doesn’t get fixed sizes the container will be calculated with 0. To work around that the first image is set like a normal image and the others are overlayed with their relative dimensions. That’s where all the other examples in the web failed.</p><p>The css part is straight forward as well. First the container will be styled, than the elements and the animations in the end.</p><pre>/* Slider */<br>/* Slideshow container */<br>#slide-container {<br> position: relative;<br> max-width: 800px; /* responsiveness */<br>}</pre><pre>/* First element to be in block mode for responsiveness */<br>#slide-first-element {<br> display: block; /* to get the dimensions set */<br> width: 100%;<br> height: auto;<br>}</pre><pre>/* Other element to be in absolute position */<br>#slide-element-2,<br>#slide-element-3 {<br> position: absolute;<br> width: 100%;<br> height: 100%;<br> top: 0;<br> bottom: 0;<br> left: 0;<br> right: 0;<br>}</pre><pre>/* Style images */<br>.slide-image {<br> width: 100%;<br> border-radius: 20px;<br>}</pre><pre>/* Style text */<br>.slide-text {<br> position: absolute;<br> bottom: 10px;<br> background-color: #0042b1bb;<br> color: white;<br> width: 100%;<br> text-align: center;<br> font-size: 1.5rem;<br>}</pre><pre>/* Animation settings for individual elements */<br>/* For more images the animations have to be adjusted */<br>#slide-first-element {<br> animation: fade-1 10s infinite;<br> -webkit-animation: fade-1 10s infinite;<br>}</pre><pre>#slide-element-2 {<br> animation: fade-2 10s infinite;<br> -webkit-animation: fade-2 10s infinite;<br>}</pre><pre>#slide-element-3 {<br> animation: fade-3 10s infinite;<br> -webkit-animation: fade-3 10s infinite;<br>}<br>/* and more if there are more slides to show */</pre><pre>@keyframes fade-1 {<br> 0% { opacity: 1; }<br> 33% { opacity: 0; }<br> 66% { opacity: 0; }<br> 100% { opacity: 1; }<br>}</pre><pre>@keyframes fade-2 {<br> 0% { opacity: 0; }<br> 33% { opacity: 1; }<br> 66% { opacity: 0; }<br> 100% { opacity: 0; }<br>}</pre><pre>@keyframes fade-3 {<br> 0% { opacity: 0; }<br> 33% { opacity: 0; }<br> 66% { opacity: 1; }<br> 100% { opacity: 0; }<br>}</pre><pre>/* example for a 4th slide */<br>@keyframes fade-4 {<br> 0% { opacity: 0; }<br> 25% { opacity: 0; }<br> 50% { opacity: 0; }<br> 75% { opacity: 1; }<br> 100% { opacity: 0; }<br>}</pre><p>This example goes with 3 elements. To use it with a different amount the animations have to be adjusted like the last example for a 4th slide is showing.</p><p>This might not be the best solution and there might be possible improvements of the code, but that’s what I found out so far. You are welcome to comment if you get a better idea and I can bring it up here as well.</p><p>The code can also be found on my <a href="https://github.com/MichaelWarneke/css-fade-show">github here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=332a8febdb81" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Merging Custom Angular Schematics]]></title>
            <link>https://medium.com/@michael.warneke/merging-custom-angular-schematics-c14a303f63b6?source=rss-3182934241f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c14a303f63b6</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[ngrx]]></category>
            <category><![CDATA[angular-cli]]></category>
            <dc:creator><![CDATA[Michael Warneke]]></dc:creator>
            <pubDate>Thu, 08 Mar 2018 09:13:31 GMT</pubDate>
            <atom:updated>2018-03-08T09:13:31.975Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*x_aKtTElLbljY9s9Yrm0_g.png" /></figure><p>Since the angular devkit team released a schematic version where you are able to extend your custom schematics, it is quite simple to have it inherit from other schematics. This will allow you to set your default schematics in your angular cli project to your custom one and still be able to “ng generate …” all the other generators from the extended ones.</p><h3>How was it before?</h3><p>In the past you were able to link your custom schematics folder to your cli project as descripted in the <a href="https://blog.angular.io/schematics-an-introduction-dc1dfbc2a2b2">angular blog by Hans</a> or just copy the folder to the node_modules. But in this case you have to call your generators by adding the project name like</p><pre>ng g &lt;project-name&gt;:&lt;generator&gt;</pre><pre>or adding the collection flag</pre><pre>ng g &lt;my-generator&gt; --collection &lt;my-collection&gt;</pre><p>Or you have to install your schematics (via npm or copy folder) into your project and using them as the default ones in the angular-cli.json.</p><pre>“defaults”: {<br> “schematics”: {<br>   “collection”: “<a href="http://twitter.com/tmp/schematics">&lt;my-collection&gt;</a>”<br> },<br> “styleExt”: “css”,<br> “component”: {}<br>}</pre><p>Than you were able to call your generators just like the cli generators.</p><pre>ng g &lt;my-generator&gt;</pre><p>But all the other cli generators are not reachable anymore as your custom collection has no information about class, interface, module, etc.</p><p>It was possible to add them individually in your custom collection.json.</p><pre>“class”: {<br> “aliases”: [ “cl” ],<br> &quot;extends&quot;: &quot;<a href="http://twitter.com/schematics/angular">@schematics/angular</a>:class&quot;<br> },<br>...</pre><p>But the list has to be kept maintained with the current angular generators.</p><h3>How to use the extends property?</h3><p>In July 2017 Hans from the angular team raised an <a href="https://github.com/angular/devkit/issues/34">issue</a> in the angular devkit to implement the merging of different schematics. His description of how to solve the problem is pretty much what the outcome of the update.</p><p>When creating your own schematics you can extend these for example from @schematics/angular to keep all cli generators in place. The extends property can be one string or an array of strings giving the opportunity to extend from multiple schematics. Like in his example.</p><pre>//Taken from issue #34 of the angular devkit<br>{<br>  &quot;$schema&quot;: &quot;http://schema.angular.io/schematics/collection/2&quot;,<br>  &quot;name&quot;: &quot;my-com&quot;,<br>  &quot;description&quot;: &quot;My Company default collection, containing all schematics that are used normally&quot;,<br>  &quot;extends&quot;: [<br>    &quot;@schematics/angular&quot;,<br>    &quot;@my-company/schematics-base&quot;,<br>    &quot;@my-company/schematics-pages&quot;<br>  ],<br>  &quot;schematics&quot;: {<br>  }<br>}</pre><pre>This would include the base angular schematics, the base my-company  schematics and the pages schematics. This helps with separating  development of each of those, while the end user can just install and  use one collection. The schematics are merged, with names being  overridden by pages, then base, then angular.</pre><p>The only difference I noticed so far (@angular-devkit v0.4.3) is that the overriding is from first to last in that array. Meaning, for example if @my-company/schematics-base is overriding the class generator it will be used instead the one from @schematics/angular.</p><p>By doing it this way your custom schematics can be deployed to npm and imported to any cli project (or link or copy the folder manually into node_modules) and used as the default schematics and all generators can be called by just</p><pre>ng g &lt;any-generator&gt;</pre><p>If you don’t want to write your own schematics but want to merge multiple third party ones this approach works pretty good as well. Only con is you have to create an empty schematic and merge the libraries you want to use. Than import your empty schematics and viola.</p><h3>Other possibilities</h3><p>I started a small project to check if I can even extend public schematics like the ones from @ngrx/schematics and @nrwl/schematics. The project is located at <a href="https://github.com/MichaelWarneke/ng-schematics">github</a>. It is not completed and I am still playing around with the extends property.</p><p>The only thing which can be a problem is that both of the schematics are extending the cli generators individually (discussed above). So in the end the class, module, service, etc generators are used which ever schematic is at the end of the extends array.</p><pre>&quot;extends&quot;: [<br>  &quot;@schematics/angular&quot;, //this class generator is overridden<br>  &quot;@nrwl/schematics&quot;, //this class generator is overridden<br>  &quot;@ngrx/schematics&quot; //this class generator is used<br>],<br>&quot;schematics&quot;: {<br>  // my onw schematics<br>}</pre><p>In my project I used forked and modified versions of nrwl and ngrx where I changed to the general extends of @schematics/angular. I also released PRs to both (<a href="https://github.com/nrwl/nx/pull/307">nrwl</a>, <a href="https://github.com/ngrx/platform/pull/892">ngrx</a>) projects to get this into the official versions. Another possibility for these kinds of third party schematics would be to not extend from the official angular schematics at all. But in this case the user has to create his own schematics and extend it from the third party and the angular schematics to get the same result. Both variations have their cons and pros and I can imagine cases where both of them are suitable.</p><p>Maybe it makes sense to treat these schematics like individual modules and be able to import an array into the angular-cli.json. Than the user can easily add and remove the ones he want to use and not, without digging to much into the schematics material.</p><h3>Steps to write your own</h3><p>Basically, just follow the blog from Hans <a href="https://blog.angular.io/schematics-an-introduction-dc1dfbc2a2b2">here</a>.</p><p>Install the @angular-devkit/schematics-cli globally either by npm or yarn or whatever package manger you use. Create your schematics project and add your own schematics if you want to. Extend your project from any third party and angular schematics. Publish your project, link it or copy the folder into your cli project and start using your custom schematics and/or enjoy the merging of different third parties.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c14a303f63b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hosting multiple Angular apps on Firebase]]></title>
            <link>https://medium.com/cloudboost/hosting-multiple-angular-apps-on-firebase-fb15e2a9dda9?source=rss-3182934241f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb15e2a9dda9</guid>
            <category><![CDATA[hosting]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Michael Warneke]]></dc:creator>
            <pubDate>Wed, 03 Jan 2018 07:45:46 GMT</pubDate>
            <atom:updated>2020-06-15T13:06:39.921Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*7GWDiMvoI9kDD_eo8NnVtA.png" /></figure><p><strong>Update 2018–12–21</strong>: Firebase accepts multiple apps hosting on the same project no. A good introduction is this video by Jeff Delaney. <a href="https://angularfirebase.com/lessons/deploy-multiple-sites-to-firebase-hosting/">https://angularfirebase.com/lessons/deploy-multiple-sites-to-firebase-hosting/</a></p><p>Having the main and the admin app hosted on Firebase in the same project could be a solution for some environments. In this short blog it is demonstrated how to set it up without going to much into detail about writing Angular apps and Firebase functions.</p><p>The source of the example project can be found <a href="https://github.com/MichaelWarneke/fb-multiple-apps">here</a> on Github and the live version <a href="https://fb-multiple-apps.firebaseapp.com/">here</a>. It was created with <a href="http://nrwl.io/nx">NRWL’s NX</a> cli which is great for building multiple apps in one monorepo.</p><p>Generally it is recommended to have different apps in different projects. And if needed point the different apps to one database. But for some smaller projects it might be easier just to run everything in one place.</p><p>A scenario could be to have the different apps in subfolders and the landing page is just a simple html. Also an api to some firebase functions can be included.</p><pre>www.myside.com  -&gt; static website (index.html, etc)<br>/my-app         -&gt; angular app<br>/admin 		-&gt; second angular app<br>/timestamp	-&gt; some api functions</pre><p>Once the project and firebase is initialized the firebase hosting can be setup with some rewrites in the firebase.json.</p><pre>{<br>  “database”: {<br>    “rules”: “database.rules.json”<br>  },<br>  “hosting”: {<br>    “public”: “dist/apps”,<br>    “ignore”: [“firebase.json”, “**/.*”, “**/node_modules/**”],<br>    “rewrites”: [<br>    {<br>      “source”: “/timestamp”,<br>      “function”: “app”<br>    },<br>    {<br>      “source”: “/my-app/**”,<br>      “destination”: “/my-app/index.html”<br>    },<br>    {<br>      “source”: “/admin/**”,<br>      “destination”: “/admin/index.html”<br>    }]<br>  }<br>}</pre><p>The public property has to point to the folder which includes the static website and the apps in their folders.</p><p>The rewrites take care of the apps and the firebase function.</p><p>First rewrite will point the timestamp to the dedicated firebase function. In this case it is just a simple timestamp function returning the current server time.</p><p>Second rewrite takes care of all request coming to /my-app and redirect them to the index.html of the angular app.</p><p>Third rewrite will do the same with the admin app.</p><p>Now the index.html of the apps need to get their base-href set to the local folders. In this case /my-app/ and /admin/ for the two applications. This can be done when building the apps with the cli using the “--bh” flag. Setting it during the build process keeps the possibility to run the individual apps in debug mode locally with ng serve.</p><p>In the example project a Makefile is used to build both apps with one command.</p><pre>help:<br>  @echo “_______BUILD ANGULAR FRONTEND______\n”<br>  @echo “To build all apps run make”</pre><pre>build-my-app:<br>  ng build -a=my-app --bh /my-app/ --prod --aot</pre><pre>build-admin:<br>  ng build -a=admin --bh /admin/ --prod --aot</pre><pre>all: build-my-app build-admin</pre><p>Once the apps are build into the dist/apps folder a static website can be placed in the same folder and the firebase tool will host everything on firebase.</p><p>Now the landing page for the dedicated project url is setup to be the static page and the apps / firebase functions can be reached in the subfolders.</p><p>If there is some authentication involved the apps share the authentication if firebase auth is used. Meaning if a user signed up in one app the authentication works for all other apps in that project. To protect the admin app from unauthorized access a role system has to be implemented and only users with the admin role should get access to the admin app.</p><h3><strong>Steps for reproduction</strong></h3><p>Creating the workspace</p><pre>curl -fsSL https://raw.githubusercontent.com/nrwl/nx/master/packages/install/install.sh | bash -s fb-multiple-apps</pre><p>Create a firebase project on firebase.com and init the workspace with that project. Select hosting, functions and database.</p><pre>firebase init</pre><p>Change the firebase.json as described above and optional create a Makefile.</p><p>Create the two apps and change the app.component.html to your preference to identify which app is loaded.</p><pre>ng g app my-app<br>ng g app admin</pre><p>Now the apps can be build to production using the Makefile or by building them manually.</p><pre>ng build -a=my-app — bh /my-app/ — prod — aot<br>ng build -a=admin — bh /admin/ — prod — aot</pre><p>Create a function to test the api calls in the functions/index.js.</p><pre>const functions = require(“firebase-functions”);<br>const express = require(“express”);<br>const app = express();</pre><pre>app.get(“/timestamp”, (request, response) =&gt; {<br>  response.send(`${Date.now()}`);<br>});</pre><pre>exports.app = functions.https.onRequest(app);</pre><p>Create an index.html in the dist/apps folder as the sample static website.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>  &lt;meta charset=&quot;utf-8&quot;&gt;<br>  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;<br>  &lt;title&gt;Firebase Multiple Apps Example&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;div id=”message”&gt;<br>    &lt;h2&gt;Welcome&lt;/h2&gt;<br>    &lt;h1&gt;Firebase Multiple Apps Example&lt;/h1&gt;<br>    &lt;a href=”/my-app”&gt;Go to the app&lt;/a&gt;<br>    &lt;a href=”/admin”&gt;Admin&lt;/a&gt;<br>    &lt;a href=”/timestamp”&gt;Timestamp&lt;/a&gt;<br>  &lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Now you can test it using firebase serve or deploy it to the server.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb15e2a9dda9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cloudboost/hosting-multiple-angular-apps-on-firebase-fb15e2a9dda9">Hosting multiple Angular apps on Firebase</a> was originally published in <a href="https://medium.com/cloudboost">CloudBoost</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NGRX get data from Firestore (part 1)]]></title>
            <link>https://medium.com/@michael.warneke/ngrx-get-data-from-firestore-part-1-6f6688946c46?source=rss-3182934241f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f6688946c46</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[firestore]]></category>
            <category><![CDATA[ngrx]]></category>
            <category><![CDATA[angularfire2]]></category>
            <dc:creator><![CDATA[Michael Warneke]]></dc:creator>
            <pubDate>Tue, 05 Dec 2017 17:32:38 GMT</pubDate>
            <atom:updated>2018-01-04T06:08:39.885Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*KCqFFrw54XMOM_xvuzT_Wg.png" /></figure><p>In this episode I want to discuss the different possibilities to load data from <a href="https://firebase.google.com/docs/firestore/">Firestore </a>into an NGRX environment using the <a href="https://github.com/angular/angularfire2">angularfire2 </a>library. There are a lot of examples out there which are individually discussed and analysed, but there is no comparison with other procedures and combinations.</p><p>Not only fetching data from Firestore and place it somehow in the NGRX store, also the authentication handling can be tricky and has lots of different approaches. This blog will discuss this matter as well.</p><p>As I like the approach of <a href="https://nrwl.io/nx">Nx </a>from <a href="https://nrwl.io/">Nrwl </a>to set up a project with different libs in one mono repository the examples will be implemented in these libs lazy loaded.</p><h3><strong>First: State Changes in Effects class</strong></h3><p>The first part will look into the Firestore <a href="https://github.com/angular/angularfire2/blob/master/docs/firestore/collections.md">stateChanges()</a> function and how to bring it together with NGRX.</p><pre>// How a function in a db service could look like<br>getFakeDataStateChanges(): Observable&lt;DocumentChangeAction[]&gt;{<br>  return this.afs.collection&lt;FakeData&gt;(&#39;fake-data&#39;).stateChanges();<br>}</pre><p>This function returns an Observable of a list of <a href="https://github.com/angular/angularfire2/blob/master/docs/firestore/collections.md">DocumentChangeActions</a>. These actions are very similar to the ones from NGRX. They come with a type and a payload. The type can be ‘added’, ‘modified’ or ‘removed’ and the payload will carry the document beside some other meta data.</p><p>To get the data into the store one way is to convert these actions into the store actions.</p><pre>@Effect()<br>getData$ = this.dataDb.getFakeDataStateChanges().pipe(<br>  mergeMap(actions =&gt; actions),<br>  map(action =&gt; {<br>    return {<br>      type: `[FirstData] ${action.type}`,<br>      payload: { <br>        id: action.payload.doc.id, <br>        ...action.payload.doc.data() <br>      }<br>    };<br>  })<br>);</pre><p>In the above effect the actions received from Firestore are mapped into store actions. The store action types are basically the same as the actions coming from Firestore but with an identifier at the start ‘[FirstData]’.</p><pre>export enum FirstActionTypes {<br>  FIRST_DATA_ADDED = &#39;[FirstData] added&#39;,<br>  FIRST_DATA_MODIFIED = &#39;[FirstData] modified&#39;,<br>  FIRST_DATA_REMOVED = &#39;[FirstData] removed&#39;<br>}</pre><p>I prefer to use enums as action types to keep it type-safe.</p><p>Finally the reducer will handle all the actions and updates the store.</p><pre>export function firstReducer(state: State, action: FirstAction) {<br>  switch (action.type) {</pre><pre>    case FirstActionTypes.FIRST_DATA_ADDED:<br>      return firstAdapter.addOne(action.payload, state);</pre><pre>    case FirstActionTypes.FIRST_DATA_MODIFIED:<br>      return firstAdapter.updateOne({<br>        id: action.payload.id,<br>        changes: action.payload<br>      },state);</pre><pre>    case FirstActionTypes.FIRST_DATA_REMOVED:<br>      return firstAdapter.removeOne(action.payload.id, state);</pre><pre>    default: {<br>      return state;<br>    }<br>  }<br>}</pre><p>In the above reducer the NGRX <a href="https://github.com/ngrx/platform/blob/master/docs/entity/README.md">entity </a>functionality is used to handle the list.</p><p>And that’s basically everything you need to have the store in sync with the database. The effect will start listening as soon as the effect class is instantiated and gets all items from the list. Once the data in the database changes the effect will call the appropriate store actions.</p><p>Changes made to the data in the app can be directed directly to the database without using the store or a store effect has to made the changes to the database without updating the store. That’s because the effect will update the store once the changes returning from the database. Once the changes are handled by the Firestore module the changes will return as mentioned above. This a pessimistic approach.</p><h3><strong>Pros and Cons</strong></h3><p>A big pro of this approach is less boilerplate in the store. There is no need for actions like GET_DATA, DATA_RECEIVED, DATA_RECEIVED_ERROR…</p><p>It just works and the store is always in sync with the database. Even <a href="https://github.com/angular/angularfire2/blob/master/docs/firestore/offline-data.md">offline </a>capabilities are implemented in Firestore with one additional line of code.</p><pre>AngularFirestoreModule.enablePersistence()</pre><p>Down side with this pessimistic approach is that the user will see updates made to the data only after they have been changed in the database and returned. That could take some time and doesn’t reflect an instant native feel app with a local storage. For sure there is a way to implement this with an optimistic pattern and it might be in one of the coming episodes.</p><p>The effect will terminate with an error once the user signs off and the connection to protected data is cut. Therefor a function on the effects class can be used to have the effects only running when the user is authenticated.</p><pre>ngrxOnRunEffects(resolvedEffects$: Observable&lt;EffectNotification&gt;) {<br> return this.actions.ofType(AuthActionTypes.SET_AUTHENTICATED).pipe(<br>   exhaustMap(() =&gt; resolvedEffects$.pipe(<br>     takeUntil(this.actions.ofType(<br>		AuthActionTypes.SET_NOT_AUTHENTICATED)))))<br>}</pre><p>Unfortunately, with NGRX v4.1.1 there is bug in the store and with above function in place the actions fired by the effect will not reach the store. Meaning on reload the data will not be loaded. The bug is already solved by PR <a href="https://github.com/ngrx/platform/pull/570">https://github.com/ngrx/platform/pull/570</a> and it should work with the next release.</p><h3><strong>Second: State Changes in Service</strong></h3><p>Instead of using an effect to update the store a service can be used to it.</p><pre>@Injectable()<br>export class SecondService implements OnDestroy {<br>  dataSub: Subscription;<br>  constructor(private store: Store&lt;any&gt;, private db: DataDbService){<br>    this.dataSub = this.db.getFakeDataStateChanges()<br>      .subscribe(actions =&gt; {<br>	actions.forEach(action =&gt;<br>	  this.store.dispatch({<br>	    type: `[SecondData] ${action.type}`,<br>    	    payload: { <br>	      id: action.payload.doc.id, <br>	      …action.payload.doc.data() <br>	    }<br>	  })<br>        )<br>      })<br>  }</pre><pre>  ngOnDestroy() {<br>    this.dataSub.unsubscribe();<br>  }<br>  <br>  getData() {<br>    return this.store.select(selectSecondAll);<br>  }<br>}</pre><p>In this case the risk that the effect will break the hole effect class is avoided. But as it uses subscribe to dispatch the actions the unsubscribe should not forgotten. The service should be in the module as the store or partial store.</p><p>The code can be found at <a href="https://github.com/MichaelWarneke/ngrx-firestore-examples">https://github.com/MichaelWarneke/ngrx-firestore-examples</a> and the first approach is settled in the lib ‘first’.</p><p>In future posts I will look into other ways of handling the same constellation and I appreciate comments and remarks to have a discussion to find betters ways of best practice.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f6688946c46" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>