Author Archives: Aleksei

About Aleksei

Blog owner

Communication on project architecture development

Discussion
Photo by Austin Distel on Unsplash

Today I had a call with a developer of a library we are using in one of our applications. We have discussed our use case: workaround we implemented to overcome limitations and an alternative solution from his side. The call was useful as I got additional inputs which I’m going to apply. That made me think about how multifaceted communication can be during the process of architecture development:

  • collect functional and non-functional requirements to the platform;
  • present research results to the team;
  • plan implementation steps;
  • collect feedback from the team;
  • contact the infrastructure team;
  • discuss alternative approaches;
  • resolving conflicts of interests;
  • contact dependencies development teams;
  • provide dedicated requirements to the team’s area of responsibility;
  • support the team.

The items might be not exactly in such order and probably I’ve missed some of them. Each round can be repeated several times during changes in the platform and depending on the development stage. Different rounds of communication involve different numbers of participants with different roles, and can go occasionally or on a scheduled basis.

Sometimes people can communicate on a topic without sharing results or agree on something not corresponding to the initial concepts, which causes conflicts of interests between participants. The more people in a group, the more difficult it is to keep track of discussions. Thanks to the scrum master role the whole process can be organized in a comfortable manner.

Moving elements through DOM tree

Tree
Photo by niko photos on Unsplash

Several days ago I worked on a task where the solution was to create some elements in the DOM tree in one container and then move them to another. What I liked about it is how easy it can be done. I would like to describe some kind of fixed todo-list implementation as an example in my current post. If you like you may just check the extended code here: https://stackblitz.com/edit/moving-elements-through-dom-tree?file=index.html.

Page markup

First let’s check the HTML structure of the page: block to store undone tasks, block to store done tasks and the button to move task from one list to another:

<div id="undone">
  <div class="task">
    <div class="header">Clean the room</div>
    <div class="description">Make the bed, put books on the shelf, vacuum the floor.</div>
  </div>
  <div class="task">
    <div class="header">Do the home work</div>
    <div class="description">Math, English, Physics</div>
  </div>
</div>

<div id="done">
</div>

<button onclick="done()">Done</button>

The task consists of two parts: header and description. By default description is hidden. Also lists have different text color and default cursor for task header is switched to pointer:

#undone .task .header { color: red; }
#done .task .header { color: green; }
.header { cursor: pointer; }
.description { display: none; }

Toggling description visibility

The function for toggling description is based on the target property of the Event object which is passed to the listener.

function showDescription(event) {
  const description = event.target.parentNode.querySelector('.description');
  if (description)
    description.style.display =
      description.style.display == 'block' ? '' : 'block';
}

Here if we could find the description element next to the header we are switching the display CSS property. After page is loaded the function is assigned to each task header element as onclick event handler:

document.addEventListener('DOMContentLoaded', () =>
  document
    .querySelectorAll(".task .header")
    .forEach((header) => header.addEventListener('click', showDescription))
);

More clever would be to assign the listener to the whole list (in real projects it will increase performance when there are lots of elements) but I intentionally have done it this way to demonstrate that after moving the element the event listener is not gone.

Moving element

Finally, function which move the first task from the list of undone task to the list of done ones:

function done() {
  const task = document.getElementById("undone").querySelector('.task');
  if (task) document.getElementById("done").appendChild(task);
}

So to move elements from one place to another in the DOM tree all is needed is just to use the appendChild method of the new parent node. When this method is used browser just reset the link to parent node for moved element.

The described example is very basic just to demonstrate browser behavior. On top of it any other logic of element manipulation can be done, e.g. blocks shuffling or creating paired lists. As an alternative cloning the node might be an option, but in this case the clone will lose all event listeners and they should be assigned once again. Depending on the situation one or another solution might be suitable.

Overengineering with Angular InjeсtionToken

Photo by ThisisEngineering on Unsplash

When I have enough material I write technical articles, but sometimes for the subject a small blog post is a much more suitable genre.

Almost every day I look for something new on Medium, Dev.to or other sources to track the context of average topics of average daily software development. Once I stumbled upon an article about using such a feature of Angular as InjectionToken. It is being used quite often and it helps to resolve situations when additional flexibility should be added to DI.

Some of provided in article examples looked as following (the code is changed, but the idea is left):

import { InjectionToken } from '@angular/core';

export const BIG_BOX_COOKIE_AMOUNT = new InjectionToken<number>('BIG_BOX_COOKIE_AMOUNT');

@Component({
  standalone: true,
  selector: 'cookies',
  template: "Cookies left: ...",
  providers: [{
     provide: BIG_BOX_COOKIE_AMOUNT,
     useFactory: () => 5 * 30 // amount of packs in a box * amount of cookies in a pack
  }]
})
export class CookiesComponent {
  constructor(@Inject(BIG_BOX_COOKIE_AMOUNT) initCookieAmount: number) {}
  // Logic of CookiesComponent
}

I understand that the intention of the author was good — to show the power of the feature, but in such a case the value (cookie amount) can be provided simply with a constant and the described feature is not relevant. A better example is needed.

When newcomers see examples they start to reproduce the approaches in their projects assuming them as normal practices. We all at some point can overengineer our code. But probably we should keep in mind that sometimes we need to think twice before committing the code if we can simplify it.

Home Page in 2024

Antique Typewriter on Dark Wood
Photo by Patrick Fore on Unsplash

Lots of various social networks provide huge possibilities to share different types of content. We create our profiles and immediately may follow our friends and colleges. After publishing something we get the feedback rather fast from our contacts. Messengers as well now provide similar experience. We shop on social networks, search for information and read news. Presence on the Internet doesn’t require any technical skills.

On the other hand, tuning of social network profiles is limited: standard profile address, design and functionality. Any picked social network profile looks the same as others and gets lost among them.

Creating a separate home page is a more tricky process which provides freedom of choice: how to organize the web-site, what kind of functionality to add, how elements of the web-page should look, etc. From the technical perspective possibilities are limited only by skills and imagination. Migration is a case of switching web-hosting or implementation most likely will be clear because of access to raw data: files and databases. Personal web-sites can be constantly being improved and be started as simple static pages.

I already worked on a couple of own web-sites (not taking into account blogs and those from early years at school), but, probably because I wanted them to pretend to be more valuable, I didn’t call them “Home Page”. And now I would like to create one starting with a WordPress blog.