<?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 Mateo Tibaquirá Palacios on Medium]]></title>
        <description><![CDATA[Stories by Mateo Tibaquirá Palacios on Medium]]></description>
        <link>https://medium.com/@matheo?source=rss-7926f178820f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*UpdXYLYLB6F3YolxJlJP2g.jpeg</url>
            <title>Stories by Mateo Tibaquirá Palacios on Medium</title>
            <link>https://medium.com/@matheo?source=rss-7926f178820f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 03:59:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@matheo/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 migrate from Stylus or Pug]]></title>
            <link>https://matheo.medium.com/how-to-migrate-from-stylus-or-pug-27cdcc8d3a24?source=rss-7926f178820f------2</link>
            <guid isPermaLink="false">https://medium.com/p/27cdcc8d3a24</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[stylus]]></category>
            <category><![CDATA[pug]]></category>
            <category><![CDATA[converter-tool]]></category>
            <dc:creator><![CDATA[Mateo Tibaquirá Palacios]]></dc:creator>
            <pubDate>Fri, 02 Sep 2022 18:09:40 GMT</pubDate>
            <atom:updated>2022-09-02T18:09:40.539Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Angular folks! here a late announcement of some packages released by <a href="https://mynd.dev/">Mynd</a> that will help some projects in the transition to Angular 13+ due to the deprecation of Stylus.</p><h4>@myndpm/stylus2scss</h4><p>This CLI utility convert styl files to scss and also updates their related Angular Components metadata. It allows to spread the conversion in different GIT commits to keep track of the history of the converted files.</p><p>It also includes the sass-migration tool to complete the process without additional steps, and some other customizable options that can be checked in the README file: <a href="https://www.npmjs.com/package/@myndpm/stylus2scss">https://www.npmjs.com/package/@myndpm/stylus2scss</a></p><h4>@myndpm/pug2html</h4><p>At <a href="https://www.mynd.co/">Mynd</a> we were using Pug since it was a fancy template engine that was quite aligned with Stylus, but after some years their tooling and support got quite behind and it was time to move to the default HTML templates.</p><p>This CLI utility convert pug content to html and also updates the Angular components metadata. It also possible to keep the GIT history or execute the process step by step with the provided --options documented in its README file: <a href="https://www.npmjs.com/package/@myndpm/pug2html">https://www.npmjs.com/package/@myndpm/pug2html</a></p><h4>Feedback</h4><p>Enjoy! and please report any issue at our GitHub repo: <a href="https://github.com/myndpm/open-source">https://github.com/myndpm/open-source</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27cdcc8d3a24" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Conditional Tasks in Dynamic Forms]]></title>
            <link>https://matheo.medium.com/conditional-tasks-in-dynamic-forms-88c4647ceb?source=rss-7926f178820f------2</link>
            <guid isPermaLink="false">https://medium.com/p/88c4647ceb</guid>
            <category><![CDATA[dynamic-form]]></category>
            <category><![CDATA[npm-libraries]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Mateo Tibaquirá Palacios]]></dc:creator>
            <pubDate>Fri, 07 May 2021 14:26:13 GMT</pubDate>
            <atom:updated>2022-02-12T01:46:19.359Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iIAj3UxN9M6F28SE4e4FOA.png" /><figcaption>Pseudo-diagram of Conditions and Matchers</figcaption></figure><blockquote><strong><em>TL;DR</em></strong><em><br>We have support for conditional behaviors in </em><em>@myndpm/dyn-forms documented at </em><a href="https://mynd.dev/docs/dyn-forms/intro/matchers"><em>mynd.dev</em></a><em> and we are able to provide them easily like the Controls, Validators, AsyncValidators, etc.</em></blockquote><p>In complex forms use-cases, some controls directly depend on the value or status of some other form control. Then we implement custom behaviors, like hiding a field when another control has some value, or disabling it depending on a complex condition, etc.</p><p>To support this, we’ve added Matchers and Conditions, which can be provided just like the Validators and AsyncValidators as we saw in the previous chapter of this series. If you want to get an initial idea from the code, you can check this <a href="https://github.com/myndpm/open-source/blob/master/libs/forms/core/src/control-matchers.types.ts">source file</a> and this <a href="https://mynd.dev/demos/dyn-forms/builder">real use-case demo</a>.</p><h3>DynTreeNode</h3><p>Each dynamic control has a composed Node service instance which holds the data of this point in the form hierarchy. It provides the <a href="https://github.com/myndpm/open-source/blob/master/libs/forms/core/src/tree.types.ts#L12">API</a> and the data to manipulate the form in a customized way when needed.</p><p>The node has the control Form Instance, the params object, some utility methods to query or select parent and child controls, manipulate the visibility, etc. We will use this node inside the Conditions, Matchers and any other custom Handlers.</p><h3>Conditions</h3><p>To match a special requirement, we need to define one or more conditions, so when all (AND) or one (OR) of them are fulfilled we perform a particular action. The Condition Function type consists of:</p><pre>interface DynControlConditionFn {<br>  (node: DynTreeNode): Observable&lt;any&gt;;<br>}</pre><p>it streams a truthy value whenever the condition is fulfilled or not, for example, we could check if a specific control has the expected value:</p><pre>(node: DynTreeNode) =&gt; {<br>  return node.query(&#39;specific.control&#39;).valueChanges.pipe(<br>    map(controlValue =&gt; controlValue === &#39;xValue&#39;),<br>  );<br>}</pre><p>we can join these conditions with the required operator (AND | OR) for our use-case, and then evaluate the action to execute in the specific Matcher.</p><h3>Matchers</h3><p>We define our requirement with the Matchers that we want to run when all or a single condition is satisfied:</p><pre>match: {<br>  matchers: [&#39;DISABLE&#39;], // one or more matchers<br>  when: [{<br>    // the library provides a DEFAULT condition handler<br>    // to process path, value and negation<br>    path: &#39;other.field&#39;,<br>    value: &#39;expectedValue&#39;<br>  }]<br>}</pre><p>the DISABLE matcher is included in the library with ENABLE, SHOW, HIDE (display: none) and INVISIBLE (visibility: hidden).</p><p>One matcher consists of a function which performs a task in the form hierarchy; to do so, it receives the DynTreeNode instance and the hasMatch conditions results:</p><pre>interface DynControlMatcherFn {<br>  (node: DynTreeNode, hasMatch: boolean, firstTime: boolean): void;<br>}</pre><p>So, for example the DISABLE matcher operates into the form control when the specified conditions are fulfilled (has match):</p><pre>{<br>  id: &#39;DISABLE&#39;,<br>  fn: (): DynControlMatcherFn =&gt; {<br>    return (node: DynTreeNode, hasMatch: boolean) =&gt; {<br>      hasMatch ? node.control.disable() : node.control.enable();<br>    }<br>  }<br>},</pre><h3>Advanced Stuff</h3><p>This conditional processing enables us to do some additional logical operations, like negate the result of one or all the conditions, so we are able to play with conditions upside down and have the simplest specification of our requirements.</p><h3>Matcher Example</h3><p>For example, if we want to run a Matcher for all the options of a SELECT except a few of them, OR without another condition, we can define that requirement with the few known values instead listing all the other values (which can be a long list), and negate the matcher input:</p><pre>match: {<br>  matchers: [&#39;MyMatcherID&#39;],<br>  operator: &#39;OR&#39;, // the operator is AND by default<br>  when: [<br>    {<br>      path: &#39;selectorName&#39;,<br>      value: [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;] // this will check if selectorName.value is IN this array<br>    },<br>    {<br>      path: &#39;other.control&#39;,<br>      value: &#39;anotherValue&#39;<br>    },<br>  ],<br>  negate: true<br>}</pre><p>the Matcher will receive hasMatch: true when the selector has a value NOT in the provided list.</p><p>Also note that you can provide your Matcher factories with a custom id like &#39;MyMatcherID&#39; just like we will do with conditions in the following section.</p><h3>Condition Factory</h3><p>We can register Factories with an id and a fn as we do with Validators, and parametrize them in the Config Object:</p><pre>export interface DynControlCondition {<br>  id: string;<br>  fn: (...args: any[]) =&gt; DynControlConditionFn;<br>}</pre><p>Remember that DynControlConditionFn returns an Observable&lt;boolean&gt; so you can implement and provide your custom conditions like:</p><pre>const conditions = [{<br>  id: &#39;MyConditionId&#39;,<br>  fn: (...args: any[]) =&gt; { // Factory<br>    return (node: DynTreeNode) =&gt; { // Condition<br>      return node.control.valueChanges.pipe(map(...));<br>    }<br>  }<br>}];</pre><pre>@NgModule({<br>  imports: [<br>    DynFormsModule.forFeature({ conditions });</pre><h3>Conditions Config</h3><p>You can use your custom conditions in these ways:</p><pre>// inline function<br>when: [<br>  (node: DynTreeNode) =&gt; {<br>    // manipulate the form via DynTreeNode<br>  }<br>]</pre><pre>// factory ID without arguments<br>when: [<br>  &#39;MyConditionId&#39;,<br>]</pre><pre>// parametrized factory<br>when: [<br>  [&#39;MyConditionId&#39;, args],<br>]</pre><pre>// or declarative inline config<br>when: [<br>  {<br>    condition: &#39;MyConditionId&#39;,<br>    path: &#39;other.control&#39;, // path is the only mandatory field in this format,<br>    param1: &#39;anyValue&#39;, // the whole object will be passed to your DynControlConditionFn<br>  },<br>]</pre><p>in the last notation the whole config object is passed to the Factory, that’s how the DEFAULT condition handler receives the path, value and negate config values.</p><p>Note: If no value is configured, the DEFAULT handler emits true everytime the configured path control value changes:</p><pre>id: &#39;DEFAULT&#39;,<br>fn: ({ path, value, negate }): DynControlConditionFn =&gt; {<br>  return (node: DynTreeNode): Observable&lt;boolean&gt; =&gt; {<br>    if (value === undefined) {<br>      return node.query(path).valueChanges.pipe(mapTo(true));<br>    }<br>    ...<br>  }<br>}</pre><h3>Conclusion</h3><p>We have covered most of the details of Matchers and Conditions, and how one or many conditions can be configured so when one or all of them are fulfilled, they trigger a matcher which can modify the state of the form hierarchy via the DynTreeNode API.</p><p>If you have an idea after this reading, or after using this library in an Angular App, please share it with us! :)</p><p>You can <a href="https://github.com/myndpm/open-source/issues/new?assignees=&amp;labels=&amp;template=feature-request.md&amp;title=">request features</a> and join our <a href="https://github.com/myndpm/open-source/discussions">discussions</a>.</p><p><em>// PS. We are hiring!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88c4647ceb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Parametrized Validators in Dynamic Forms]]></title>
            <link>https://matheo.medium.com/parametrized-validators-in-dynamic-forms-ac718654298?source=rss-7926f178820f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac718654298</guid>
            <category><![CDATA[dynamic-form]]></category>
            <category><![CDATA[open-source-software]]></category>
            <category><![CDATA[npm-libraries]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Mateo Tibaquirá Palacios]]></dc:creator>
            <pubDate>Mon, 03 May 2021 16:15:22 GMT</pubDate>
            <atom:updated>2022-02-12T00:13:31.132Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="mynd.dev" src="https://cdn-images-1.medium.com/max/816/1*HvoGx1JYLzxhJSQk83h5FQ.png" /><figcaption>Work in progress documentation at mynd.dev</figcaption></figure><blockquote><strong><em>TL;DR</em></strong><em><br>We are building the documentation of </em><em>@myndpm/dyn-forms at </em><a href="https://mynd.dev/docs/dyn-forms/"><em>mynd.dev</em></a><em> and we&#39;ve added support for a variety of custom functions like Validators, AsyncValidators, Matchers, Conditions and more.</em></blockquote><p>The next crucial part of any form is validation, aka Validators and AsyncValidators, and we took some time to study a nice way to implement them and we picked the most declarative one:</p><pre>createMatConfig(&#39;INPUT&#39;, {<br>  name: &#39;quantity&#39;,<br>  validators: [&#39;required&#39;, [&#39;min&#39;, 1] ],<br>  asyncValidators: [&#39;myAsyncValidator&#39;],</pre><h3>Angular Validators</h3><p>Angular provides default <a href="https://angular.io/api/forms/Validators">Validators</a> that we’re used to consume programatically in our Reactive Forms, some of them are Validator Functions (ValidatorFn) like Validators.required, and some others are Validator Factories ((args) =&gt; ValidatorFn) which builds a Validator based on a required parameter like Validators.minLength(4).</p><p>The definition of a Validator Function is:</p><pre>(control: AbstractControl) =&gt; ValidationErrors | null</pre><p>it receives the control to be validated, and returns null if its value is valid, or an error object of the form { [error: string]: any }</p><p>Validator Factories are high-order functions that builds a Validator Function according some input parameters:</p><pre>function minLength(minLength: number): ValidatorFn {<br>  return (control: AbstractControl) =&gt; {<br>    return (control.value &amp;&amp; control.value.length &lt; minLength)<br>      ? { minLength: true } // invalid<br>      : null; // valid<br>  }<br>}</pre><p>as you can see, this is a very nice way to parametrize our Functions, so we defined the provisioning of Validators (and all the other handlers) with an id and a factory fn:</p><pre>export interface DynControlValidator {<br>  id: string;<br>  fn: (...args: any[]) =&gt; ValidatorFn;<br>}</pre><p>The id will be the string that we will use in our Configuration Object. By default, @myndpm/dyn-forms provide the default Angular Validators with the same name as we know them: required, requiredTrue, email, pattern, minLength, maxLength, min and max.</p><p>The notation to use them in the Config Object is as follows:</p><pre>// without parameters<br>validators: [&#39;required&#39;],</pre><pre>// with parameters as array<br>validators: [&#39;required&#39;, [&#39;min&#39;, 1] ],</pre><pre>// with parameters as object<br>validators: { required: null, minLength: 4 },</pre><pre>// with an inline ValidatorFn or ValidatorFn factory<br>validators: [myValidatorFn, myValidatorFactory(args)],</pre><p>supporting these different notations is unexpensive and can be useful for different kind of systems or developer tastes.</p><h3>Custom Validators</h3><p>You can provide inline functions to build a fast prototype, but to store a plain config somewhere, you need to provide your ValidatorFn Factory with an id and a fn in the respective module with a code like this:</p><pre>import { AbstractControl, ValidatorFn } from &#39;@angular/forms&#39;;<br>import { DynFormsModule } from &#39;@myndpm/dyn-forms&#39;;<br>import { DynControlValidator } from &#39;@myndpm/dyn-forms/core&#39;;</pre><pre>const validators: DynControlValidator[] = [<br>  {<br>    id: &#39;email&#39;,<br>    fn: (): ValidatorFn =&gt; {<br>      return (control: AbstractControl) =&gt; {<br>        // implement my validator<br>        // to return { email: true } | null;<br>      }<br>    }<br>  }<br>];</pre><pre>@NgModule({<br>  imports: [<br>    DynFormsModule.forFeature({ validators, priority: 100 });</pre><p>note the priority parameter to override the default validators (which weight is 0); we will play with priorities in a further article.</p><h3>AsyncValidators</h3><p>Providing async validators works in the same way. You provide your fn with an id and use them in the Config Object:</p><pre>createMatConfig(&#39;INPUT&#39;, {<br>  name: &#39;quantity&#39;,<br>  validators: [&#39;required&#39;],<br>  asyncValidators: [&#39;myAsyncValidatorId&#39;],</pre><p>and if you need to provide arguments to your AsyncValidator factory, you can use:</p><pre>// single argument which can be an object<br>asyncValidators: [[&#39;myAsyncValidatorId&#39;, args]],<br>// your factory will receive fn(args)</pre><pre>// multiple arguments in array to be destructured<br>asyncValidators: [[&#39;myAsyncValidatorId&#39;, [arg1, arg2]]],<br>// your factory will receive fn(arg1, arg2)</pre><h3>Custom Handlers</h3><p>With this notation we added support for multiple kinds of functions that we require in the Dynamic Forms: Validators and AsyncValidators as we just saw, Matchers and Conditions to manipulate the controls under some special requirements, and also ParamFns to inject functions to the parameters of the DynControls too.</p><p>We will be digging into the conditional executions in the next chapter.<br>In the meantime, <strong>what do you think</strong> of this notation?</p><p>Previously in this series: <a href="https://matheo.medium.com/a-new-approach-to-have-dynamic-forms-in-angular-683a2c417661">A new approach to have Dynamic Forms in Angular</a></p><p><em>// PS. We are hiring!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac718654298" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A new approach to have Dynamic Forms in Angular]]></title>
            <link>https://matheo.medium.com/a-new-approach-to-have-dynamic-forms-in-angular-683a2c417661?source=rss-7926f178820f------2</link>
            <guid isPermaLink="false">https://medium.com/p/683a2c417661</guid>
            <category><![CDATA[dynamic-form]]></category>
            <category><![CDATA[open-source-software]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[npm-libraries]]></category>
            <dc:creator><![CDATA[Mateo Tibaquirá Palacios]]></dc:creator>
            <pubDate>Sun, 11 Apr 2021 06:23:36 GMT</pubDate>
            <atom:updated>2022-08-09T22:23:26.670Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*Hv6c-9TIXHWtqlYe4hrLQQ.png" /><figcaption>HTML output of the dynamic components</figcaption></figure><blockquote><strong>TL;DR</strong><br>Go to <a href="https://stackblitz.com/edit/myndpm-dyn-forms?file=src/app/simple-form/simple.form.ts">Stackblitz</a> and witness the power of @myndpm/dyn-forms , check its synthetic <a href="https://github.com/myndpm/open-source/tree/master/libs/forms">source code</a> and join the <a href="https://github.com/myndpm/open-source/discussions">GitHub Discussions</a> to design the upcoming features based on our experiences with Angular Forms.</blockquote><p>As in most companies, at <em>Mynd</em> we build forms, filters, tables and display <em>views</em> for different purposes. We handle a ton of entities, and we have custom components in our Design System to satisfy our needs. In this complex scenario, avoid boilerplate is a must, and to speed up the development process and facilitate the implementation and maintenance of these <em>views</em>, we built some base libraries to abstract the requirements into configuration objects that enable us to <em>easily modify</em> a form, a filter, a table, without touching a view template (most of the times).</p><p>So the question is: can we implement a standard, flexible enough layer to do this job and be shared with the Angular Community?</p><h3>A bit of History</h3><p>This challenge has been addressed by <a href="https://ngx.tools/#/search?q=dynamic%20forms">many developers and companies</a> in many ways, we even have an <a href="https://angular.io/guide/dynamic-form">official documentation guide</a> on this topic; some approaches ends up with a template processing different types of fields with a ngSwitch, others vary on the entrypoint component depending on the desired UI framework, or their config objects are not standardized and uses different field names for the same task on different controls. They are not completely generic, typed and/or extensible.</p><p>The ideal is to have a strictly typed and serializable configuration object, so we can store it in the state or the database without problems, as well as the ability to share some recipes with the community for common use-cases without complex functions involved, just a JSON object; there are a lot of good ideas out there, and we’re in the process of <a href="https://github.com/myndpm/open-source/discussions">discussing</a> the best possible solutions for each topic.</p><p>Technically speaking, the challenge is to translate a Config Object (JSON) into a functional Form (FormGroup) being able to build any required nested structure, composing Control (inputs, selects, etc) into Containers to group them and customize the layout (cards, panels, etc).</p><h3>What’s New?</h3><p><em>@myndpm/dyn-forms</em> is not just a “dynamic” forms library providing you a finite set of controls, or limiting your creativity and possibilities in any way. This library aims to be a quite <em>generic</em> and <em>lightweight</em> layer on the top of Angular’s Form Framework, allowing us to build, extend and maintain our forms from their metadata, giving us more time to focus our attention on the business-logic requirements, custom validations, etc.</p><p>Moreover, we keep the control of our <em>model</em> and the Angular Form, manipulating the supported methods of FormGroup, FormArray and FormControl, giving the responsibility of building the form hierarchy and its presentation to the library, but patching and listening any valueChange as we are used to.</p><h3>Creating a DynForm</h3><p>All we need is to import DynFormsModule to our NgModule and also provide the DynControls that we require in our form. As a demostrative implementation, we mocked DynFormsMaterialModule at @myndpm/dyn-forms/ui-material to enable you right now to see how it works with some basic components:</p><pre>import {<br>  DynFormsMaterialModule<br>} from &#39;@myndpm/dyn-forms/ui-material&#39;;</pre><pre>@NgModule({<br>  imports: [<br>    DynFormsMaterialModule.forFeature()</pre><p>This package also provides a typed createMatConfig <em>Factory Method</em> that (hopefully) will facilitate the development experience while creating configuration objects, by supporting type-checks (with overloads for the different controls):</p><pre>import { createMatConfig } from &#39;@myndpm/dyn-forms/ui-material&#39;;</pre><pre>@Component(...) {<br><strong>form</strong> = new FormGroup({});<br><strong>mode</strong> = &#39;edit&#39;;<br><strong>config</strong> = {<br>  controls: [<br>    createMatConfig(&#39;<strong>CARD</strong>&#39;, {<br>      name: &#39;<strong>billing</strong>&#39;,<br>      params: { title: &#39;Billing Information&#39; },<br>      controls: [<br>        createMatConfig(&#39;<strong>INPUT</strong>&#39;, {<br>          name: &#39;<strong>firstName</strong>&#39;,<br>          validators: [&#39;required&#39;],<br>          params: { label: &#39;First Name&#39; },<br>        }),<br>        createMatConfig(&#39;<strong>INPUT</strong>&#39;, {<br>          name: &#39;<strong>lastName</strong>&#39;,<br>          validators: [&#39;required&#39;],<br>          params: { label: &#39;Last Name&#39; },<br>        }),<br>        createMatConfig(&#39;<strong>DIVIDER</strong>&#39;, {<br>          params: { invisible: true },<br>        }),<br>        ...</pre><p>now you’re ready to invoke the Dynamic Form in your template:</p><pre>&lt;form [formGroup]=&quot;form&quot;&gt;<br>  &lt;dyn-form<br>    [config]=&quot;<strong>config</strong>&quot;<br>    [form]=&quot;<strong>form</strong>&quot;<br>    [mode]=&quot;<strong>mode</strong>&quot;<br>  &gt;&lt;/dyn-form&gt;<br><br>  &lt;button type=&quot;button&quot; (click)=&quot;mode = &#39;display&#39;&quot;&gt;<br>    Switch to Display Mode<br>  &lt;/button&gt;<br>&lt;/div&gt;</pre><p>and voilá!</p><figure><img alt="simple-form demo at Stackblitz" src="https://cdn-images-1.medium.com/max/717/1*z3eisrGseg4bwH1nYQbC_w.png" /></figure><h3>Where the magic happens</h3><p>The main feature is the ability to plug-in new Dynamic Form Controls, provide customized ones for some particular requirements, or integrate third-party components into our forms, with ease!</p><p>For this matter, Angular’s InjectionTokensare the way to apply the <a href="https://dev.to/this-is-angular/plugin-architecture-for-angular-libraries-using-dependency-injection-5d8k"><em>Dependency Inversion Principle</em></a>, so we do not rely on the controls provided by a single library anymore, but any NgModule (like DynFormsMaterialModule) can provide new controls via the DYN_CONTROL_TOKEN by registering the component to be loaded dynamically (DynControl) with an “ID” (INPUT, RADIO, SELECT, etc).</p><p>From there the Dynamic Form Registry can let the Factory know what component it should load for a given “ID”</p><pre>@Injectable()<br>export class DynFormRegistry {<br>  constructor(<br>    @Inject(<strong>DYN_CONTROLS_TOKEN</strong>) controls: ControlProvider[]<br>  )</pre><p>it’s super hard to name these kind of “id” and “type” fields, so trying to keep the context clear, the ControlProvider interface consists of:</p><pre>export interface InjectedControl {<br> control: DynControlType;<br> instance: DynInstanceType;<br> <strong>component</strong>: Type&lt;AbstractDynControl&gt;;<br>}</pre><ol><li>the control identificator is the ‘string’ to reference the dynamic control in the Config Object</li><li>the instance is the type of AbstractControl that it will create in the form hierarchy (FormGroup, FormArray or FormControl), and</li><li>the component which should extend any of the Dynamic Control classes (DynFormGroup, DynFormArray, DynFormControl or DynFormContainer) implementing the simple contract <a href="https://github.com/myndpm/open-source/tree/master/libs/forms#extending">explained here</a>.</li></ol><h3>Configuration Object Typing</h3><p>You can define your Form with an array of controls which can have some subcontrols; with this nested structure you can build any hierarchy to satisfy your needs (like in the example). This configuration unit is specified by the DynBaseConfig interface which follows a simple Tree structure:</p><pre>export interface <strong>DynBaseConfig</strong>&lt;TMode, TParams&gt; {<br> <strong>name</strong>?: string;<br> <strong>controls</strong>?: <strong>DynBaseConfig</strong>&lt;TMode&gt;[];<br> modes?: DynControlModes&lt;TMode&gt;;<br>}</pre><p>The form also supports different “modes”. Modes are partial overrides that we can apply to the main Control Configuration depending on a particular situation. In the <a href="https://mynd.dev/demos/dyn-forms/simple-form">simple-form demo</a> we show an example of this: a display mode where we define a readonly: true parameter to be passed to all the dynamic controls, and they react changing their layout or styles. These “modes” are just a custom string, so the configuration is open to any kind of mode that you’d like to define.</p><p>In the DynFormConfig you can specify the global overrides for each mode:</p><pre>const config: DynFormConfig&lt;&#39;edit&#39;|&#39;display&#39;&gt; = {<br>  modes: {<br>    <strong>display</strong>: {<br>      params: { readonly: true }</pre><p>and you can also override the configuration of a single control for a given a mode, like this RADIO button being changed to an INPUT control when we switch the form to display mode:</p><pre>createMatConfig(&#39;<strong>RADIO</strong>&#39;, {<br>  name: &#39;account&#39;,<br>  params: { label: &#39;Create Account&#39;, color: &#39;primary&#39; },<br>  modes: {<br>    <strong>display</strong>: {<br>      control: &#39;<strong>INPUT</strong>&#39;,<br>      params: { color: &#39;accent&#39; },</pre><p>In this case, the control will be overriden but the params will be merged and we will have the original label in the display mode.</p><h3>Feedback WANTED</h3><p>With this brief introduction to this powerful library, we hope that you join its design/development efforts by sharing your experience/ideas/point of view in the <a href="https://github.com/myndpm/open-source/discussions">GitHub Discussions</a> opened for the upcoming features, creating Pull Request extending or adding new Material controls, or reporting <a href="https://github.com/myndpm/open-source/issues">Issues</a> that you find.</p><p>There are some challenges to be addressed, like a standard way to handle the Validations and show the respective Error message; handle the visibility of a field depending on some conditions; these topics have opened discussions to collect ideas and figure out a solution.</p><p>We might write more articles explaining the internals to analyze and improve the chosen architecture.</p><p>Without further ado, <a href="https://www.npmjs.com/package/@myndpm/dyn-forms">enjoy it</a>!</p><p><em>// PS. We are hiring!</em></p><p><a href="https://stackblitz.com/edit/myndpm-dyn-forms?file=src/app/simple-form/simple.form.ts">myndpm-dyn-forms - StackBlitz</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=683a2c417661" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reactive DataSource for Angular]]></title>
            <link>https://matheo.medium.com/reactive-datasource-for-angular-1d869b0155f6?source=rss-7926f178820f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d869b0155f6</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[material-design]]></category>
            <category><![CDATA[data-list]]></category>
            <dc:creator><![CDATA[Mateo Tibaquirá Palacios]]></dc:creator>
            <pubDate>Mon, 17 Jun 2019 05:15:46 GMT</pubDate>
            <atom:updated>2021-02-23T21:32:38.374Z</atom:updated>
            <content:encoded><![CDATA[<p>This article presents you @matheo/datasource which aims to facilitate the listing of any kind of data inside a Material Table or any Angular Component. It’s a battle-tested library but improvements and suggestions are <a href="https://github.com/matheo/angular/issues/new">warmly welcomed</a>. This article is the initial documentation as I need some help and time to build a decent one :D</p><p>I’ve mounted a <a href="http://matheo.co/demos/datasource">demo app</a> with a (hopefully) self-explanatory <a href="https://github.com/matheo/blitz.datasource/commits">list of commits</a>, building the list step by step, consuming a simple Firestore collection:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*r2D9vEE9bjonzmH3913WYg.png" /><figcaption>Screenshot of the demo list that will showcase the features</figcaption></figure><h3>The Concepts</h3><p>Some years ago I had the challenge to build different lists with mat-table, so I took some code snippets from the official documentation (thanks for the awesome docs material team!) and I saw their approach having a Database service providing the data, to a DataSource that was consumed by the table component on initialization, via aconnect() method.</p><p>The connect() returns a stream of data to be listed. Nowadays, the mat-table.dataSource input can be an array of data, a direct stream or a DataSource instance implementing the connect/disconnect interface.</p><p>I loved the DataSource approach and I started to dream with a flexible class to build data lists with ease, reusing it in the different scenarios that I had to implement. In those days I had no experience with rxjs and I had to feed this DataSource with different observables from the UI events like Sorting, Pagination, Filtering, and sometimes System events.</p><p>That stream of events flows within this structure:</p><ul><li>a UI triggering different events for the List,</li><li>a DataSource collects them to build a <em>REQ</em>uest object,</li><li>a Database processing the request into a <em>RAW</em> data result,</li><li>a mat-table consuming a post-processed <em>RES</em>ult fromconnect.</li></ul><p>the upper-case notation corresponds to the MatDataSource definition:</p><p>abstract class MatDataSource&lt;REQ, RAW, RES&gt; extends DataSource&lt;RES&gt;</p><h3>The Code</h3><p>Start installing the library as usual:</p><p>yarn add @matheo/datasource or npm install @matheo/datasource</p><p>and adding MatDataSourceModule to your modules aimed to list data:</p><p>import { MatDataSourceModule } from &#39;@matheo/datasource&#39;;</p><h4>Database</h4><p>The database service will translate a <em>REQ</em>uest into a <em>RAW</em> list of data to be processed by the DataSource and obtain a <em>RES</em>ult, so, the database service methods are queries to the backend or any source of data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/1*FOlrO584NYrMlvS7mGXl2Q.png" /><figcaption>Simplest Firebase Database</figcaption></figure><p>It can be as simple as <a href="https://github.com/matheo/blitz.datasource/blob/e4fc37f60b6ce621ca113fb16262f54072a0d650/src/app/features/sponsors/data/sponsors.database.ts">in the image</a>, or with some complexity, it will query the backend considering each scenario and will look like <a href="https://github.com/matheo/blitz.datasource/blob/master/src/app/features/sponsors/data/sponsors.database.ts">this</a>.<br>This simple database is not processing a <em>REQ</em>uest but listing some items, and with this initial database, you will be able to see your table working and start to extend it depending on the required functionality as you can see in the <a href="https://github.com/matheo/blitz.datasource/commits">commit list</a>.</p><h4>DataSource</h4><p>The datasource service will collect (register) the change-event input streams via the addStream method; each stream emits a full or partial <em>REQ</em>uest object, some of them might need to startWith a default value. For instance, MatPaginator.page observable streams a PageEvent that can be formatted to match your pagination parameters, and by default it uses the configuredpageIndex and pageSize.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*vwkFf6Eqj6EvEqLLraywpg.png" /></figure><p>Once we use the connect method, the datasource will combine the registered streams and merges their output values to produce the <em>REQ</em>uest object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*5P72SK5jbeDwPkukH9E5yw.png" /></figure><p>We can configure it to know when to autoStart or not, so it will block the stream if necessary; also, it will skip the repeated <em>REQ</em>uests, and if you want to force it you can use the reload method. After that, it will execute the query, process the total count, post-process the <em>RAW</em> data, and returns an array of <em>RES</em>ulting items.</p><p>There are some additional processes under the hood, like timeout messages if there’s no response after some seconds, updating the isLoading, isLoaded, isEmpty state flags and triggering the change$ observable every time the DataSource changes its state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*L5H24qMEmxJ18o_EgRKsdA.png" /></figure><p>To implement your DataSources you only have to customize the core processing of your data, from building up the <em>REQ</em>uest object, fetching the <em>RAW</em> data, having a default <em>RAW</em> response in case of error, fetching the total count for pagination purposes, and post-processing the <em>RES</em>ult to get your desired data on the table!</p><p>The DataSource for Firestore required some special considerations to handle the sorting and the total, and the queries of course. The complete code can be seen <a href="https://github.com/matheo/blitz.datasource/blob/master/src/app/features/sponsors/data/sponsors.datasource.ts">here</a>, and any feedback is welcome :)</p><h4>List Component</h4><p>Personally, I do provide the Database service globally (providedIn: &#39;root&#39;) but the DataSource locally from the container component, so I don’t have conflicts with another instance configured in a different way. I include it in the providers of the container component and <a href="https://github.com/matheo/blitz.datasource/commit/34772270190779070f977c2a0bcb90e8ace6594a">pass it to child components</a>.</p><p>Also, the library provides an overlay component, to render the table and other elements and show the loading spinner, the configured timeout messages, and any error or empty message too. You just need to wrap the mat-table inside it:</p><p>&lt;mat-datasource [dataSource]=&quot;source&quot;&gt;<br> &lt;mat-table [dataSource]=&quot;source&quot; ...&gt;...&lt;/mat-table&gt;<br>&lt;/mat-datasource&gt;</p><p>You can customize the look and feel vía the .mat-datasource-overlay CSS class which defaults to a flexbox with centered content, and use .mat-datasource-empty , .mat-datasource-error and .mat-datasource-loading for the configured messages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*jYC6W30CZYVFBmvPJzVxeQ.png" /></figure><p>You can configure the DataSource in the way you want vía the config API. I usually put the global config in the constructor, and some custom stuff inside each container component. Note that you can enable the debug to get verbose information of each step in the data processing.</p><h4>Input Streams / Data Mutators</h4><p>As mentioned, you add the streams to listen vía addStream. For the MatSort and MatPaginator streams, the library offers built-in methods to extract the relevant arguments, like the orderBy, orderDir, pageIndex and pageSize respectively, so you can simply use:</p><p>this.dataSource.setPaginator(this.paginator)</p><p>where paginator is the MatPaginator ViewChild of the <a href="https://github.com/matheo/blitz.datasource/commit/7bc6444ff89a573ff9e55c9e754356dfe38a9453">component</a>.</p><p>Additional streams can be registered <a href="https://github.com/matheo/blitz.datasource/commit/549c70f765bc175c53883202cf8ee54816dbe431">like this</a>, listening form changes, and setting up the form.valueChanges stream to start with the form.value as the initial part of the <em>REQ</em>uest. The DataSource merges all the outputs of the streams to build the complete <em>REQ</em>uest object.</p><h4>Furthermore</h4><p>This DataSource can be used in Autocompleters and Search components extending the ReactiveDatasource abstract class, and implementing two additional methods:</p><ul><li>filter to search a certain query and get a limit set of items:<br>filter(query: string, limit: number): void</li><li>resFilter to post-process the matching results and format them in a friendly standard format for item lists or auto-completers:<br>resFilter(result: RES[]): DataSourceItem[]</li></ul><p>Also, there’s a dataSource pipe to work like the async pipe but taking a ReactiveDataSource as input: *ngIf=&quot;source | dataSource as items&quot;.</p><h3>Demo Running</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstackblitz.com%2Fedit%2Fmatdatasource%3Fembed%3D1%26view%3Dpreview&amp;url=https%3A%2F%2Fstackblitz.com%2Fedit%2Fmatdatasource%3Fembed%3D1%26view%3Dpreview&amp;image=https%3A%2F%2Fc.staticblitz.com%2Fassets%2Ficon-664493542621427cc8adae5e8f50d632f87aaa6ea1ce5b01e9a3d05b57940a9f.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=stackblitz" width="745" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/28279fa327ea10c3a35552c80a84bea2/href">https://medium.com/media/28279fa327ea10c3a35552c80a84bea2/href</a></iframe><h3>Enjoy!</h3><p>That’s it! basically. I need to get some time to build the documentation (help is welcome!) and maybe share some Databases for different needs, like I did this time with the Firestore specific requirements.</p><p>Please leave a comment with your impression,<br>even if it’s to say that I over-extended the size of this article,<br>or improvements in the writing (apologies in advance)<br>Have fun! :D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d869b0155f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a full-stack Nx monorepo]]></title>
            <link>https://matheo.medium.com/creating-a-full-stack-nx-monorepo-cbc5b88e4fa3?source=rss-7926f178820f------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbc5b88e4fa3</guid>
            <category><![CDATA[angular-cli]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[nx]]></category>
            <dc:creator><![CDATA[Mateo Tibaquirá Palacios]]></dc:creator>
            <pubDate>Tue, 15 Jan 2019 20:40:46 GMT</pubDate>
            <atom:updated>2021-03-08T02:06:49.192Z</atom:updated>
            <content:encoded><![CDATA[<p>Edit: <a href="https://indepth.dev/posts/1247/code-sharing-made-easy-in-a-full-stack-app-with-nx-angular-and-nestjs">This article by Mateus Carniatto</a> seems more updated than my old experiment. I will be posting new ones soon :)</p><p>First of all, why a monorepo? there are <a href="https://danluu.com/monorepo/">many</a> <a href="https://hackernoon.com/one-vs-many-why-we-moved-from-multiple-git-repos-to-a-monorepo-and-how-we-set-it-up-f4abb0cfe469">articles</a> <a href="https://medium.com/@maoberlehner/monorepos-in-the-wild-33c6eb246cb9">out</a> <a href="https://www.google.com/search?q=advantajes+of+monorepos">there</a> that explain why this kind of setup facilitates the development of complex applications. Code reusability and consistency are hugely improved, making visible any particular change on the system across all the dependencies, and facilitating the integration tests.</p><p>@nrwl/nx is a tool built on the top of @angular/cli that help us to create a workspace. with special folders for applications and libraries, along with some scaffolding to help with building, linting, and testing, encouraging the global usage of best practices and team standards.</p><h3>Setting up an Nx monorepo</h3><p>Nx can be installed in the following ways:</p><pre>npm install -g @angular/cli @nrwl/schematics<br>yarn add global @angular/cli @nrwl/schematics</pre><p>Within @nrwl/schematics we have the utility to create our workspace:</p><pre>create-nx-workspace mymonoreponame</pre><p>This will create an Nx Workspace using Angular CLI with the Nx schematics collection. You can also add Nx capabilities to an existing CLI project using:</p><pre>ng add @nrwl/schematics</pre><p>Within the workspace, we will have the apps, libs, tools, with the configuration files for Angular, Nx, TSLint and Typescript:</p><pre>/apps           &lt;- our frontend and backend apps<br>/libs           &lt;- shared libraries<br>/tools          &lt;- schematic and misc tooling<br>angular.json    &lt;- angular configuration for apps and libs<br>nx.json         &lt;- nx metadata<br>package.json    &lt;- main project info and scripts<br>tsconfig.json   &lt;- global compilation config<br>tslint.json     &lt;- global lint rules</pre><p>By default, Angular uses Karma and Protractor for testing, but Nx supports the usage of Jest and Cypress. If you want to enable Jest, you need to execute:</p><pre>ng generate jest</pre><p>this will install the packages and update the required configurations, and we need to do it only once per workspace.</p><h4>Creating a Frontend App</h4><p>Adding new apps to an Nx workspace is done by using the Angular CLI generate command, with the app schematic provided by Nx:</p><pre>ng generate app myfrontendapp<br>ng generate app web --unitTestRunner=jest --e2eTestRunner=cypress</pre><p>This will add the required folders and files, and its configuration like:</p><pre>/apps<br>  /web<br>    /src              &lt;- Angular app<br>    browserslist      &lt;- supported browsers criteria<br>    jest.config.js    &lt;- Jest config<br>    tsconfig*.json    &lt;- custom compilation rules<br>    tslint.json       &lt;- custom lint rules<br>  /web-e2e<br>    /src              &lt;- Angular e2e tests<br>    cypress.json      &lt;- Cypress config<br>    tsconfig*.json    &lt;- custom compilation rules</pre><h4>Creating a Backend App</h4><p>We need to use the node-app schematic here, and optionally we can pick a backend framework like express or nestjs.</p><pre>ng generate node-app server<br>ng generate node-app server --framework=nestjs</pre><p>generating a backend App with a pretty similar structure:</p><pre>/apps<br>  /server<br>    /src              &lt;- NestJS/Express App<br>    jest.config.js    &lt;- Jest config<br>    tsconfig*.json    &lt;- custom compilation rules<br>    tslint.json       &lt;- custom lint rules</pre><p>as you can see, Nx provides easy ways to customize the global rules when a specific project requires it and organizes our apps in a consistent way.</p><h4>Creating Libraries</h4><p>Now it’s time to share some code using libs. Let’s create theshared one:</p><pre>ng generate lib mylibraryname<br>ng generate lib shared --unitTestRunner=jest --publishable</pre><p>this will create a consistent structure but this time with some new files:</p><pre>/libs<br>  /shared<br>    /src<br>      /lib            &lt;- library source<br>      index.ts        &lt;- library entrypoint<br>    jest.config.js    &lt;- test runner config<br>    ng-package.json   &lt;- packaging configuration<br>    package.json      &lt;- library npm metadata<br>    tsconfig*.json    &lt;- custom compilation rules<br>    tslint.json       &lt;- custom lint rules</pre><p>the --publishable option added some package files required to publish the built library on an npm registry. That’s helpful if another repository or project will use this library outside of the monorepo.</p><p>This library generation will also configure the global tsconfig.json paths with the library entry point. Be sure to customize your project scope in the nx.json file or while you create your workspace:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30b1b019c7aa93d95de47b0185d6cde0/href">https://medium.com/media/30b1b019c7aa93d95de47b0185d6cde0/href</a></iframe><p>From there, you can add some common components and utilities inside the @myproject/shared library, and import them in your apps easily. You can think about how many libraries do you want to handle to modularize your project properly, and Nx will take care of the setup for you.</p><h4>Nx Utilities</h4><p>Nx also knows how your apps and libs depend on each other. To see the dependency graph of your project just run:</p><pre>npm run dep-graph<br>yarn dep-graph</pre><p>also, Nx provides a useful script for CI to test only the changed code on a branch. If you modify a library, it will run tests for all the apps that use it:</p><pre>npm run affected:test --base=master<br>yarn affected:test --base=master</pre><p>and finally, you can keep your Nx up to date running the following script when a new release comes out:</p><pre>yarn add @nrwl/schematics@latest<br>yarn update</pre><p>you can check all the available scripts inside the package.json file.</p><h3>Angular Console</h3><p>Recently the <a href="https://medium.com/u/2817fb68583">Nrwl.io</a> team released a powerful tool that gives a visual overview of the complete project and the available schematics to use. With it you can check deeper all the options that you have while creating Apps and Libraries, and also generating components, services, etc. You can learn more at <a href="https://angularconsole.com/">angularconsole.com</a>.</p><h4>NgRx Schematics</h4><p>Using it, I’ve been developing a custom set of scripts with the available schematics to build my Stores, Reducers, Actions, and Effects faster. Here I share some of them with my custom approach to structure them.</p><h4>Root Store with Actions and Effects</h4><p>Tools shouldn’t limit your taste when it comes to structure your projects, so playing with the Angular Console, I’ve been finding the right commands to use to keep my standards and have a result like:</p><pre>/app<br>  /store<br>    /actions<br>      session.actions.ts<br>    effects.ts<br>    index.ts<br>    reducers.ts<br>    state.ts</pre><p>and I made it with three actions on the Console that resulted in the following commands:</p><pre>ng generate @ngrx/schematics:store app --statePath=store --no-flat --no-spec --root --module=app.module.ts --stateInterface=AppState</pre><pre>ng generate @ngrx/schematics:effect store/router --no-flat --no-spec --root --module=app.module.ts</pre><pre>ng generate @ngrx/schematics:action store/lang --group</pre><p>you can check the detailed commits and my customizations <a href="https://github.com/matheo/monorepo/commits/master?after=827122d957e6dfe41e4444607ce811332c47b990">here</a>.</p><h3>Enjoy!</h3><p>Angular is moving on with awesome tools and patterns that will make our life as developers pretty enjoyable, so keep it up with the new releases!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbc5b88e4fa3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>