<?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 Benjamin Canape on Medium]]></title>
        <description><![CDATA[Stories by Benjamin Canape on Medium]]></description>
        <link>https://medium.com/@benjamin.canape?source=rss-9bbabe36a3fd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wo2zVb3X0YSzwHaGOP1N7Q.png</url>
            <title>Stories by Benjamin Canape on Medium</title>
            <link>https://medium.com/@benjamin.canape?source=rss-9bbabe36a3fd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 04:31:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@benjamin.canape/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[Best Practices when using RxJS in Angular]]></title>
            <link>https://medium.com/@benjamin.canape/best-practices-when-using-rxjs-in-angular-e1e3e210b304?source=rss-9bbabe36a3fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1e3e210b304</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[rxjs]]></category>
            <dc:creator><![CDATA[Benjamin Canape]]></dc:creator>
            <pubDate>Sat, 01 Feb 2025 13:34:06 GMT</pubDate>
            <atom:updated>2025-02-02T20:06:45.035Z</atom:updated>
            <content:encoded><![CDATA[<p>RxJS is a powerful library for handling reactive programming in Angular applications. While it provides flexibility and control over asynchronous operations, improper usage can lead to memory leaks, performance issues, and unreadable code. This article explores best practices to ensure efficient and maintainable RxJS usage in Angular.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oHxbVjUlnKPg2qzF5joZsw.png" /></figure><h4>1. Use the Right Operators</h4><p>Choosing the correct RxJS operators is crucial for performance and readability.</p><ul><li>Use <strong>map()</strong> instead of <strong>tap()</strong> when transforming data.</li><li>Prefer <strong>switchMap()</strong> over <strong>mergeMap()</strong> for HTTP requests to cancel previous ones.</li></ul><pre>this.searchInput.valueChanges.pipe(<br>  debounceTime(300),<br>  distinctUntilChanged(),<br>  switchMap(searchTerm =&gt; this.noteService.searchNotes(searchTerm))<br>).subscribe();</pre><h4>2. Manage Subscriptions Properly</h4><p>Unmanaged subscriptions can cause memory leaks, leading to performance degradation over time.</p><ul><li>Use the <strong>async </strong>pipe in templates to handle subscriptions automatically.</li><li>Use <strong>takeUntil()</strong> with a subject to manage component lifecycle.</li><li>Use <strong>take(1) </strong>when<strong> </strong>you need only the first emitted value</li><li>Complete your <strong>Subject </strong>at component destruction</li></ul><pre>private destroy$ = new Subject&lt;void&gt;();<br><br>ngOnInit() {<br>  this.noteService.getNotes()<br>    .pipe(takeUntil(this.destroy$))<br>    .subscribe();<br>}<br><br>ngOnDestroy() {<br>  this.destroy$.next();<br>  this.destroy$.complete();<br>}</pre><h4>3. Avoid Placing Logic Inside subscribe()</h4><p>Placing logic inside <strong>subscribe()</strong> can make code harder to maintain and test.</p><ul><li>Use RxJS operators to transform and handle data before subscribing.</li><li>Chain multiple operators if needed instead of writing complex logic inside subscribe().</li><li>Keep your operators as simple and as short as possible.</li></ul><p>🚫<strong> Avoid this:</strong></p><pre>this.noteService.getNotes().subscribe(notes =&gt; {<br>  const importantNotes = notes.filter(note =&gt; note.important);<br>  console.log(&#39;Important notes:&#39;, importantNotes);<br>  this.notes = importantNotes;<br>});</pre><p><strong>✅ Better approach:</strong></p><pre>this.notes$ = this.noteService.getNotes().pipe(<br>  map(notes =&gt; notes.filter(note =&gt; note.important)),<br>  tap(filteredNotes =&gt; console.log(&#39;Important notes:&#39;, filteredNotes))<br>);</pre><h4>4. Use combineLatest() for Dependent Observables</h4><p>When working with multiple observables that depend on each other, combineLatest() is useful for emitting the latest values whenever one of them changes.</p><ul><li>Use <strong>combineLatest()</strong> when you need the latest values from multiple observables.</li><li>Ensure all observables emit at least one value to avoid unexpected behavior.</li></ul><pre>import { combineLatest } from &#39;rxjs&#39;;<br><br>const noteTitle$ = this.noteService.getNoteTitle();<br>const noteContent$ = this.noteService.getNoteContent();<br><br>combineLatest([noteTitle$, noteContent$]).pipe(<br>    tap(([title, content]) =&gt; {<br>      console.log(`Title: ${title}, Content: ${content}`);<br>    })<br>).subscribe();</pre><p>This ensures that whenever either the title or the content updates, the latest values are always emitted together.</p><h4>5. Use Subjects Wisely</h4><p>Subjects are powerful but should be used carefully to avoid unnecessary complexity.</p><ul><li>Use <strong>BehaviorSubject</strong> when you need an initial value and want subscribers to get the last emitted value.</li><li>Use <strong>ReplaySubject</strong> when you need to replay multiple past values.</li><li>Use <strong>Subject</strong> for event handling, like user actions.</li><li>Don’t overuse <strong>BehaviorSubject</strong> , depending on your need <strong>Signals</strong> might be better.</li></ul><pre>private notesSubject = new BehaviorSubject&lt;Note[]&gt;([]);<br>this.notes$ = this.notesSubject.asObservable();<br><br>updateNotes(newNotes: Note[]) {<br>  this.notesSubject.next(newNotes);<br>}</pre><h4>6. Optimize Performance</h4><p>RxJS provides operators to improve performance and reduce unnecessary computations.</p><ul><li>Use <strong>debounceTime()</strong> and <strong>distinctUntilChanged()</strong> for handling user inputs efficiently.</li><li>Use <strong>shareReplay(1)</strong> for caching API responses.</li></ul><pre>this.notes$ = this.noteService.getNotes().pipe(<br>  shareReplay(1)<br>);</pre><h4>7. Debug RxJS Streams Effectively</h4><p>Debugging RxJS can be challenging, but there are techniques to make it easier.</p><ul><li>Use <strong>tap()</strong> to log intermediate values.</li><li>Use <strong>catchError()</strong> to handle errors with a clean approach.</li></ul><pre>this.notes$ = this.noteService.getNotes().pipe(<br>  tap(notes =&gt; console.log(&#39;Fetched notes:&#39;, notes)),<br>  catchError(error =&gt; {<br>    console.error(&#39;Error fetching notes&#39;, error);<br>    return of([]);<br>  })<br>);</pre><h3>Conclusion</h3><p>Using RxJS effectively in Angular requires following best practices to ensure maintainable, efficient, and bug-free applications. By implementing these practices, your Angular applications will be more scalable, performant, and easier to debug.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1e3e210b304" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NgRx: Mastering State Management in Angular]]></title>
            <link>https://medium.com/@benjamin.canape/ngrx-mastering-state-management-in-angular-a4ebe80d5426?source=rss-9bbabe36a3fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4ebe80d5426</guid>
            <category><![CDATA[better-programming]]></category>
            <category><![CDATA[ngrx]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[state]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Benjamin Canape]]></dc:creator>
            <pubDate>Sun, 05 Jan 2025 18:45:30 GMT</pubDate>
            <atom:updated>2025-01-22T22:23:56.642Z</atom:updated>
            <content:encoded><![CDATA[<p>Managing state in Angular applications can quickly become difficult. Data sharing between components, handling asynchronous operations, and ensuring a predictable flow of data — all of these can turn into challenges as your application grows. NgRx<strong> </strong>, a powerful library inspired by Redux, which offers a robust solution for managing application state is here to help you.</p><p>In this article, we’ll dive into what NgRx is, why it’s beneficial, and how you can use it in your Angular projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*KEZRay9jMAuJcT9NQVCZBw.png" /></figure><h3>What is NgRx?</h3><p>NgRx is a state management library for Angular applications. It is built on the principles of Redux. The idea is simple: keep your application’s state centralized in a store, ensuring that all changes to this state are handled in a structured and predictable way.</p><p>With NgRx, you can:</p><ul><li>Centralize your application’s state.</li><li>Ensure immutability of the state.</li><li>Use a clear flow to modify the state.</li><li>Easily debug and track state changes.</li></ul><h3>Why Use NgRx?</h3><p>NgRx brings a lot of benefits :</p><h4>Centralized State</h4><p>With NgRx, all your application’s data resides in a single store, making it easier to manage and share data across components.</p><h4>Predictable Flow</h4><p>Each change to the state follows a clear and consistent process: <strong>Action → Reducer → New State</strong>. This predictability makes debugging much easier.</p><h4>DevTools Integration</h4><p>NgRx integrates with Redux DevTools, allowing you to visualize actions and state changes in real time.</p><h4>Scalability</h4><p>For large applications with complex data flows, NgRx provides a structured approach that scales well.</p><h4>Asynchronous Handling</h4><p>Using NgRx Effects, you can manage side effects like API calls in a clean and isolated way.</p><h3>When to Use NgRx</h3><p>NgRx is a powerful tool, but it’s not always necessary. Use NgRx if:</p><ul><li>Your application has a complex state that needs to be shared across multiple components.</li><li>You’re dealing with numerous asynchronous operations, like API calls.</li><li>You want a predictable and maintainable state management solution.</li></ul><p>For simpler applications, services and @Input()/@Output() bindings might be sufficient.</p><p>Usually you want to respect the SHARI principle to know when to use NgRx:</p><ul><li>Shared: state that is accessed by many components and services</li><li>Hydrated: state that is persisted and rehydrated from external storage</li><li>Available: state that needs to be available when re-entering routes</li><li>Retrieved: state that must be retrieved with a side-effect</li><li>Impacted: state that is impacted by actions from other sources</li></ul><h3>Core Concepts of NgRx</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VSocJlfNbFti2kK3_EvSnQ.png" /></figure><p>Let’s break down the key building blocks of NgRx:</p><h4>Actions</h4><p>Actions are plain objects that describe an intention to change the state.</p><h4>Reducers</h4><p>Reducers specify how the state should change in response to an action. They are pure functions that take the current state and an action, returning a new state.</p><h4>Selectors</h4><p>Selectors are used to query specific slices of the state from the store.</p><h4>Effects</h4><p>Effects handle side effects like API calls. They listen to dispatched actions and can dispatch new actions based on the outcome.</p><h3>Building a Feature with NgRx: Adding a Note</h3><p>Let’s walk through a simple example of using NgRx to manage notes in an application.</p><h4>1. Define the state</h4><p>Here we will define what will be stored in the state: an array of Notes initialized with an empty array.</p><pre>export interface Note {<br>  id: string;<br>  creationDate: Date;<br>  title?: string;<br>  content: string;<br>}<br><br>export interface NoteState {<br>  notes: Note[];<br>}<br><br>const initialState: NoteState {<br>  notes: []<br>}<br><br>export interface AppState {<br>  notes: NoteState<br>}</pre><h4>2. Define Actions</h4><p>We will create an action that will add a note.</p><pre>export const add = createAction(&#39;[Note] Add&#39;, props&lt;{ note: Note }&gt;());                </pre><p>Another way to define actions is ActionGroups. When you want to group some actions that are linked.</p><pre>export const noteActions = createActionGroup({<br>  source: &#39;Note&#39;,<br>  events: {<br>    Add: props&lt;{ note: Note }&gt;(),<br>    &#39;Add Success&#39;: props&lt;{ note: Note }&gt;(),<br>    &#39;Add failed&#39;: props&lt;{ error: string }&gt;(),<br>  }<br>});</pre><h4>3. Create the effects</h4><p>An effect is a way to handle side effects on action launched.</p><p>For exemple, we want to call an api on the add note action, we have to create a service that will make the api call. And in the effect we will listen to the add note action, when the action is detected, we will call the note service that will make the api call and the effect will return another action. If the api call succeded, we will dispatch an add success action, otherwise an add failed action. The reducer will then listen to those success and failed actions and will update the state accordingly. It is the first kind of effect.</p><p>Another kind of effect, is the ones that don’t require to dispatch another action. For instance, we just want to display a toast or a snack bar to let the user know that the action succeded, it is possible by adding { dispatch: false } as a second parameter of the createEffect function.</p><pre>@Injectable()<br>export class NoteEffects {<br>  private actions$ = inject(Actions);<br>  private noteService = inject(NoteService);<br><br>  addNote$ = createEffect(() =&gt;<br>    this.actions$.pipe(<br>      ofType(noteActions.add),<br>      switchMap(({ note }) =&gt;<br>        this.noteService.add(note).pipe(<br>          map(note =&gt; noteActions.addSuccess({ note })),<br>          catchError(error =&gt; of(noteActions.addFailure({ error })))<br>        )<br>      )<br>    )<br>  );<br><br>  addNoteSuccess$ = createEffect(<br>    () =&gt;<br>      this.actions$.pipe(<br>        ofType(noteActions.addSuccess),<br>        switchMap(() =&gt; this.showSnackBar(&#39;notes.add_success&#39;))<br>      ),<br>    { dispatch: false }<br>  );<br><br>}</pre><h4>4. Create a Reducer</h4><p>The reducer will listen to the addSuccess action and modify the state by adding the note to it.</p><pre>export const notesReducer = createReducer(<br>  initialState,<br>  on(noteActions.addSuccess, (state, { note }) =&gt; [...state, note])<br>);</pre><h4>5. Set Up Selectors</h4><p>When we want to get all the notes from the state, we need to use this selector.</p><pre>export const selectNotes = createSelector(<br>  (state: AppState) =&gt; state.notes,<br>  (notes) =&gt; notes<br>);</pre><h4>6. Use in a Component through a Facade</h4><p>I will invite you to create a facade that will expose observables and methods that will dispatch actions or select data from the store. It will allow to just inject this facade in your components or services and use them directly. I think it is a clean way opposed to directly dispatch actions in components.</p><pre>@Injectable({<br>  providedIn: &#39;root&#39;,<br>})<br>export class NoteFacade {<br>  private store = inject(Store&lt;NoteState&gt;);<br><br>  notes$ = this.store.select(selectNotes);<br><br>  add(note: Note) {<br>    return this.store.dispatch(noteActions.add({ note }));<br>  }<br>}</pre><pre>@Component({<br>  selector: &#39;app-notes&#39;,<br>  template: `<br>    &lt;div *ngFor=&quot;let note of notes$ | async&quot;&gt;<br>      {{ note.content }}<br>    &lt;/div&gt;<br>    &lt;button (click)=&quot;addNote()&quot;&gt;Add Note&lt;/button&gt;<br>  `<br>})<br>export class NotesComponent {<br>  private noteFacade = inject(NoteFacade);<br><br>  notes$ = this.noteFacade.notes$;<br><br>  addNote() {<br>    this.noteFacade.add({ <br>      id: &#39;1&#39;, <br>      creationDate: new Date(),  <br>      content: &#39;New Note&#39; <br>    });<br>  }<br>}</pre><h4>7. Do not forget to register your state</h4><p>After doing all of this, you want to test this new store you created but when you launch the application, it does not work and you have no error.</p><p>It is logical, something is missing.<br>You need to register your store in the application. <br>So just add this in your ApplicationConfig:</p><pre>const reducers: ActionReducerMap&lt;AppState&gt; = { notes: noteReducer };<br><br>export const appConfig: ApplicationConfig = {<br>  providers: [<br>    provideStore(reducers, { metaReducers }),<br>    provideEffects([NoteEffects]),<br>]</pre><p>Now go ahead, it should be fine and your store should work. Hourra !!!</p><h3>More advanced subjects</h3><h4>Meta reducers</h4><p>They are called before the « normal » reducers and they allows to pre-process actions, for instance for logging needs.</p><pre>export function debug(reducer: ActionReducer&lt;any&gt;): ActionReducer&lt;any&gt; {<br>  return function(state, action) {<br>    console.log(&#39;state&#39;, state);<br>    console.log(&#39;action&#39;, action);<br><br>    return reducer(state, action);<br>  }<br>}<br><br>export const metaReducers: MetaReducer&lt;any&gt;[] = [debug];</pre><h4>Rehydrate state on page refresh</h4><p>When you want to rehydrate your store on browser reload, you need to install and configure a new package : ngrx-store-localstorage</p><pre>export function localStorageSyncConfig(): LocalStorageConfig {<br>  return {<br>    keys: [&#39;notes&#39;],<br>    rehydrate: true,<br>  };<br>}<br><br>export function localStorageSyncReducer(reducer: any): any {<br>  return localStorageSync(localStorageSyncConfig())(reducer);<br>}<br><br>const metaReducers: Array&lt;MetaReducer&lt;any, any&gt;&gt; = [localStorageSyncReducer];</pre><p>And don’t forget to add it in your ApplicationConfig object</p><pre> provideStore(reducers, { metaReducers }),</pre><h3>How to Debug ?</h3><p>You will need to install an extension for your browser.</p><p>Chrome extension: <a href="https://chromewebstore.google.com/detail/redux-devtools">https://chromewebstore.google.com/detail/redux-devtools</a></p><p>Firefox extension: <a href="https://addons.mozilla.org/fr/firefox/addon/reduxdevtools/">https://addons.mozilla.org/fr/firefox/addon/reduxdevtools/</a></p><p>And to configure your app with this app conf:</p><pre>    provideStoreDevtools({<br>      maxAge: 25,<br>      logOnly: !isDevMode(),<br>      autoPause: true,<br>      trace: false,<br>      traceLimit: 75,<br>      connectInZone: true,<br>    }),</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GrhN2L_ReGlGioG_ZLDw7A.png" /></figure><h3>Conclusion</h3><p>NgRx is a powerful library for managing state in Angular applications. While it introduces a learning curve, its benefits — predictability, scalability, and maintainability — make it an excellent choice for large or complex projects.</p><p>If you’re ready to take your Angular skills to the next level, give NgRx a try. You’ll not only make your application’s architecture better but also make your codebase easier to maintain.</p><h3>What’s Next?</h3><ul><li>Dive into the NgRx Documentation for more details (<a href="https://ngrx.io/">https://ngrx.io/</a>)</li><li>Share your experiences and thoughts in the comments below. How do you manage state in your Angular applications ?</li><li>Train yourself by doing exercises about this subject: <a href="https://github.com/BenjaminCanape/AdvancedAngularLessons">https://github.com/BenjaminCanape/AdvancedAngularLessons</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4ebe80d5426" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 things to know when you start your journey to become a developer]]></title>
            <link>https://medium.com/@benjamin.canape/10-things-to-know-when-you-start-your-journey-to-become-a-developer-8cc808297da7?source=rss-9bbabe36a3fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/8cc808297da7</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[junior-developer]]></category>
            <category><![CDATA[developer]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[best-practices]]></category>
            <dc:creator><![CDATA[Benjamin Canape]]></dc:creator>
            <pubDate>Mon, 28 Oct 2024 08:31:39 GMT</pubDate>
            <atom:updated>2024-10-28T08:31:39.580Z</atom:updated>
            <content:encoded><![CDATA[<p>When you start coding, you want your code to be clean to help others understand it and reduce bugs. Clean code is the best way to protect yourself from silly bugs. My goal is to share some advices to help junior developers, especially in a professional environment.</p><p>Let’s start the journey toward writing better code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*VO5DI90mbiJcmgvomRTcjA.jpeg" /></figure><ol><li>Think before writing code</li></ol><p>Writing code is easy, writing good code is less easy. Spend some time thinking about what you’re going to write and how to make it as efficient and effective as possible, without introducing side effects. Plan the architecture of what you’re going to build. If needed, use diagrams like UML and ask experienced developers if you have questions.</p><p>2. Write small functions and small classes</p><p>Long files with methods that go on for hundreds of lines can be overwhelming to read and maintain. Instead, make your code clear and manageable by dividing it into small functions, each dedicated to a single task.</p><p>3. Create abstract, generic and reusable classes</p><p>For instance, in front-end frameworks, components that have similar behaviors should be refactor into a single, generic and reusable component to reduce code duplication. Avoid writing specific conditions or methods in these generic components. Instead, keep the specific logic in components that use them.</p><p>4. Be careful to memory leaks</p><p>Manipulating data, listening to events … A lot of things can increase memory usage. If not managed well, this can lead to crashes. In the case of RxJS observables, it essentially means: Unsubscribe to your observables and complete your BehaviorSubjects when they are no longer necessary, at least at component destruction. In C or C++, never forget to free the memory you allocated.</p><p>5. Handle the errors</p><p>You may know how your code should work ideally, but real-world scenarios often differ. For example, what happens if the internet connection is lost while using an online app ? You must handle common error cases so users understand what’s happening when issues arise.</p><p>6. Respect Team Coding Conventions</p><p>Whether it’s naming methods or variables in camelCase or snake_case, consistency is essential. Follow your team’s established coding conventions to maintain a cohesive and readable codebase.</p><p>7. Learn to use your console, logs and debuggings tools</p><p>Debugging is a critical skill. Understand and use tools like your console, logs, and debugging extensions (e.g., Redux DevTools for NgRx users) to trace and solve issues effectively. Knowing how to debug without overusing console.log is a game-changer.</p><p>8. Test your code (and imagine what consequences it could have on the entire application)</p><p>Writing code is one thing, but testing it is crucial. Don’t wait too long to compile and test. Remember that changes in one part of the code can affect other parts of the application, so watch out for side effects.</p><p>9. Never stop learning</p><p>Always try to improve yourself and your code. Learn by having side projects. Technologies, Frameworks, Languages are improving and changing every year, so update your knowledge. In development, continuous learning is essential.</p><p>10. Know How to Use AI Effectively</p><p>Tools like ChatGPT and Copilot can boost your productivity. However, it’s important to first understand the basics of development on your own. If you rely too heavily on AI without solid knowledge, you may end up implementing incorrect or buggy solutions. Start by using AI to clarify code you don’t understand, and once you gain more experience, use it to improve your coding quality.</p><p>— — — — —</p><p>This is your first step to becoming a better developer. These guidelines will benefit you throughout your career. Start learning and applying them now, your future self (and your colleagues) will thank you when you revisit your own code in a few years.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8cc808297da7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating Flutter Mobile App Builds and Tests with GitHub Actions]]></title>
            <link>https://medium.com/@benjamin.canape/automating-flutter-mobile-app-builds-and-tests-with-github-actions-6256c47ecee2?source=rss-9bbabe36a3fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/6256c47ecee2</guid>
            <category><![CDATA[test]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Benjamin Canape]]></dc:creator>
            <pubDate>Sun, 04 Feb 2024 11:05:23 GMT</pubDate>
            <atom:updated>2024-02-04T11:30:33.128Z</atom:updated>
            <content:encoded><![CDATA[<p>In today’s fast-paced development environments, ensuring the reliability and consistency of mobile applications across various platforms is paramount. To streamline the development process and maintain high standards of quality, many teams leverage automation tools like GitHub Actions. Let’s delve into a specific configuration file that exemplifies how to automate the build and testing processes for mobile apps using Flutter, a popular cross-platform framework, with GitHub Actions.</p><h3>Understanding the Workflow File</h3><p>The provided YAML file outlines a set of actions to be executed upon certain events within a GitHub repository. Here’s a breakdown of its key components:</p><pre>name: Build mobile apps &amp; check tests<br>on:<br>  push:<br>    branches: [ &quot;main&quot; ]<br>  pull_request:<br>    branches: [ &quot;main&quot; ]</pre><p>This section defines the events that trigger the workflow. Specifically, it runs upon pushes to the main branch and pull requests targeting the same branch.</p><h3>Jobs and Steps</h3><p>The workflow consists of several jobs, each representing a distinct task to be performed.</p><h4>1. Building Android Application</h4><pre>jobs:<br>  build-android:<br>    name: Build android<br>    runs-on: ubuntu-latest</pre><p>This job, named “Build android,” is configured to run on the latest version of Ubuntu.</p><pre>steps:<br>    - uses: actions/checkout@v3<br>    - uses: actions/setup-java@v2<br>      with:<br>        distribution: &#39;zulu&#39;<br>        java-version: &#39;11&#39;<br>    - uses: subosito/flutter-action@v2<br>      with: <br>        flutter-version: &#39;3.16.9&#39;<br>    - name: Install dependencies<br>      run: flutter pub get<br>    - name: Generate l10n<br>      run: flutter gen-l10n<br>    - name: Build apk<br>      run: flutter build apk<br>    - name: Build appbundle<br>      run: flutter build appbundle</pre><p>These steps include setting up Java, configuring Flutter, installing dependencies, generating localization files, and finally, building the Android application as both an APK and an App Bundle.</p><h4>2. Building iOS Application</h4><pre>build-ios:<br>    name: Build ios<br>    runs-on: macos-latest</pre><p>This job, “Build ios,” runs on the latest version of macOS.</p><pre>steps:<br>    - uses: actions/checkout@v3<br>    - uses: subosito/flutter-action@v2<br>      with:<br>        channel: &#39;stable&#39;<br>        architecture: x64<br>    - name: Install dependencies<br>      run: flutter pub get<br>    - name: Generate l10n<br>      run: flutter gen-l10n<br>    - name: Build ios<br>      run: flutter build ios --release --no-codesign</pre><p>Similar to the Android build job, this job involves checking out the repository, configuring Flutter, installing dependencies, generating localization files, and building the iOS application.</p><h4>3. Checking Tests</h4><pre>check-tests:<br>    name: Check Tests<br>    runs-on: ubuntu-latest</pre><p>This job, named “Check Tests,” also runs on the latest version of Ubuntu.</p><pre>steps:<br>      - uses: actions/checkout@v3<br>      - uses: subosito/flutter-action@v2<br>        with:<br>          flutter-version: &#39;3.16.9&#39;<br>          channel: &#39;stable&#39;<br>      - name: Flutter doctor<br>        run: flutter doctor<br>      - name: Get dependencies<br>        run:  flutter pub get<br>      - name: Run l10n generation<br>        run: flutter gen-l10n<br>      - name: Run tests<br>        run: flutter test</pre><p>This job involves checking out the repository, configuring Flutter, checking the Flutter environment, fetching dependencies, generating localization files, and running tests for the Flutter application.</p><p>And the result when a push or a merge request is made to the main branch:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T0uN8zfRunZNc3Kmo5-jiA.png" /><figcaption>All jobs have been executed and are successful</figcaption></figure><h3>Conclusion</h3><p>By utilizing GitHub Actions and Flutter, developers can automate the build and testing processes for mobile applications, ensuring consistent performance and reliability across different platforms. This YAML configuration file serves as a blueprint for setting up an efficient and automated development workflow, ultimately saving time and effort while maintaining the quality of mobile applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6256c47ecee2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to get the most out of Git]]></title>
            <link>https://medium.com/@benjamin.canape/how-to-get-the-most-out-of-git-2d6925522cbc?source=rss-9bbabe36a3fd------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d6925522cbc</guid>
            <category><![CDATA[git]]></category>
            <dc:creator><![CDATA[Benjamin Canape]]></dc:creator>
            <pubDate>Sun, 27 Mar 2022 15:22:08 GMT</pubDate>
            <atom:updated>2022-04-23T22:39:09.439Z</atom:updated>
            <content:encoded><![CDATA[<p>Git is a powerful versioning tool. It allows to keep track of every single changes in your code. Working with multiple co-workers has neither been easier with this tool. You can have many versions of your applications at the same time. You can review every single line before adding some new features and revert it if you find that it introduce a bug.</p><p>But to get the most out of Git, you must know how to correctly use it. Here is some workflow I’ve been using lately.</p><p>First of all, we are going to use the command lines to understand what is happening. But you can use some tools that will facilitate your tasks like Git Kraken or Git inside IntelliJ. I was never a big fan of theses tools, I think they are slower and hide what is really going on so you can easily break something.</p><p>So, now, let’s start.</p><p>The first thing you’ve got to do is to clone a project. You can use the git clone command like that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*A2LYB2YT-lYG6tThlgCNIg.png" /></figure><p>It will download the repository on your local environment. Then, just go inside the folder with a cd command.</p><p>Inside the folder, we’re going to use the git status command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*Qlt_bifpT2wR2WACtjA5fw.png" /></figure><p>This command gives you the current state of your local repository. That means the branch you are on, if you are up-to-date or not and the changes that you’ve made.</p><p>So, now let’s pause here to explain a few things.</p><p>What is a branch ?</p><p>A branch is some kind of version of the application where you can add or remove some code. You can create as many branch as you want. Basically, when you need to create a new feature or fix a bug, you need to create a branch. The main branch is mostly called master. It’s the most up-to-date version of your application. I know some projects use a dev branch that is the most up-to-date version. In that case master is the latest stable version and dev is the most up-to-date but can be instable.</p><p>So, how can we create a new branch, you might say. Well, it’s easy, just do that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*aVJidYNjju45s_QuvdM4uA.png" /></figure><p>What is this command that appear from nowhere ?</p><p>Git checkout is a command that allows you to move from branch to branch. The -b option means that we are going to create a new branch. When you do a git checkout -b command, the new branch will be created from the current branch you are in. It means that if you were in the master branch, the branch will be created with the code that is on the master branch. If you’ve done it from the dev branch, it’s the code from dev that is on your new branch.</p><p>If I want I can go back to master by doing that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*DtMoE79GeY5hrbTqi4zs_w.png" /></figure><p>Now, what if I want to see all the branches that I have:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*Ivg4Zja_k49n_Vd9UKMjvg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*REysLHUnPvs-OtTpaRDgMA.png" /></figure><p>And to delete a branch. Just do a git branch -D command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*5R7Ig85DyrrGabvDlC_-QA.png" /></figure><p>Sometimes, if someone else is working on the repository, you need to update the list of the branches that have been created on origin. You can do that with git fetch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*4KChp6CXaQk3PG2CrD-UtA.png" /></figure><p>And if I want to update a branch that has been modified by another co-worker. I can pull the changes. Remember that on the git status command, we had a up-to-date status. If it’s not up-to-date, just do that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*QsROR7tkpGToxORe082j7w.png" /></figure><p>If the local branch was not up-to-date, it would have downloaded the changes.</p><p>Now, let’s assume you created a branch and worked a bit. And you want your co-workers to be able to see the changes you’ve made.</p><p>You need to commit and push.</p><p>The commits are packs of changes that means something. It needs to correspond to a feature or a bug fix or an improvement. The commit is an action that will stay on your local environment. To push it to the origin server, you need to git push.</p><p>But before committing some files, you may need to see the different changes that you’ve made.</p><p>To do that, you can do a git status to see the files that have been changed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WLYuDT__Z2cx8Z85CqLCOA.png" /></figure><p>To see which lines have been modified, you can do a git diff:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0pqHv4cbaGRszVTG9HUaQA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yAcVMcbP7DY0gTXFlGQl6g.png" /></figure><p>The green lines are the ones that have been added. The red lines are the ones that have been deleted.</p><p>If you are ok with the change, you can add the file to say that it will be taken into account when you will commit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IMAuqRn1lV_McZ9fcFicLg.png" /></figure><p>If you changed you mind, you can do the git restore command that git tells you.</p><p>Now you can commit. When you commit you need to add a message to say what it is about with the -m option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jRg1euJ1539OXMnRyy8N-A.png" /></figure><p>The commit has been done. It gives you the details of what changes have been done. Remember, this is still on your local environment. So now we need to push it to the server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SEU2ZAgvd1nESdibpHpH4A.png" /></figure><p>If you are using tools like Gitlab or GitHub, now you can see the newBranch in your repository. And create a Merge request so that your code can be added to the application. Otherwise you can do it in command line too.</p><p>Just go back to master with a git checkout and do this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*y4D30MA3dq4RGalJgM-ZEA.png" /></figure><p>If you want to see if the merge worked. You can git log to see the commits that are present on you current branch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H5S3ag2XnQf0QjEHSuLJ3w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tUs6Chszh5ctCGp-u3EKbA.png" /></figure><p>This means that the code you added on your newBranch is now also on the master branch.</p><p>Don’t forget to git push if you have done it on your local environment.</p><p>You’ve got the bases now. Congratulations.</p><p>From now on, I will give you advises I give to everyone I know to be more efficient with Git.</p><ol><li><strong>Stash changes</strong></li></ol><p>Use Git stash/git stash pop when you want to move your local changes in the basket stack. It can be useful when you move from branch to branch or your priorities change and you don’t want to commit but no longer want the modification you have done. You can get the changes back later when you stash pop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TxcBmtoQwnh2PThp6iMF7A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*kaYQJkBu6Rp1U-71AqumMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mZW6E1dh0wAqlzHjVxaWgQ.png" /></figure><p>As you can see, the line I have added is no longer present. I moved it into the basket stack. To get it back, I can un stash it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lQBoi5LqhHofGSJtyx5WiA.png" /></figure><p><strong>2. Cherry-picking</strong></p><p>When your application has many versions, you may want to report a commit to many branches. To do that you can use the hash of the commit to cherry-pick it to the branch you want.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J_OJcv2DNUEJR2WPDX3WrQ.png" /></figure><p><strong>3. Rebasing</strong></p><p>Working on a branch during a few days or a few weeks means that during that time you are no longer up-to-date with the new commits being pushed and that can lead to a lot of conflict when you decide to finally merge. To avoid that, you can do a rebase, on a daily base. The rebase will take the branch you want (for instance master) and play the commits you added on your current branch (newBranch) to play them on top. As a result, you’ve got a clean branch up-to-date with the branch you diverged from (master in our case) and on which you also have your current commits (the commit on newBranch is on top of the commits of master). It’s similar to a merge but it does not add a merge commit so the history is cleaner but it rewrite completely the git history. So, be very very careful. The <strong>rebase</strong> command must <strong>only</strong> be used on <strong>personal branches</strong> on which you work <strong>alone</strong>. Otherwise, if the branch is shared, you will completely destroy your co-workers branches. They will certainly hate you for that. In that case (<strong>shared branches</strong>), only use a <strong>merge</strong>. This is important.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*lwdnWTSJYGcer3QF4hRqDQ.png" /></figure><p>There is also another great feature that you can use with the rebase command: the interactive mode. It allows you to edit the commits you created. For instance, if you want to merge all the commits you have done into one, you can easily do it by doing a git rebase — i. Then, in the window that has opened you replace the pick word by “s” or “f” to squash or fix the commit you want to make invisible. The commits where you put a “s” or a “f” before will be merged into the one before. It is useful when your different commits are about the same thing. They should be regrouped into only one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IG-mgHszHAKSgZvuqvsC_A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DiWrHrKX4Pa8NYMnV91TQQ.png" /></figure><p>When the rebase is finished, we can git log to see that indeed the last commit disappeared but the code that was in it was not removed but merged into the first commit.</p><p><strong>4. Edit the message of the last commit</strong></p><p>Adding a message to a commit is not easy sometimes because we have no idea what to put. Other times, we need to edit it because we squashed many commits into one. But don’t worry we can edit the message easily. The git commit amend is here to help us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YiUDBc8ZX9xq_TgqYkA6Jw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X2-pV7DbHHijkBFreI_8WA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ySVmdX7ym1uVdxVMLfDJg.png" /></figure><p><strong>5. Replace local branch with the remote one</strong></p><p>Sometimes, you may be in need to replace your local branch with the remote one. It can be done with a git reset command</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6rCUp4YCuc5ito-NO0-q8w.png" /></figure><p><strong>6. Reflog — life saving command</strong></p><p>Playing with git sometimes can lead you into situations where your branch is broken and you seem to have lost days of work and you don’t know how to repair what is broken. For this situation, I have found a very useful command. Git reflog. This command gives you a history of what you’ve done on your git local repository. If a merge or a rebase has broken your branch. You can see the history by doing that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J4F3udE0lvpj1IfOBExrOg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ok6l486cb8RtHgmm6ZWFSw.png" /></figure><p>If you think your branch has been broken since the merge. Go back to this state of your repository by git checkout either the hash or the HEAD number at the beginning of the history line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W1-MhZctAJ7Ni1zKRq6X-A.png" /></figure><p>This solution can save your life. This is one of the most important command I’ve used.</p><p>Thank you for reading this. If you’ve got better ideas on how to be better at git or if you think I missed some important commands, I’m open to discussion.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d6925522cbc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>