<?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>Tutorial Archives - Nerd Corner</title>
	<atom:link href="https://nerd-corner.com/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerd-corner.com/tag/tutorial/</link>
	<description>Craft your dreams!</description>
	<lastBuildDate>Sun, 05 Dec 2021 03:36:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>

<image>
	<url>https://nerd-corner.com/wp-content/uploads/2019/10/cropped-LogoNerdCorner-2-32x32.png</url>
	<title>Tutorial Archives - Nerd Corner</title>
	<link>https://nerd-corner.com/tag/tutorial/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to build a PUSH based architecture in Angular &#8211; Facade Design Pattern</title>
		<link>https://nerd-corner.com/how-to-build-a-push-based-architecture-in-angular-facade-design-pattern/</link>
					<comments>https://nerd-corner.com/how-to-build-a-push-based-architecture-in-angular-facade-design-pattern/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Sun, 05 Dec 2021 03:36:36 +0000</pubDate>
				<category><![CDATA[Angular]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[angular]]></category>
		<category><![CDATA[angularjs]]></category>
		<category><![CDATA[behavior subject description: Make Reactive Applications]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[observables]]></category>
		<category><![CDATA[Push Based Architecture with RxJS]]></category>
		<category><![CDATA[Remove term: Push Based Architecture with RxJS tags: angular Push Based Architecture with RxJS]]></category>
		<category><![CDATA[rxjs]]></category>
		<category><![CDATA[rxjs observables]]></category>
		<category><![CDATA[state management]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[typescript]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/?p=1095</guid>

					<description><![CDATA[<p>Typically, a PULL-based architecture is used in software development and only rarely a PUSH-based architecture. A service is called to request data from a server, &#8230; </p>
<p>The post <a href="https://nerd-corner.com/how-to-build-a-push-based-architecture-in-angular-facade-design-pattern/">How to build a PUSH based architecture in Angular &#8211; Facade Design Pattern</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Typically, a PULL-based architecture is used in software development and only rarely a PUSH-based architecture. A service is called to request data from a server, which sends a request to the server and receives the required data. However, during this process, the main UI thread is blocked.</p>
<p>Angular itself regularly checks the view model for changes. If the view model changes due to a state change, Angular re-renders the view because Angular automatically adjusts the UI when the model changes. These continuous observations make the whole application slower.</p>
<p>Moreover, with the traditional pull approach, complexity increases. Especially when multiple views need the same data. What happens when the data changes? How are views notified that new data is available? Callback functions could help, but as a result, the application quickly becomes confusing. They also have a negative impact on handling and maintenance, especially for larger applications. After all, the objects have to be initialized individually and the dependencies or the order of the methods have to be considered.</p>
<p>A push-based architecture can be used to avoid this problem. Angular offers a great way to implement this with RxJS and the facades design pattern! The implementation is explained using an Angular example in this blog article and is transferable for all platforms and frameworks (Angular, React, Vue.js, etc.).</p>
<h2>List of components</h2>
<ul>
<li>IDE (Visual Studio Code)</li>
<li>Angular CLI</li>
</ul>
<p><img fetchpriority="high" decoding="async" class="aligncenter wp-image-1110 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/11/RandomBeerPUSH.png" alt="Push based Architecture Facade Service example" width="650" height="443" srcset="https://nerd-corner.com/wp-content/uploads/2021/11/RandomBeerPUSH.png 659w, https://nerd-corner.com/wp-content/uploads/2021/11/RandomBeerPUSH-300x204.png 300w" sizes="(max-width: 650px) 100vw, 650px" /></p>
<h2>What is a facade actually?</h2>
<p>The facade design pattern is a central interface that communicates with various interfaces of one or more lower-level subsystems. It can perform additional functions both before and after a client request.</p>
<p>The facade object provides a unified and usually simplified interface to one or more subsystems. As an intermediary, it ensures that communication or access to the individual components of a subsystem is simplified, thereby also minimizing direct dependence on these components. It delegates the client calls in such a way that clients need to know neither the classes nor their relations and dependencies.</p>
<p>This is especially helpful in large systems when a subsystem contains many technically oriented classes that are rarely used externally. Using a facade reduces complexity by combining multiple interfaces into one. In addition, the subsystem can be extended more easily due to the loose coupling.</p>
<h2>The PUSH Architecture</h2>
<p>For a push based architecture, advanced design patterns like Redux or NgRx can be used. However, a very elegant and performant push based solution can also be achieved using RxJS.</p>
<p>Using the long-living RxJS Observable streams, changes in the data can be pushed to all subscribers. To do so, the views subscribe to the desired data stream. If the data changes, the changes are pushed directly to all subscribers via the stream without blocking the UI thread.</p>
<p>In this way, direct data access is prevented and the data is read-only. The actual data source is accessed similar to an API used by the views. The facade described at the beginning serves as the central interface here. This consists of streams that provide data when the data changes and methods to request changes to the data or request specific user-defined streams.</p>
<p>The actual raw data is only available after it has been pushed through the stream(s). This shielding centralizes all logic and forces views to passively respond to incoming data. With the push based services, Angular View components become highly performant using both ChangeDetectionStrategy.OnPush, and the async pipe for the delivered stream data.</p>
<p>Therefore, the system is lazy loading. The UI framework does not need to check for state changes of the view model and instead lazily waits for a new state to be pushed.</p>
<h2>Practical example</h2>
<p>As an example for a push based architecture a simple application is used, which receives a random beer type via the HTTP request https://random-data-api.com/api/beer/random_beer?size=1. The type of beer is displayed in a view. An input field can be used to vary the number of beers to be shown. A facade as a central element automatically pushes the new beers to the view as soon as they are available.</p>
<p><img decoding="async" class="aligncenter wp-image-1120 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/11/facade_explanation-1.png" alt="PUSH vs PULL based architecture facade design Angular" width="1275" height="717" srcset="https://nerd-corner.com/wp-content/uploads/2021/11/facade_explanation-1.png 1280w, https://nerd-corner.com/wp-content/uploads/2021/11/facade_explanation-1-300x169.png 300w, https://nerd-corner.com/wp-content/uploads/2021/11/facade_explanation-1-1024x576.png 1024w, https://nerd-corner.com/wp-content/uploads/2021/11/facade_explanation-1-768x432.png 768w" sizes="(max-width: 1275px) 100vw, 1275px" /></p>
<p>As a basis for the design pattern serves the article by Thomas Burleson: <a href="https://thomasburlesonia.medium.com/push-based-architectures-with-rxjs-81b327d7c32d" target="_blank" rel="noopener">https://thomasburlesonia.medium.com/push-based-architectures-with-rxjs-81b327d7c32d</a></p>
<h3>The first step is to set up the state management:</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="atomic">export interface Beer {
  brand: string;
  name: string;
  style: string;
  hop: string;
  alcohol: string;
}

export interface BeerState {
  beerArray: Beer[];
  size: number;
}</pre>
<h3>Next, we initialize the values of the facade&#8217;s state management:</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="atomic">export interface BeerState {
  beerArray: Beer[];
  size: number;
}

let _state: BeerState = {
  beerArray: [],
  size: 4
};</pre>
<h3>The facade uses RxJS streams to push data directly to the views. These streams can also automatically execute a Rest API call when the states change:</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="atomic">combineLatest(this.size$)
      .pipe(
        //switchMap: Maps values to observable. Cancels the previous inner observable.
        switchMap(([size]) =&gt; {
          return this.findBeerArray(size);
        })
      )
      .subscribe((beerArray) =&gt; {
        this.updateState({ ..._state, beerArray });
      });</pre>
<h3>Streams are set up to be persistent and only become active when data changes:</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="atomic">export class BeerFacade {

  beerArray$ = this.state$.pipe(
    map((state) =&gt; state.beerArray),
    distinctUntilChanged()
  );

  size$ = this.state$.pipe(
    map((state) =&gt; state.size),
    distinctUntilChanged()
  );

  private updateState(state: BeerState) {
    this.store.next((_state = state));
  }
}
</pre>
<h3>For better management, the streams are combined into a single one:</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="atomic">vm$: Observable&lt;BeerState&gt; = combineLatest(this.beerArray$, this.size$).pipe(
    map(([beerArray, size]) =&gt; {
      return { beerArray, size };
    })
  );</pre>
<h5>The HTTP request can be outsourced to a separate data service. However, since this is only a small sample program, the Rest API call is implemented and executed within the Facade:</h5>
<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="atomic">/** RandomBeer REST call */
  private findBeerArray(size: number): Observable&lt;Beer[]&gt; {
    const url = `https://random-data-api.com/api/beer/random_beer?size=${size}`;
    return this.http.get&lt;Beer[]&gt;(url);
  }</pre>
<h3>The facade and view model stream can now be easily initialized and used. Incredibly less code is required:</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="atomic">export class AppComponent {
  vm$: Observable&lt;BeerState&gt; = this.facadeService.vm$;

  //facadeService is public for direct usage in html
  constructor(public facadeService: RandomBeerFacadeService) {} 
  title = 'RandomBeerApp';
}</pre>
<h3>The view model stream data is displayed with the following code snippet:</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="atomic">&lt;div *ngIf="vm$ | async as vm"&gt;  
  &lt;ul&gt;
    &lt;li id="random-beer-list" *ngFor="let u of vm.beerArray"&gt;
      Brand: {{ u.brand }}, Alcohol: {{ u.alcohol }}, Hop: {{ u.hop }}
    &lt;/li&gt;
  &lt;/ul&gt;
  &lt;input id="input-rand-beer" type="number" (change)="facadeService.updateSize($event)" /&gt;
&lt;/div&gt;</pre>
<p>Angular&#8217;s Async Pipe ensures that the most current data is always displayed. <a href="https://angular.io/api/common/AsyncPipe" target="_blank" rel="noopener">Here is a detailed explanation of the async pipe.</a></p>
<h5>Since the facade service is declared as public, the inputs are passed directly to the updateSize function of the facade:</h5>
<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="atomic">updateSize(selectedSize: any) {
    const size = selectedSize.target.value;
    this.updateState({ ..._state, size });
  }</pre>
<p>As a result, the application initially displays 4 random beers. Afterwards the number can be increased to 7 by the input field. This calls the updateSize() function, which updates the state of the size$ stream using updateState(). As a result, a new REST call is automatically executed and the result is pushed to the view model. With the help of the async pipe the latest data is displayed. In our case the 7 random beer types.</p>
<p><img fetchpriority="high" decoding="async" class="aligncenter wp-image-1110 zoooom" src="https://nerd-corner.com/wp-content/uploads/2021/11/RandomBeerPUSH.png" alt="Push based Architecture Facade Service example" width="650" height="443" srcset="https://nerd-corner.com/wp-content/uploads/2021/11/RandomBeerPUSH.png 659w, https://nerd-corner.com/wp-content/uploads/2021/11/RandomBeerPUSH-300x204.png 300w" sizes="(max-width: 650px) 100vw, 650px" /></p>
<h3>Finally, it makes sense to test the functionality of the individual facade components:</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="atomic">it('should get individual Observable "stream" of vm data', (done) =&gt; {
    testFacade.vm$.subscribe((vm) =&gt; {
      expect(vm.size).toEqual(initStateMock.size);
      done();
    });
  });

  it('should update state values', (done) =&gt; {
    const updatedStateMock: TestBeerState = {
      beerArray: [
        {
          brand: 'Pabst Blue Ribbon',
          name: 'Two Hearted Ale',
          style: 'Merican Ale',
          hop: 'Sorachi Ace',
          alcohol: '2,9%',
        },
        {
          brand: 'Bud Light',
          name: 'La fin Du Monde',
          style: 'Stout',
          hop: 'Bullion',
          alcohol: '2,7%',
        },
      ],
      size: 2,
    };
    testFacade['updateState'](updatedStateMock);
    testFacade.vm$.subscribe((vm) =&gt; {
      expect(vm).toEqual(updatedStateMock);
      done();
    });
  });

  it('should update the size value', (done) =&gt; {
    const newSize = 9;
    const mockEvent = {
      target: {
        value: newSize,
      },
    };
    testFacade['updateSize'](mockEvent);
    testFacade.vm$.subscribe((vm) =&gt; {
      expect(vm.size).toEqual(newSize);
      done();
    });
  });

  it('should perform a mocked http request', (done) =&gt; {
    const httpMock: HttpTestingController = TestBed.inject(
      HttpTestingController
    );

    const mockResponse = {
      brand: 'Pabst Blue Ribbon',
      name: 'Two Hearted Ale',
      style: 'Merican Ale',
      hop: 'Sorachi Ace',
      alcohol: '2,9%',
    };

    testFacade['findBeerArray'](1);
    testFacade.vm$.subscribe((tb) =&gt; {
      expect(tb.beerArray).toBeTruthy();
      expect(tb.beerArray[0].brand).toBe(mockResponse.brand);
      expect(tb.beerArray[0].name).toBe(mockResponse.name);
      expect(tb.beerArray[0].style).toBe(mockResponse.style);
      expect(tb.beerArray[0].hop).toBe(mockResponse.hop);
      expect(tb.beerArray[0].alcohol).toBe(mockResponse.alcohol);

      done();
    });

    const mockRequest = httpMock.expectOne(
      'https://random-data-api.com/api/beer/random_beer?size=1'
    );
    mockRequest.flush(mockResponse);
  });</pre>
<p>The post <a href="https://nerd-corner.com/how-to-build-a-push-based-architecture-in-angular-facade-design-pattern/">How to build a PUSH based architecture in Angular &#8211; Facade Design Pattern</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/how-to-build-a-push-based-architecture-in-angular-facade-design-pattern/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>SolidWorks &#8211; Stand design and 3D print</title>
		<link>https://nerd-corner.com/solidworks-tutorial-stand-design-and-3d-print/</link>
					<comments>https://nerd-corner.com/solidworks-tutorial-stand-design-and-3d-print/#comments</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Sun, 19 Jul 2020 12:28:23 +0000</pubDate>
				<category><![CDATA[SolidWorks]]></category>
		<category><![CDATA[3D print]]></category>
		<category><![CDATA[magnet]]></category>
		<category><![CDATA[magnet board]]></category>
		<category><![CDATA[magnetic wall]]></category>
		<category><![CDATA[SolidWorks Tutorial]]></category>
		<category><![CDATA[Stand]]></category>
		<category><![CDATA[Tutorial]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/?p=622</guid>

					<description><![CDATA[<p>SolidWorks is a three-dimensional CAD program. CAD means &#8220;computer aided design&#8221;. The SolidWorks software can be used to develop a model and simulate how it &#8230; </p>
<p>The post <a href="https://nerd-corner.com/solidworks-tutorial-stand-design-and-3d-print/">SolidWorks &#8211; Stand design and 3D print</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>SolidWorks is a three-dimensional CAD program. CAD means &#8220;computer aided design&#8221;. The <a href="https://en.wikipedia.org/wiki/SolidWorks" target="_blank" rel="noopener noreferrer">SolidWorks software</a> can be used to develop a model and simulate how it works. There are already some tutorials on the Internet. Unfortunately, their models are often not feasible in production or are never really “brought to life” for various reasons. However, we have made a firm commitment to really create each of our designs with a 3D printer to demonstrate that our components actually work. This SolidWorks Tutorial stand design and 3D print is easy to follow and good for learning.</p>
<p>My girlfriend and I collected a magnet from every vacation spot. In the post <a href="https://nerd-corner.com/how-to-transform-old-pc-screen-to-beautiful-magnetic-wall/" target="_blank" rel="noopener noreferrer">&#8220;How to transform old PC screen to beautiful magnetic wall&#8221;</a> I gave my girlfriend a magnet board as a Christmas present. This was built from an old LCD screen. The stand of the magnetic board was designed in SolidWorks. The following steps show exactly how to recreate this stand construction.</p>
<p><a href="https://youtu.be/cvSBddL-_S4" target="_blank" rel="noopener noreferrer"><em>Click here if you want to see the 3D print time lapse.</em></a></p>
<h2>Step 1 – Designing the middle part</h2>
<p>We divide the SolidWorks Tutorial stand design into 3 parts and plug them together to form a strip. If we would design the stand as a long, single piece, it would be too large for the 3D printer and could therefore not be realized.</p>
<p>It is advisable to start with the middle piece. After the construction of the middle piece we save it and can then use it as a template for the left and right pieces of the stand. The left and right part only needs to be slightly modified.</p>
<p><iframe hcb-fetch-image-from="https://www.youtube.com/watch?v=ezoB5Az7ji0" title="SolidWorks Tutorial: Stand with LED strip // Part 1 (Creating the middle stand)" width="1200" height="675" src="https://www.youtube.com/embed/ezoB5Az7ji0?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<h2>Step 2 – Designing the right part</h2>
<p>As mentioned in the first step, the file of the centerpiece can be loaded here and only needs to be modified slightly.</p>
<p><iframe loading="lazy" hcb-fetch-image-from="https://www.youtube.com/watch?v=Sei9jKJUVPk&amp;t=0s" title="SolidWorks Tutorial: Stand with LED strip // Part 2 (Creating the right stand)" width="1200" height="675" src="https://www.youtube.com/embed/Sei9jKJUVPk?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<h2>Step 3 – Designing the left part</h2>
<p>Here the middle piece can also serve as a template and only needs to be slightly modified. In addition, a few recesses are added for the electronics.</p>
<p><iframe loading="lazy" hcb-fetch-image-from="https://www.youtube.com/watch?v=AFn5QecLVIM&amp;0s" title="SolidWorks Tutorial: Stand with LED strip // Part 3 (Creating the left stand)" width="1200" height="675" src="https://www.youtube.com/embed/AFn5QecLVIM?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<h2>Optional: Step 4 – Assemble all parts together in SolidWorks</h2>
<p>For our purpose, it is not necessary to put the individual pieces together in SolidWorks. But it is definitely a good practice for our Solid Works: Design stand tutorial!</p>
<p><iframe loading="lazy" hcb-fetch-image-from="https://www.youtube.com/watch?v=4pGhzJFRD7k&amp;0s" title="SolidWorks Tutorial: Stand with LED strip // Part 4 (Assembling all parts together)" width="1200" height="675" src="https://www.youtube.com/embed/4pGhzJFRD7k?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<h2>Step 5 – Slicing with Cura and 3D printing the parts</h2>
<p>After the work is done, you want to hold the result in your hands. Therefore, the following video shows how to print out the designed component.</p>
<p><iframe loading="lazy" hcb-fetch-image-from="https://www.youtube.com/watch?v=cvSBddL-_S4&amp;0s" title="SolidWorks Tutorial: Stand with LED strip // Part 5 (3D Printing)" width="1200" height="675" src="https://www.youtube.com/embed/cvSBddL-_S4?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<h2>Download files</h2>
<ul>
<li><a href="https://cults3d.com/en/3d-model/various/stand-for-magnet-board" target="_blank" rel="nofollow noopener noreferrer">STL files for the magnet board</a></li>
</ul>
<p>The post <a href="https://nerd-corner.com/solidworks-tutorial-stand-design-and-3d-print/">SolidWorks &#8211; Stand design and 3D print</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/solidworks-tutorial-stand-design-and-3d-print/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
