<?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 Imeda Bekaia on Medium]]></title>
        <description><![CDATA[Stories by Imeda Bekaia on Medium]]></description>
        <link>https://medium.com/@imedbekaia?source=rss-b210a610c653------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*DV9AmVkib2BKx8Jup9sKdw.jpeg</url>
            <title>Stories by Imeda Bekaia on Medium</title>
            <link>https://medium.com/@imedbekaia?source=rss-b210a610c653------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 08:01:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@imedbekaia/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[ფიზიკა, რომელსაც ხელით შეეხები: როგორ შევქმენით ოფლაინ ფიზიკის ლაბორატორია]]></title>
            <link>https://imedbekaia.medium.com/%E1%83%A4%E1%83%98%E1%83%96%E1%83%98%E1%83%99%E1%83%90-%E1%83%A0%E1%83%9D%E1%83%9B%E1%83%94%E1%83%9A%E1%83%A1%E1%83%90%E1%83%AA-%E1%83%AE%E1%83%94%E1%83%9A%E1%83%98%E1%83%97-%E1%83%A8%E1%83%94%E1%83%94%E1%83%AE%E1%83%94%E1%83%91%E1%83%98-%E1%83%A0%E1%83%9D%E1%83%92%E1%83%9D%E1%83%A0-%E1%83%A8%E1%83%94%E1%83%95%E1%83%A5%E1%83%9B%E1%83%94%E1%83%9C%E1%83%98%E1%83%97-%E1%83%9D%E1%83%A4%E1%83%9A%E1%83%90%E1%83%98%E1%83%9C-%E1%83%A4%E1%83%98%E1%83%96%E1%83%98%E1%83%99%E1%83%98%E1%83%A1-%E1%83%9A%E1%83%90%E1%83%91%E1%83%9D%E1%83%A0%E1%83%90%E1%83%A2%E1%83%9D%E1%83%A0%E1%83%98%E1%83%90-%E1%83%A5%E1%83%90%E1%83%A0%E1%83%97%E1%83%95%E1%83%94%E1%83%9A%E1%83%98-e0e983180ba6?source=rss-b210a610c653------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0e983180ba6</guid>
            <category><![CDATA[physics]]></category>
            <category><![CDATA[edtech]]></category>
            <category><![CDATA[electronics]]></category>
            <category><![CDATA[threejs]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Imeda Bekaia]]></dc:creator>
            <pubDate>Tue, 13 Oct 2026 11:51:55 GMT</pubDate>
            <atom:updated>2026-10-13T11:54:58.029Z</atom:updated>
            <content:encoded><![CDATA[<p><em>dwall-e — 75 ინტერაქტიული სიმულაცია ქართულად, ინტერნეტის გარეშე, ნებისმიერ კომპიუტერზე</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*weCd7dI0GNAoZ6KOByzjFw.png" /><figcaption><em>ჰორიზონტისადმი კუთხით ნასროლი სხეულის ტრაექტორია</em></figcaption></figure><h3>დაფა, ცარცი და ფორმულა, რომელიც არაფერს ამბობს</h3><p>წარმოიდგინეთ ფიზიკის გაკვეთილი. დაფაზე წერია s = v₀t + at²/2. მასწავლებელი ხსნის, მოსწავლეები იწერენ. ზოგს ესმის, უმეტესობას კი ფორმულა რჩება სიმბოლოების უაზრო რიგად, რომელიც საკონტროლოსთვის უნდა დაიზეპიროს.</p><p>ახლა წარმოიდგინეთ სხვა სურათი. მოსწავლე სლაიდერით ზრდის სროლის კუთხეს და უყურებს, როგორ იცვლება ტრაექტორია. 30°-ზე ბურთი შორს მიდის, 60°-ზე მაღლა ადის, მაგრამ იმავე მანძილზე ეცემა. 45°-ზე ყველაზე შორს. ეს ფორმულიდან არავის უთქვამს, მან თვითონ აღმოაჩინა.</p><p>ფიზიკა ექსპერიმენტული მეცნიერებაა. მას ცდებით სწავლობენ, დაზეპირებით ვერ ისწავლი. სწორედ ამ იდეაზე დგას <strong>dwall-e</strong>.</p><h3>პრობლემა: რატომ არის ფიზიკა ქართულ სკოლაში რთული</h3><p>ფიზიკა ბუნებით რთული საგანი არ არის. უბრალოდ, სწავლება ხშირად ისე არ მიმდინარეობს, როგორც ამ საგანს სჭირდება.</p><p><strong>1. ლაბორატორიის ნაკლებობა.</strong> ბევრ სკოლაში, განსაკუთრებით რეგიონებში, ფიზიკის ლაბორატორია ან საერთოდ არ არის, ან მოძველებულია. ქანქარის, ჭოჭონაქის ან ელექტრული წრედის აწყობა ბევრ მოსწავლეს მხოლოდ სახელმძღვანელოს ნახატზე უნახავს. ელექტრომაგნიტური ინდუქცია, ატომის აგებულება ან შავი ხვრელი კი ვერცერთ სკოლის ლაბორატორიაში ვერ „დაიჭირე“.</p><p><strong>2. შედეგები.</strong> PISA 2022-ის კვლევაში საქართველოს მოსწავლეების შედეგები საბუნებისმეტყველო მეცნიერებებსა და მათემატიკაში OECD-ის საშუალოზე მნიშვნელოვნად დაბალია. <em>[აქ ჩასვით ზუსტი ციფრები და წყარო: OECD PISA 2022 Results, Georgia country note]</em>. ეს მოსწავლეების ნიჭის ბრალი არ არის. ეს იმის ნიშანია, რომ აბსტრაქტული ცნებები მათ თვალით არ უნახავთ და ხელით არ უცდიათ.</p><p><strong>3. ენა.</strong> მსოფლიოში ფიზიკის შესანიშნავი ინტერაქტიული რესურსები არსებობს, მაგრამ უმეტესობა ინგლისურადაა. ქართულ თარგმანებს, სადაც ისინი არსებობს, ხშირად არ ახლავს თეორია, დავალებები და ქართული სასწავლო გეგმის ლოგიკა. მეათე კლასელს ფიზიკისა და ინგლისურის ერთად სწავლა არ უნდა დასჭირდეს.</p><p><strong>4. ინტერნეტი.</strong> ონლაინ პლატფორმები გულისხმობს, რომ ყველა კლასს სტაბილური ინტერნეტი აქვს. ეს ყოველთვის ასე არ არის. სკოლის კომპიუტერულ კლასს, სოფლის სკოლას ან სახლის ძველ ლეპტოპს უნდა შეეძლოს მუშაობა ქსელის გარეშეც.</p><h3>იდეა: ლაბორატორია, რომელიც ყველა კომპიუტერში ეტევა</h3><p>dwall-e არის <strong>დესკტოპ აპლიკაცია</strong>, რომელიც 10–18 წლის მოსწავლეებისთვის შეიქმნა. მისი მთავარი პრინციპები ასეთია:</p><ul><li><strong>მხოლოდ ინტერაქტიული.</strong> პროექტში ერთი წესი არ ირღვევა: ყოველი თემა არის ცოცხალი, ანიმირებული სიმულაცია, რომლის პარამეტრებსაც მოსწავლე თვითონ ცვლის. „მხოლოდ ტექსტის“ გვერდები აკრძალულია. სწავლობ ასე: ცვლი მნიშვნელობას და აკვირდები, რა ხდება.</li><li><strong>სრულად ქართულად</strong> (და ინგლისურად). ყოველი სიტყვა, ფორმულის განმარტება და დავალება ორივე ენაზე არსებობს.</li><li><strong>ოფლაინ.</strong> ერთხელ ჩამოტვირთავ და ინტერნეტი აღარ გჭირდება. არც ანგარიში, არც რეგისტრაცია. პროგრესი მხოლოდ შენს კომპიუტერზე ინახება.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E--vMkcMLaRT6V2e35ZD1Q.png" /><figcaption>მთავარი გვერდი: თემები, ძიება და „მნიშვნელოვანი თემები“</figcaption></figure><h3>რა არის შიგნით</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*T7yx94uxDJ1qjxldvg7wjQ.gif" /><figcaption>45°-ით ნასროლი ბურთი: ტრაექტორია და სიჩქარის ვექტორები</figcaption></figure><p><strong>8 თემატური მიმართულება:</strong> მექანიკა, ტალღები, ელექტრობა, მაგნეტიზმი, ოპტიკა, თერმოდინამიკა, თანამედროვე ფიზიკა, კოსმოსი. მათში უკვე <strong>75 მზა სიმულაციაა</strong>: თავისუფალი ვარდნიდან და ნიუტონის კანონებიდან ფუკოს ქანქარამდე, ომის კანონიდან ტრანსფორმატორამდე, კეპლერის კანონებიდან ფარდობითობის თეორიამდე და შავ ხვრელებამდე.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CZ3EymLBbGveKfcaH2R06A.png" /><figcaption>მზის სისტემა 3D-ში: პლანეტების ორბიტები და თარიღი</figcaption></figure><p><strong>4 სირთულის დონე:</strong> დამწყები, საშუალო, გაღრმავებული, ექსპერტი. ერთი და იგივე სიმულაცია მეხუთე კლასელს ორ მარტივ სლაიდერს აჩვენებს, მეთერთმეტე კლასელს კი დამატებით პარამეტრებს, გრაფიკებს, ფორმულებს და დროის ბიჯის მართვას. თემა მოსწავლესთან ერთად „იზრდება“.</p><p><strong>ყოველ სიმულაციაში:</strong></p><ul><li><strong>პარამეტრები</strong> და მზა პრესეტები (მაგ. „მთვარეზე“, „იუპიტერზე“);</li><li><strong>ცოცხალი გაზომვები</strong>: სიჩქარე, ენერგია, ძალა, დრო;</li><li><strong>გრაფიკები</strong>, რომლებიც რეალურ დროში იხაზება;</li><li><strong>თეორია</strong>: ძირითადი იდეა, ფორმულები, ცვლადები ერთეულებით;</li><li><strong>გამოწვევები</strong>: „ააწყვე ბერკეტი ისე, რომ წონასწორობაში იყოს“, „ესროლე ბურთი ისე, რომ 50 მეტრზე დაეცეს“. სისტემა ფიზიკურ შედეგს ამოწმებს და არა იმას, სლაიდერი სწორ მნიშვნელობაზე დგას თუ არა.</li></ul><p><strong>ლაბორატორია.</strong> მზა სიმულაციების გარდა, აპში არის თავისუფალი ლაბორატორია. მექანიკის მაგიდაზე საკუთარ ცდას ააწყობ, ელექტრონიკის ლაბორატორიაში კი ვირტუალურ <strong>დაფაზე (breadboard)</strong> რეზისტორებით, ნათურებითა და ელემენტებით აწყობ წრედს, ხოლო ამპერმეტრი და ვოლტმეტრი რეალურ მნიშვნელობებს აჩვენებს. ომის კანონის თემიდან ერთი ღილაკით („ააწყვე ლაბორატორიაში“) იგივე წრედი დაფაზე გადადის.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5SJzk7Ty1L5dKRmRyoQILg.png" /><figcaption>ელექტრონიკის ლაბორატორია: ნათურა, ამპერმეტრი და ვოლტმეტრი სამონტაჟო დაფაზე</figcaption></figure><p><strong>ცნობარი.</strong> ფორმულები და SI ერთეულები ერთ ადგილას, ყოველთვის ხელმისაწვდომი.</p><h3>ქართული მეცნიერება: არა მხოლოდ სახელმძღვანელოს ფურცლებზე</h3><p>ზოგი თემა სასკოლო კურსზე დიდია. აპში მათ <strong>„მნიშვნელოვანი“</strong> ნიშანი აქვთ და მთავარ გვერდზე ცალკე განყოფილებაშია.</p><p><strong>ელეფთერ ანდრონიკაშვილის ცდა (1946).</strong> ქართველმა ფიზიკოსმა უშუალოდ აჩვენა, რომ თხევადი ჰელიუმი II ორი კომპონენტისგან შედგება: ნორმალური და ზედენადი სითხისგან. ეს მეოცე საუკუნის ფიზიკის კლასიკური ექსპერიმენტია და მსოფლიოს სახელმძღვანელოებშია შესული. dwall-e-ში მოსწავლე ამ ცდას თვითონ „ჩაატარებს“: ჰელიუმში ჩაშვებული თხელი დისკების დასტა გრეხით რხევებს ასრულებს. ტემპერატურის კლებასთან ერთად რხევის პერიოდი მცირდება, რადგან ზედენადი ნაწილი დისკებს აღარ მიჰყვება. ამ პერიოდით მოსწავლე თვითონ ითვლის, ჰელიუმის რა ნაწილი გახდა ზედენადი.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pdG6HAWVpZj7btjgys_WcA.png" /><figcaption>ანდრონიკაშვილის ცდა: 1.41 K-ზე ჰელიუმის 91% ზედენადია</figcaption></figure><p><strong>გია დვალის კვანტური შავი ხვრელები.</strong> ქართველმა ფიზიკოსმა გია დვალმა და სეზარ გომესმა შავი ხვრელის კვანტური აღწერა შემოგვთავაზეს. ეს თანამედროვე თეორიული ფიზიკაა, და მოსწავლე აქ სწავლობს არა მხოლოდ თვითონ იდეას, არამედ იმასაც, რით განსხვავდება თეორიული მოდელი ექსპერიმენტით დადასტურებული ფაქტისგან.</p><p>ქართველ მოსწავლეს უნდა იცოდეს, რომ ფიზიკა „სადღაც შორს“ არ კეთდება. ის აქაც კეთდებოდა და კეთდება.</p><h3>ტექნოლოგიები: რით არის აწყობილი</h3><p>ტექნიკური მკითხველისთვის, მოკლედ, რა ავირჩიეთ და რატომ:</p><ul><li><strong>Electron 44 (დესკტოპის გარსი):</strong> ერთი კოდი Windows-ზე, macOS-ზე და Linux-ზე.</li><li><strong>Angular 21 (ინტერფეისი; standalone, signals, zoneless):</strong> ზონების გარეშე, ანიმაციის 60 კადრი წამში ცვლილებების აღმოჩენას (change detection) არ იწვევს.</li><li><strong>Three.js (2D და 3D ვიზუალიზაცია):</strong> ერთი ძრავა სიბრტყის ცდებისთვისაც და ატომის ან მზის სისტემის 3D სცენებისთვისაც.</li><li><strong>Tailwind CSS v4 (სტილი):</strong> დიზაინის ტოკენები, ღია და მუქი თემა.</li><li><strong>TypeScript (ყველგან):</strong> ფიზიკის მოდელიდან IPC-მდე ყველაფერი ტიპიზებულია.</li><li><strong>node:sqlite (მონაცემები):</strong> პარამეტრები, პროგრესი და შენახული ცდები. ნატიური მოდული არ არის, ამიტომ ყველა სისტემისთვის ხელახალი აწყობა არ სჭირდება.</li><li><strong>Vitest (ტესტები):</strong> ფიზიკის მოდელები სუფთა ფუნქციებია და წამებში მოწმდება.</li><li><strong>საკუთარი Canvas 2D კომპონენტი (გრაფიკები):</strong> პატარაა, ოფლაინ მუშაობს და 60 Hz-ზე ზედმეტ მეხსიერებას არ მოიხმარს.</li></ul><h3>მთავარი არქიტექტურული წესი: ფიზიკა არ არის დამოკიდებული ხატვაზე</h3><p>პროექტის ყველაზე მნიშვნელოვანი გადაწყვეტილება ერთ წინადადებაში ეტევა:</p><pre>PhysicsModel.step(state, dt, params)   ← სუფთა, დეტერმინისტული, ტესტირებული<br>          │<br>          ▼<br>   SimulationState (უბრალო მონაცემები)<br>          │<br>          ▼<br>SimulationView.render(state)           ← Three.js მხოლოდ ხატავს</pre><p>ყოველი თემის ფიზიკური მოდელი სუფთა TypeScript-ია: მასში არ არის DOM, Angular ან Three.js. მოდელმა არ იცის, ეკრანზე როგორ გამოიყურება. მან მხოლოდ ის იცის, როგორ გადადის სისტემა ერთი მდგომარეობიდან მეორეში. ხედი კი მხოლოდ ხატავს და ფიზიკას არასოდეს „აჩქარებს“.</p><p>ეს გვაძლევს სამ რამეს:</p><ol><li><strong>ფიზიკის ტესტირება.</strong> ყოველ მოდელს აქვს ტესტები, რომლებიც შედეგს <strong>ანალიზურ ამოხსნას</strong> ადარებს: ფორმულებს, ენერგიის და იმპულსის მუდმივობას, ზღვრულ შემთხვევებს. „მუშაობს“ ტესტად არ ითვლება. დღეს პროექტში 800-ზე მეტი ტესტია.</li><li><strong>ფიქსირებული დროის ბიჯი.</strong> მოძრაობა SimulationClock-ის ბიჯებით ითვლება და არა კადრებს შორის დროით. ამიტომ ნელ ლეპტოპზეც და სწრაფ კომპიუტერზეც ბურთი ზუსტად ერთსა და იმავე წერტილში დაეცემა.</li><li><strong>ერთი შაბლონი ყველა თემისთვის.</strong> ახალი თემა ყოველთვის ერთნაირად შედგება: მოდელი, ტესტები, ხედი, განსაზღვრება (პარამეტრები, გაზომვები, გრაფიკები, გამოწვევები, თეორია) და თარგმანები. ავტომატური შემოწმება ყოველ რეგისტრირებულ თემაში ამოწმებს, რომ არაფერი აკლია: ორივე ენის გასაღებები, დონეები, გამოწვევები და ა.შ.</li></ol><h3>გამოწვევები: რა აღმოჩნდა რთული</h3><h3>1. ფიზიკა უნდა იყოს სწორი</h3><p>სასწავლო აპში ლამაზი, მაგრამ არასწორი ანიმაცია ცუდ სახელმძღვანელოზე უარესია, რადგან მოსწავლეს ის თვალით „ახსოვს“. ამიტომ ყოველი მოდელის ფაილი იწყება მისი განტოლებებითა და დაშვებებით, და <strong>ყოველი გამარტივება მოსწავლეს ეჩვენება</strong>: „ჰაერის წინააღმდეგობა უგულებელყოფილია“, „მასშტაბი დაცული არ არის“, „ჰიგსის ველი აქ ანალოგიით არის ნაჩვენები“. ანალოგიას ანალოგია ჰქვია და ის ფაქტად არ გაასაღება.</p><h3>2. ქართული ფიზიკური ტერმინოლოგია</h3><p>თარგმანი ფიზიკაში მხოლოდ ენის საკითხი არ არის. „Momentum“ იმპულსია თუ მოძრაობის რაოდენობა? „Efficiency“ მარგი ქმედების კოეფიციენტია. ტერმინები ქართული სასკოლო სახელმძღვანელოებს უნდა ემთხვეოდეს, თორემ მოსწავლე აპსა და გაკვეთილს შორის დაიბნევა. პროექტის წესია: თუ ქართულ ტერმინში დარწმუნებული არ ხარ, ჰკითხე და ნუ გამოიცნობ.</p><h3>3. სრულად ოფლაინ და უსაფრთხოდ</h3><p>აპი არცერთ სკრიპტს, შრიფტს ან სტილს ინტერნეტიდან არ ტვირთავს. ყველაფერი შეფუთულია და მკაცრი Content Security Policy-ით იტვირთება. ინტერფეისი ოპერაციულ სისტემას მხოლოდ რამდენიმე ტიპიზებული და შემოწმებული არხით ეკონტაქტება. ბავშვებისთვის განკუთვნილ პროგრამაში ეს აუცილებელია.</p><h3>4. განახლება არასოდეს უნდა წაშალოს მოსწავლის ნამუშევარი</h3><p>მოსწავლე ვერსიებს ტოვებს: შეიძლება ოთხი თვე არ განაახლოს და მერე პირდაპირ უახლესი დააყენოს. მისი პროგრესი და შენახული ცდები მაინც უნდა დარჩეს. ამიტომ მონაცემთა ბაზის სქემა ვერსიონირებულია, მიგრაციები ჯაჭვს ქმნის ნულოვანი ვერსიიდან, და გამოქვეყნებულ მიგრაციას აღარავინ ცვლის. ძველი ფორმატის ფაილებიც კი ერთხელ შემოდის და სარეზერვოდ რჩება.</p><h3>5. ერთი კოდი, სამი ოპერაციული სისტემა</h3><p>ბიბლიოთეკები, რომლებიც ნატიურ მოდულებს იყენებს, ყოველი სისტემისა და პროცესორისთვის ცალკე უნდა აიწყოს. ეს macOS-ის უნივერსალურ ვერსიას და ავტომატურ რელიზს არღვევს. ამიტომ ბაზისთვის Node-ის ჩაშენებული node:sqlite ავირჩიეთ. ახლა package.json-ში ვერსიის შეცვლა საკმარისია: GitHub Actions თვითონ აწყობს Windows-ის, macOS-ის და Linux-ის ინსტალერებს და აქვეყნებს რელიზს.</p><h3>რა არის შემდეგი</h3><ul><li><strong>მოსწავლის პროფილები:</strong> ერთ კომპიუტერზე რამდენიმე მოსწავლე, თითოეულს თავისი პროგრესითა და დონით.</li><li><strong>მასწავლებლის კონტენტი:</strong> მასწავლებლებს საკუთარი დავალებებისა და ცდების დამატება შეეძლებათ.</li><li><strong>ახალი თემები</strong> და არსებულების გაღრმავება.</li><li><strong>ციფრული ხელმოწერა</strong>, რომ Windows-მა და macOS-მა პირველ გაშვებაზე გაფრთხილება აღარ აჩვენოს.</li></ul><h3>როგორ შეგიძლიათ დაგვეხმაროთ</h3><p>dwall-e ჯერ ბეტა ვერსიაშია (0.5.6) და ყველაზე მეტად <strong>რეალური მოსწავლეებისა და მასწავლებლების გამოხმაურება</strong> გვჭირდება.</p><ul><li><strong>მოსწავლე ხარ?</strong> ჩამოტვირთე, სცადე და გვითხარი, რა იყო გაუგებარი.</li><li><strong>ფიზიკის მასწავლებელი ხართ?</strong> სცადეთ გაკვეთილზე. გვითხარით, რომელი თემა გაკლიათ და სად არის ტერმინი არაზუსტი.</li><li><strong>დეველოპერი ხარ?</strong> არქიტექტურაზე და კოდზე ნებისმიერი შენიშვნა გვეხმარება.</li></ul><p><strong>ჩამოტვირთვა: </strong><a href="https://dwall-e.ge/">https://dwall-e.ge/</a></p><p>ფიზიკა სამყაროს აღწერის ენაა. გვინდა, რომ ქართველმა მოსწავლემ ეს ენა მშობლიურ ენაზე ისწავლოს: ცდით, შეცდომით და აღმოჩენით.</p><p><em>თეგები: Physics, Education, EdTech, Georgia, Angular, Electron, Three.js, Open Source</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0e983180ba6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Agents of S.O.L.I.D — Angular]]></title>
            <link>https://imedbekaia.medium.com/agents-of-s-o-l-i-d-angular-1fd89e2aaf7e?source=rss-b210a610c653------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fd89e2aaf7e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[shield]]></category>
            <category><![CDATA[solid-principles]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Imeda Bekaia]]></dc:creator>
            <pubDate>Fri, 13 Jun 2025 10:49:36 GMT</pubDate>
            <atom:updated>2025-06-13T10:50:34.665Z</atom:updated>
            <content:encoded><![CDATA[<h3>Agents of S.O.L.I.D — Angular</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Tf_riusFANAECViV" /></figure><p>ალბათ ყველა პროგრამული უზრუნველყოფის ინჟინრის(და არამარტო…) სამაგიდო თუ საფლეილისთო ვიდეოაა გიორგი მამალაძის ლექცია, რომელშიც ძალიან კარგადაა ნაჩვენები, თუ როგორია ფრანკეშტეინის მონსტრობა და როგორია იყო NEO (The one)(რომელსაც ჩაქუჩის სინდრომი არ ექნება). აქ ყველაფერია იმის შესახებ, რაზეც ღირს დაფიქრება და რისთვისაც ღირს უკან მიბრუნება, გადამეორება, ხელახლა გააზრება, უფრო კარგად აღქმა და საერთო ჯამში სხვადასხვა ენაში თუ framwork-ში, მისი დანერგვა. როგორც გიორგი ამბობს, ყველა ახალ framwork-ს თუ library-ს თავისი ‘hello world’ მარტივი პროექტი ეკუთვნის. ჰოდა, მოდი მივუბრუნდეთ ერთ მნიშნელოვან საკითხს — პრინციპებს.</p><p>პრინციპები საჭიროა იმისთვის, რომ შევინარცუნოთ სისუფთავე კოდში(Clean code).</p><p>-და რაში გვეხმარება?</p><ul><li>ეხმარება სხვა ინჟინერს, რომ ფეხი არაფერს გამოსდოს და არ აილეწოს.</li><li>გვეხმარება ჩვენვე, მომავალში (Back in the future)</li></ul><p>რამდენიმე მნიშნელოვანი პრინციპი:</p><ul><li><strong>KISS — Keep It Simple, Stupid</strong></li><li><strong>Boy Scout Rule</strong></li><li><strong>DRY — Don’t Repeat Yourself</strong></li><li><strong>LSP — Liskov Substitution Principle</strong></li><li><strong>ISP — Interface Segregation Principle</strong></li></ul><p>ზემოთ ჩამოთვლილი პრინციპები არის საბაზისო და თან საჭიროც, ყველა პროგრამისტისთვის. ბოლო, ორი მათგანი კი, ის აგენტები არიან, რის შესახებად სტატიის სათაური მიუთითებს. მაშ ასე, რა არის <strong>S.O.L.I.D </strong>? ვინ არიან აგენტები, რომლებიც მისთვის მუშაობენ?</p><p><strong>S.O.L.I.D</strong> — აკრონიმია, რომელიც შედგება 5 პრინციპისგან (აგენტები), ამ პრინციპების კომბინაციით კი ინჟინერს შეუძლია ადვილად განავითაროს პროგრამის კოდი.</p><p><strong>S</strong> — Single Responsibility. One class = One purpose.</p><p><strong>O</strong> — Open/ClosedOpen for extension, closed for modification.</p><p><strong>L</strong> — Liskov SubstitutionSubtypes should substitute base types.</p><p><strong>I</strong> — Interface Segregation. No fat interfaces (split large into smaller).</p><p><strong>D</strong> — Dependency Inversion. Depend on abstractions, not concretions.</p><h3><strong>S (</strong>Single Responsibility<strong>) — ერთადერთობა</strong></h3><p>კლასს, სერვისს ან კომპონენტს ცვლილების მხოლოდ ერთი მიზეზი უნდა ჰქონდეს. ერთი კლასი = ერთი პასუხისმგებლობა (შესასრულებელი დავალება). გააკეთე ერთი, გააკეთე კარგად! ყველაფერშიკობა არაფერში ვარგა…</p><p>❌ არასწორია</p><pre>@Injectable({ providedIn: &#39;root&#39; })<br>export class AuthService {<br>  login() { /* logic */ }<br>  logout() { /* logic */ }<br>  isLoggedIn() { /* logic */ }<br><br>  saveToLocalStorage() { /* unrelated */ }<br>  trackAnalytics() { /* unrelated */ }<br>  navigateToDashboard() { /* unrelated */ }<br>}</pre><p>✅ სწორია</p><pre>@Injectable({ providedIn: &#39;root&#39; })<br>export class AuthService {<br>  login() { /* logic */ }<br>  logout() { /* logic */ }<br>  isLoggedIn() { /* logic */ }<br>}</pre><p>Angular-ის შემთვევაში, ცოტა სხვაგვარად გვაქვს საქმე. ზოგადად, ერთ კლასს უნდა ჰქონდეს ერთი შესასრულებელი დავალება, როგორც ზემოთ აღვნიშნეთ, თუმცა Angular-ში ცოტა სხვაგვარადა. წარმოვიდგინოთ სერვისი(იგივე კლასი), რომელსაც ვქმნით გაზიარებადი ლოგიკისთვის. სერვისი, რომ მხოლოდ ერთადერთი მეთოდისთვის შევქმნათ გამოვა უაზრობა და მეტი არაფერი. ამ შემთხვევაში ოდნავ სახეცვლილი პრინციპი მოქმედებს — ერთი კლასი = დაახლოებული ლოგიკები.</p><h3>O (Open/Closed)</h3><p>ობიექტები უნდა იყოს ღია გაფართოებისთვის, მაგრამ დახურული ცვლილებების მიმართ. სხვა სიტყვებით რომ ვთქვათ, კლასი ადვილად უნდა ფართოვდებოდეს, მაგრამ ცვილებების გარეშე.</p><p>❌ არასწორია</p><pre>@Injectable({ providedIn: &#39;root&#39; })<br>export class ReportService {<br>  generateReport(type: &#39;pdf&#39; | &#39;excel&#39;, data: any) {<br>    if (type === &#39;pdf&#39;) {<br>      // PDF generation logic<br>    } else if (type === &#39;excel&#39;) {<br>      // Excel generation logic<br>    }<br>  }<br>}</pre><p>✅სწორია</p><pre>@Injectable({ providedIn: &#39;root&#39; })<br>export class ReportService {<br>  generatePdf(data: any) {<br>    // generate PDF logic<br>    console.log(&#39;Generating PDF...&#39;);<br>  }<br><br>  generateExcel(data: any) {<br>    // generate Excel logic<br>    console.log(&#39;Generating Excel...&#39;);<br>  }<br><br>  // Future extension<br>  generateCsv(data: any) {<br>    // new logic here — no existing code touched<br>    console.log(&#39;Generating CSV...&#39;);<br>  }<br>}</pre><p>როგორც წინა, ამ შემთხვევაშიც Angular-ში ოდნავ სახეცვლილად მოქმედებს ეს პრინციპი. არ შეიძლება ერთმა მეთოდმა, დროის განმავლობაში განიცადოს ცვლილება, ეს პრინჩიპი გადაჟაჭვულია პირველ პრინციპთან.</p><p>❌არასწორია</p><pre>class Discount {<br>  getDiscount(type: string): number {<br>    if (type === &#39;regular&#39;) {<br>      return 0;<br>    } else if (type === &#39;vip&#39;) {<br>      return 10;<br>    } else if (type === &#39;premium&#39;) {<br>      return 20;<br>    }<br>    return 0;<br>  }<br>}<br><br>const discount = new Discount();<br>console.log(discount.getDiscount(&#39;vip&#39;)); // 10</pre><p>✅სწორია</p><pre>interface DiscountStrategy {<br>  getDiscount(): number;<br>}<br><br>class RegularCustomer implements DiscountStrategy {<br>  getDiscount(): number {<br>    return 0;<br>  }<br>}<br><br>class VIPCustomer implements DiscountStrategy {<br>  getDiscount(): number {<br>    return 10;<br>  }<br>}<br><br>class PremiumCustomer implements DiscountStrategy {<br>  getDiscount(): number {<br>    return 20;<br>  }<br>}<br><br>// consumer class doesn&#39;t need to change<br>class Discount {<br>  constructor(private strategy: DiscountStrategy) {}<br><br>  calculate(): number {<br>    return this.strategy.getDiscount();<br>  }<br>}<br><br>const vip = new Discount(new VIPCustomer());<br>console.log(vip.calculate()); // 10<br><br>const premium = new Discount(new PremiumCustomer());<br>console.log(premium.calculate()); // 20</pre><h3>L (Liskov Substitution)</h3><p>წარმოებული კლასის ობიექტები უნდა იყოს ჩანაცვლებადი მათი საბაზო კლასის ობიექტებით, სისწორის შეცვლის გარეშე. ყველა ქვე-კლასი უნდა იქცეოდეს ისე როგორც საბაზისო.</p><p>❌არასწორია</p><pre>abstract class AuthService {<br>  abstract authenticate(): void;<br>}<br><br>@Injectable({ providedIn: &#39;root&#39; })<br>class EmailAuthService extends AuthService {<br>  authenticate() {<br>    console.log(&#39;Authenticating with email...&#39;);<br>  }<br>}<br><br>@Injectable({ providedIn: &#39;root&#39; })<br>class GoogleAuthService extends AuthService {<br>  authenticate() {<br>    console.log(&#39;Authenticating with Google...&#39;);<br>  }<br>}<br><br>@Injectable({ providedIn: &#39;root&#39; })<br>class MockAuthService extends AuthService {<br>  authenticate() {<br>    throw new Error(&#39;MockAuthService should not be used in production&#39;);<br>  }<br>}<br><br>@Component({ /* ... */ })<br>export class LoginComponent {<br>  constructor(private authService: AuthService) {}<br><br>  login() {<br>    this.authService.authenticate(); // ❌ Might throw unexpectedly<br>  }<br>}</pre><p>✅სწორია</p><pre>interface IAuthStrategy {<br>  authenticate(): void;<br>}<br><br>@Injectable({ providedIn: &#39;root&#39; })<br>class EmailAuthService implements IAuthStrategy {<br>  authenticate() {<br>    console.log(&#39;Email auth...&#39;);<br>  }<br>}<br><br>@Injectable({ providedIn: &#39;root&#39; })<br>class GoogleAuthService implements IAuthStrategy {<br>  authenticate() {<br>    console.log(&#39;Google auth...&#39;);<br>  }<br>}<br><br>@Injectable({ providedIn: &#39;root&#39; })<br>class MockAuthService implements IAuthStrategy {<br>  authenticate() {<br>    console.log(&#39;Mock auth... test passed.&#39;);<br>  }<br>}<br><br><br><br>providers: [{ provide: &#39;AUTH&#39;, useClass: EmailAuthService }]<br><br><br><br>@Component({ /* ... */ })<br>export class LoginComponent {<br>  constructor(@Inject(&#39;AUTH&#39;) private authService: IAuthStrategy) {}<br><br>  login() {<br>    this.authService.authenticate(); // ✅ Works consistently<br>  }<br>}</pre><p>ამ შემთხვევაში გვაქვს IAuthStrategy ინტერფეისი, რომელიც არის base (მშობელი) კლასი, რომლითაც ხდება ქვე-კლასების გაფართოება. მიუხედავად იმისა, რომ ზემოთ ჩამოთვლილი კლასებიდან ყველა გაფართოებულია და აქვს შესაძლებლობა გამოიყენოს .authenticate() მეთოდი, ერთ შემთხვევაში მეთოდი არ იქცევა ისე, რომ შეინარჩუნოს სისწორე - ანუ ვიღებთ შედეგს, რომელსაც არ ველოდებით და რომელიც შეაჩერებს პროცესს. სწორი მიდგომა, ამ შემთხვევაში არის ის, რომ დავარეგისტრიროთ ახალი პროვაიდერი შესაბამისი ინჯექშენ ტოკენით (Injection Token) და დავაინჯექთოთ შესაბამისი დეფენდენსი ისე, რომ არ შეგვიქმნას რაიმე პრობლემა, თავიდან ავიცილოთ მოულოდნელობა.</p><pre>TestBed.configureTestingModule({<br>  providers: [{ provide: AuthService, useClass: MockAuthService }]<br>});</pre><p>მაგალითად, როცა ტესტირებაში ვეცდებით mock სერვის გამოყენებას აპლიკაცია დაიქრაშებოდა წამიერად. პროვაიდერის რეგიტრაციით Angular-ს ვეუბნებით, რომ ‘მენდე, ვიცი რასაც ვაკეთებ. აიღე ყველაფერი რა საჭიროა’.</p><p>✅სწორია</p><pre>abstract class BaseGreeting {<br>  abstract greeting(): string;<br>}<br><br>class RussianGreeting extends BaseGreeting {<br>  greeting() {<br>    return &#39;Zdravstvuyte!&#39;;<br>  }<br>}<br><br>class GeorgianGreeting extends BaseGreeting {<br>  greeting() {<br>    return &#39;Gamardjoba!&#39;;<br>  }<br>}<br><br>function sayHello(greeter: BaseGreeting) {<br>  console.log(greeter.greeting());<br>}<br><br>sayHello(new RussianGreeting());  // ✅ No problem<br>sayHello(new GeorgianGreeting()); // ✅ No problem</pre><p>❌არასწორია</p><pre>class LathinGreeting extends BaseGreeting {<br>  greeting() {<br>    throw new Error(&quot;I am dead language&quot;);<br>  }<br>}</pre><p>არასწორია იმიტომ, რომ ეწინააღდეგება ლისკოვის პრინციპს. მიუხედავად იმისა, რომ .greeting() მეთოდს იყენებს, გამოყენება არ უნდა არღვევდეს ან წყვეტდეს აპლიკაციის პროცესს.</p><h3>I (Interface Segregation)</h3><p>არცერთ კლასს არ უნდა ჰქონდეს ვალდებულება დააიპლმენეტიროს მეთოდი, რომელიც არ სჭირდება. არცერთი კლასი არ უნდა იყოს დამოკიდებული მისთვის არასასურველ მეთოდზე.</p><p>მაგალითისთვის შევქმნათ ქასთომ Lifecycle ინტერფეისი კომპონენტისთვის. ამ შემთხვევაში გამოდის, რომ კლასს ვაიძლებს ერთბაშათ ჰქონდეს ყველა მეთოდი. არადა ჩვენი ვალდებულებაა, ყველაფერი იყოს არჩევადი.</p><p>❌ არასწორია</p><pre>interface ComponentLifecycle {<br>  ngOnInit(): void;<br>  ngOnDestroy(): void;<br>  ngAfterViewInit(): void;<br>  ngAfterViewChecked(): void;<br>  ngDoCheck(): void;<br>}<br><br>@Component({...})<br>export class HomeComponent implements ComponentLifecycle {<br>  ngOnInit() {<br>    console.log(&#39;HomeComponent initialized&#39;);<br>  }<br><br>  ngOnDestroy() {}<br>  ngAfterViewInit() {}<br>  ngAfterViewChecked() {}<br>  ngDoCheck() {}<br>}</pre><p>✅სწორია</p><pre><br><br>export interface OnInit {<br>  ngOnInit(): void;<br>}<br><br>export interface OnDestroy {<br>  ngOnDestroy(): void;<br>}<br><br>@Component({...})<br>export class HomeComponent implements OnInit {<br>  ngOnInit() {<br>    console.log(&#39;Only init logic, nothing more!&#39;);<br>  }<br>}</pre><p>❌ არასწორია</p><pre>interface Worker {<br>  work(): void;<br>  eat(): void;<br>}<br><br>class Robot implements Worker {<br>  work() {<br>    console.log(&quot;Robot working...&quot;);<br>  }<br><br>  eat() {<br>    // ❌ Robots don&#39;t eat<br>    throw new Error(&quot;Robot doesn&#39;t eat&quot;);<br>  }<br>}</pre><p>✅სწორია</p><pre>interface Workable {<br>  work(): void;<br>}<br><br>interface Eatable {<br>  eat(): void;<br>}<br><br>class Human implements Workable, Eatable {<br>  work() {<br>    console.log(&quot;Human working...&quot;);<br>  }<br><br>  eat() {<br>    console.log(&quot;Human eating...&quot;);<br>  }<br>}<br><br>class Robot implements Workable {<br>  work() {<br>    console.log(&quot;Robot working...&quot;);<br>  }<br>}</pre><h3>D (Dependency Inversion)</h3><p>დამოკიდებულებები უნდა იყოს აბსტრაქციებზე და არა კონკრეტიკებზე. მაგალითად, მაღალი დონის მოდულები არ უნდა იყოს დამოკიდებული დაბალი დონის მოდულებზე. ორივე უნდა იყოს დამოკიდებული აბსტრაქციებზე.</p><p>❌ არასწორია</p><pre>@Injectable({ providedIn: &#39;root&#39; })<br>export class AuthService {<br>  login(email: string, password: string) {<br>    return this.http.post(&#39;/api/login&#39;, { email, password });<br>  }<br><br>  constructor(private http: HttpClient) {}<br>}<br><br>@Component({ ... })<br>export class LoginComponent {<br>  constructor(private authService: AuthService) {}<br><br>  onLogin() {<br>    this.authService.login(&#39;user@mail.com&#39;, &#39;pass&#39;).subscribe();<br>  }<br>}</pre><p>LoginComponent პირდაპირ დამოკიდებულია დაბალი დონის AuthService-ზე.</p><p>თუ მოგვიანებით გსურთ mock-ის გაკეთება, Firebase-ზე გადასვლა ან HTTP სერვისის შეცვლა, მოგვწიწევს ამ კომპონენტის რეფაქტორი.</p><p>სწორია</p><pre>export interface IAuthService {<br>  login(email: string, password: string): Observable&lt;any&gt;;<br>}<br><br>@Injectable({ providedIn: &#39;root&#39; })<br>export class HttpAuthService implements IAuthService {<br>  constructor(private http: HttpClient) {}<br><br>  login(email: string, password: string): Observable&lt;any&gt; {<br>    return this.http.post(&#39;/api/login&#39;, { email, password });<br>  }<br>}<br><br><br><br><br>@Component({ ... })<br>export class LoginComponent {<br>  constructor(@Inject(&#39;AUTH&#39;) private authService: IAuthService) {}<br><br>  onLogin() {<br>    this.authService.login(&#39;user@mail.com&#39;, &#39;pass&#39;).subscribe();<br>  }<br>}<br><br><br><br>@NgModule({<br>  providers: [<br>    { provide: &#39;AUTH&#39;, useClass: HttpAuthService }<br>  ]<br>})<br>export class AppModule {}</pre><p>ახლა უკვე, LoginComponent დამოკიდებულია IAuthService-ზე და არა კონკრეტულ იმპლემენტაციაზე.</p><p>თქვენ შეგიძლიათ HttpAuthService-ის FirebaseAuthService-ზე ან MockAuthService-ზე გადართვა კომპონენტზე შეხების გარეშე.</p><h3>შეჯამება</h3><p>სტატიაში განხილულია პრინციპების გავლენა Angular-ის ფრეიმვორკსა და ტაიპსკრიპტზე, რომლებიც ერთმანეთტან არიან გადაჯაჭვულები. როცა პატარა პროექტთან გავქვს საქმე, SOLID პრინციპი შეგვიძლია გამოვტოვოთ. თუმცა, დიდ პროექტებში რაღაც დონეზე სავალდებულოცაა. ან მაგალითა, რაიმე public ბიბლიოტეკას თუ ვქმნით, მნიშვნელოვანია SOLID პრინციპის დაცვა. ჩვენი გადასაწყვეტია ვითანამშრომლებთ თუ არა, S.O.L.I.D ის აგენტებთან, ყველაფერი მაინც ჩვენს სასარგებლოდ იმეტყველებს.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fd89e2aaf7e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RxJs — Obseriverable]]></title>
            <link>https://imedbekaia.medium.com/rxjs-obseriverable-0cf3cecba7c2?source=rss-b210a610c653------2</link>
            <guid isPermaLink="false">https://medium.com/p/0cf3cecba7c2</guid>
            <category><![CDATA[rxjs]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[observables]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Imeda Bekaia]]></dc:creator>
            <pubDate>Wed, 04 Jun 2025 09:10:14 GMT</pubDate>
            <atom:updated>2025-06-04T09:11:23.505Z</atom:updated>
            <content:encoded><![CDATA[<h3>RxJs — Obseriverable</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*3qhPjZBRsSGmpjdA.jpg" /><figcaption><a href="https://www.wikiart.org/en/niko-pirosmani/a-young-fisherman">A young fisherman — Niko Pirosmani</a></figcaption></figure><p>Obseriverable ? Obser… who? Obser… what? River?!<br><strong> </strong>What even is that ?</p><p>When learning <strong>RxJS</strong> or reactive programming in general, it’s easy to get lost in abstract definitions like:</p><blockquote><em>“An Observable is a stream of asynchronous events you can observe and react to over time.”</em></blockquote><p>Okay, but what does that really mean?<br>Let’s break it down — with a real-life analogy.</p><h3>Imagine a River…</h3><p>Visualize a <strong>river</strong> flowing from left to right. This river is not just water — it’s carrying something: <strong>fish</strong>.</p><p>Each <strong>fish</strong> represents a <strong>data value</strong> emitted by the observable. These values come over time — just like fish swimming downstream. Some arrive early, some come later, and some might never show up. That’s the nature of asynchronous data.</p><h3>You Are the Fisherman</h3><p>Now, picture yourself standing beside the river, holding a fishing rod. You want to catch these fish, right?</p><p>In the RxJS world, <strong>casting your fishing rod</strong> is the equivalent of <strong>subscribing</strong> to an Observable.</p><p>Until you throw your line in (subscribe), you won’t catch anything. The river keeps flowing, but you’re not involved — yet.</p><p>Once you subscribe:</p><ul><li>You start <strong>receiving data</strong>.</li><li>Every time a fish swims by (the Observable emits a value), you <strong>catch</strong> it.</li><li>You then <strong>decide what to do</strong> — keep it, inspect it, process it.</li></ul><p>This is your next() handler — where you react to each new emitted value.</p><h3>The Box Beside You</h3><p>As you fish, you need a place to store the catches. This could be your <strong>subscription handler logic</strong> — where you manage or store the data.</p><p>Maybe you keep all the fish (like pushing values into an array), or maybe you examine each one and throw it back (like filtering or transforming values with operators).</p><h3>The River Ends — or Gets Rough</h3><p>Every river has an end. In RxJS, when the observable is done emitting values, it <strong>completes</strong>.</p><blockquote><em>This is like the river drying up — no more fish. You’re done fishing.</em></blockquote><p>But sometimes, the river doesn’t end peacefully.</p><p>Imagine a <strong>log</strong> or <strong>trash</strong> suddenly hitting you. That’s an <strong>error</strong> — an unexpected event. When that happens, fishing is over, whether you like it or not. You’re forced to stop — just like an observable that throws an error.</p><h3>Summary</h3><p>Thinking of Observables as rivers, and yourself as a fisherman, makes reactive programming feel more natural and intuitive.</p><ul><li>The <strong>Observable</strong> is the river.</li><li>The <strong>emitted values</strong> are the fish.</li><li><strong>Subscription</strong> is casting your rod.</li><li>The <strong>handlers</strong> (next, error, complete) are what you do with each event.</li></ul><p>This metaphor not only makes understanding Observables easier — it makes them memorable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0cf3cecba7c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Event Loop (js) ანუ როგორია თამადობა]]></title>
            <link>https://imedbekaia.medium.com/event-loop-js-%E1%83%90%E1%83%9C%E1%83%A3-%E1%83%A0%E1%83%9D%E1%83%92%E1%83%9D%E1%83%A0%E1%83%98%E1%83%90-%E1%83%97%E1%83%90%E1%83%9B%E1%83%90%E1%83%93%E1%83%9D%E1%83%91%E1%83%90-b510681f605e?source=rss-b210a610c653------2</link>
            <guid isPermaLink="false">https://medium.com/p/b510681f605e</guid>
            <category><![CDATA[event-loop-in-js]]></category>
            <category><![CDATA[თამადა]]></category>
            <category><![CDATA[tamada]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[event-loop]]></category>
            <dc:creator><![CDATA[Imeda Bekaia]]></dc:creator>
            <pubDate>Mon, 24 Feb 2025 20:44:26 GMT</pubDate>
            <atom:updated>2025-02-28T10:13:54.285Z</atom:updated>
            <content:encoded><![CDATA[<p>შენ ალბათ აქედანვე არ მოგწონს შესავალი, რომელიც უფრო débil-ურია, ვიდრე რამენაირად უადგილო თუ გაუგებარი(but, still…).</p><p>90-იანებში(იქამდეც)(ალბათ ახლაც), როცა ყველა სახის მოვლენა(<strong>event</strong>) — ქორწილი, დღეობა, ქელეხი, ნათლობა და ა.შ. ერთი გა<strong>LOO</strong>მ<strong>P</strong>ული კარვის(<strong>სეფის</strong>) ქვეშ იმართებოდა, ყოველთვის საჭირო იყო წინამძღოლი. ადამიანი, რომელიც წარმართავდა პროცეს და მიჰყვებოდა დადგენილ წესებს.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5TXTJlHP9GCW39H8.png" /></figure><p><strong>Event Loop</strong> არის მნიშნელოვანი კონცეფცია/მექანიზმი ჯავასკრიპტში, რომელიც ასინქრონულ პროგრამირებას(asynchronous programming) საშუალებას აძლევს გაუმკლავდეს ამოცანებს ეფექტურად (ამ ამოცანების პრიორიტეტიზაციით). თავიდანვე უნდა აღინიშნოს, რომ ჯავასკრიპტი არის <strong>ერთ ნაკადიანი</strong>(single-threaded), რაც მოიაზრებს ერთდროულად, მხოლოდ და მხოლოდ ერთი ამოცანის შესრულებას. მიუხედავად იმისა, რომ ჯავასკრიპტს შეუძლია ასინქრონული ოპერაციების შესრულება, იგი რაღაცნაირად ინარჩუნებს სინქრონულობას, ანუ ამუშავებს კოდს თანმიმდევრობით, სტრიქონ-სტრიქონ. ჰოდაააა, რადგანაც, ერთ ნაკადიანობა საშუალებას არ გვაძლევს ბევრი ამოცანის პარალელურად დამუშავების, ამიტომ ვიყენებთ სხვადახვა მექანიზმს: <strong>Callbacks, Promises, Async/Await, Event Loop;</strong></p><blockquote><strong>Event Loop = თამადა (Toastmaster)</strong></blockquote><p>მთელს ჩვენს პროცესიებს მხოლოდ ერთი წინამძღოლი(გამტარი, ნაკადის მარეგულირებელი) ჰყავს — თამადა. მანდ უნდა მოახერხოს და ეფექტურად აკონტროლოს ყველა პროცესი, სადღეგრძელო, შემოსწრებული, ადრე წასული, მუსიკალური გაფორმება და ა.შ.</p><p><strong>Event Loop</strong> შედგება ორი ძირითადი ნაწილისაგან:</p><ol><li><em>დასტა</em>(<strong>the call stack</strong>)(სინქრონული ამოცანები მიდის <strong>LIFO</strong> მოდელით ანუ ბოლოს შემოსული ამოცანა სრულდება პირველ რიგში). მაგალითად, როცა ფუნქცია გამოძახება, მექანიზმი მას დასტაში აგდებს და როცა შესრულდება ლოგილა, ამოიშლება დასტიდან დაუყოვნებლივ.</li><li><em>შეტყობინებების რიგი</em>(<strong>the message queue</strong>)(რიგი ეყრდნობა <strong>FIFO</strong> მოდელს, პირველად შემოსული ამოცანა, სრულდება დაუყოვნებლივ); შეტყობინებების რიგი იყოფა თავისთავად ორ ნაწილად: <em>მაკროამოცანების რიგი</em>(<strong>the task queue</strong>)(setTimeout, fetch , setInterval , DOM events) რომელიც დაბალი პრიორიტეტის მქონეა და <em>მიკროამიცანების რიგი</em>(<strong>microtask queue</strong>)(Promises and async/await) რომელიც, შესაბამისად მაღალი პრიორიტეტიზაციით სარგებლობს.</li></ol><h3>The Call Stack</h3><pre>// Call Stack<br><br><br>function first() {<br>  console.log(&quot;First function&quot;);<br>}<br><br>function second() {<br>  first();<br>  console.log(&quot;Second function&quot;);<br>}<br><br>second();</pre><ul><li>second() გამოძახება → ვარდება დასტაში.</li><li>first() ფუნქცია გამოიძახება second() -ის შიგნით → და ვარდება დასტაში.</li><li>console.log(&quot;First function&quot;) სრულდება → დაილოგება &quot;F</li><li>irst function&quot;, შემდეგ კი first() პროცესი ამოშლება დასტიდან.</li><li>console.log(&quot;Second function&quot;) სრულდება → დაილოგება &quot;Second function&quot;, შემდეგ კიsecond() -ც ამოიშლება დასტიდან და დასტა გათავისუფლდება სრულად.</li></ul><h3>Macrotask Queue (Task Queue)</h3><pre>// Macrotask Queue<br><br>console.log(&quot;Start&quot;);<br><br>setTimeout(() =&gt; {<br>  console.log(&quot;Macrotask - setTimeout&quot;);<br>}, 0);<br><br>console.log(&quot;End&quot;);<br><br><br>// Start<br>// End<br>// Macrotask - setTimeout</pre><ul><li>console.log(&quot;Start&quot;) დაილოგება დაუყოვნებლივ.</li><li>setTimeout(..., 0) ჩავარდება მაკროამოცანების რიგში.</li><li>console.log(&quot;End&quot;) შემდეგ გაეშვება მეორე ლოგირება.</li><li>და როცა კი Event Loop ნახავს, რომ დასტა ცარიელია, მაკროამოცანას გაუშვებს და დალოგასვ &quot;Macrotask - setTimeout&quot;.</li></ul><h3>Microtask Queue (Promise Queue)</h3><pre>// Microtask Queue<br><br>console.log(&quot;Start&quot;);<br><br>setTimeout(() =&gt; {<br>  console.log(&quot;Macrotask - setTimeout&quot;);<br>}, 0);<br><br>Promise.resolve().then(() =&gt; {<br>  console.log(&quot;Microtask - Promise&quot;);<br>});<br><br>console.log(&quot;End&quot;);<br><br>// Start<br>// End<br>// Microtask - Promise<br>// Macrotask - setTimeout</pre><ul><li>&quot;Start&quot; დაილოგება დაუყოვნებლივ.</li><li>setTimeout(..., 0) ჩავარდება მაკროამოცანების რიგში.</li><li>Promise.resolve().then(...) ჩავარდება მიკროამოცანების რიგში.</li><li>&quot;End&quot; დაილოგება დაყოვნებლივ.</li><li>მიკროამოცანებს რადგანაც პრიორიტეტიზაციის (მოჩვენებითი)ინდექსი მეტი აქვთ, იგი შესრულდება დაუყოვნებლივ, მაკროამოცანებამდე და დაილოგება → &quot;Microtask - Promise&quot;.</li><li>ბოლოს კი, რადგან დასტა ცარიელია და არც რამე მიკროამოცანა არ არის დარჩენილი, შერსულდება ბოლო მაკროამოცანა და დალოგავს → &quot;Macrotask - setTimeout&quot;.</li></ul><h3>გულბაათ ჭავჭავაძე</h3><p>ეს ჩვენი გულბაათიც იგივე პროცესს გადის ჭინჭილის გადაცლამდე. მისი დასტა, ერთი გრძელი სუფრაა, რომელსაც ბოლო არ უჩანს. ყოველი ახალი სადღეგრძელო ახალი პროცესიაა, განმეორებადი. ეს ასინქრონული პროცესები კი შემოსწრებული და ნაადრევად წასასვლელად გამზადებული თანამეინახენი არიან. პრიორიტეტი შემოსწრებულს ენიჭება, რადგან ის უნდა დაეწიოს სუფრას და მის ფერხულში ჩადგეს. ნაადრევად წამსვლელი მოიცდის. მისი ჯერიც მოვა და როცა, როცა ბოლოს ადღეგრძელებნ და გაუყენებენ ისე სახლის გზას. წესი — წესია, პირველი ღმერთისას ამბობენ დაუყოვნებლივ, მეორეს მშვიდობას. დაგვიანებული სტუმარი შემოისწრებს ამ დროს, და იას უცებ მოითავებენ, ორივეს ერთად შეასემევენ, დააწევენ სუფრას.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fWXuuXkmW1PdLDmRJ499NA.png" /><figcaption>Georgian Event Loop</figcaption></figure><p>ასე და ამგვარად — შენ თუ აქამდე გაუძელი, შენ გაგიმარჯოს Event Loop-ის თამადობით. მის გარეშე ჯავასკრიპტი, უპატარძ… უთამადო ქორწილს დაემსგავსებოდა.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b510681f605e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Zone pollution in Angular]]></title>
            <link>https://imedbekaia.medium.com/zone-pollution-in-angular-141b92a59b33?source=rss-b210a610c653------2</link>
            <guid isPermaLink="false">https://medium.com/p/141b92a59b33</guid>
            <dc:creator><![CDATA[Imeda Bekaia]]></dc:creator>
            <pubDate>Thu, 28 Nov 2024 13:05:02 GMT</pubDate>
            <atom:updated>2024-12-09T10:43:43.900Z</atom:updated>
            <content:encoded><![CDATA[<p>Avoiding zone pollution in Angular involves ensuring that Angular’s <strong>zone.js</strong> does not intercept or wrap unnecessary asynchronous operations or events, leading to degraded performance or unintended side effects. Let’s dive deep into this topic:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mVnPwKCyeq_Gk_Op.png" /></figure><h3>1. What is Zone Pollution?</h3><p>Zone pollution occurs when <strong>zone.js</strong> patches and tracks asynchronous operations or event listeners that are irrelevant or too broad for Angular’s change detection. This results in:</p><ul><li>Excessive change detection cycles.</li><li>Unintended bugs, particularly in high-performance scenarios or apps with real-time features.</li></ul><h3>2. Common Causes of Zone Pollution</h3><p>In some cases scheduled tasks or microstask don’t make any changes in the data model, which makes running change detection unnecessary. Common examples are:</p><ul><li>Patching global APIs (e.g., setTimeout, setInterval, or Promise).</li><li>Event listeners on window, document, or other DOM nodes.</li><li>Third-party libraries that rely on their own async mechanisms, like RxJS, or custom polling systems.</li><li>Web APIs like IntersectionObserver, MutationObserver, or WebSockets being unnecessarily tracked.</li></ul><h3>3. Strategies to Avoid Zone Pollution</h3><h4>3.1. Use runOutsideAngular</h4><p>The NgZone.runOutsideAngular() method prevents Angular from tracking specific async operations. This is useful for performance-heavy tasks that don’t affect the DOM.</p><pre>import { Component, NgZone } from &#39;@angular/core&#39;;<br><br>@Component({<br>  selector: &#39;app-root&#39;,<br>  template: &#39;&lt;div (mousemove)=&quot;onMouseMove($event)&quot;&gt;Move the mouse&lt;/div&gt;&#39;,<br>})<br>export class AppComponent {<br>  constructor(private ngZone: NgZone) {}<br><br>  onMouseMove(event: MouseEvent): void {<br>    this.ngZone.runOutsideAngular(() =&gt; {<br>      // Perform non-DOM operations like logging or heavy computation<br>      console.log(event.clientX, event.clientY);<br>    });<br>  }<br>}</pre><h4>3.2. Limit Global Event Listeners</h4><p>Avoid adding broad listeners to document or window. If you must, manage them outside of Angular’s zone.</p><pre>ngOnInit(): void {<br>  this.ngZone.runOutsideAngular(() =&gt; {<br>    window.addEventListener(&#39;scroll&#39;, this.onScroll);<br>  });<br>}<br><br>ngOnDestroy(): void {<br>  window.removeEventListener(&#39;scroll&#39;, this.onScroll);<br>}<br><br>onScroll(): void {<br>  // Scroll logic here<br>}</pre><h4>3.3. Optimize Observable Subscriptions</h4><p>Use RxJS operators like takeUntil or first to manage subscriptions efficiently. Avoid long-lived subscriptions that Angular continues to monitor.</p><pre>ngOnInit(): void {<br>  this.ngZone.runOutsideAngular(() =&gt; {<br>    this.observable$.pipe(takeUntil(this.destroy$)).subscribe(data =&gt; {<br>      console.log(data);<br>    });<br>  });<br>}</pre><h3>Updating the View from Outside Angular</h3><p>When you perform operations outside Angular’s zone using runOutsideAngular, Angular won&#39;t automatically detect the changes. To update the view manually, you can use:</p><ul><li><strong>ChangeDetectorRef</strong>: To trigger a single component&#39;s change detection.</li><li><strong>NgZone.run</strong>: To re-enter Angular&#39;s zone and let Angular handle change detection.</li></ul><pre>import { Component, NgZone, ChangeDetectorRef } from &#39;@angular/core&#39;;<br><br>@Component({<br>  selector: &#39;app-root&#39;,<br>  template: `<br>    &lt;p&gt;Counter: {{ counter }}&lt;/p&gt;<br>    &lt;button (click)=&quot;startCounting()&quot;&gt;Start Counting&lt;/button&gt;<br>  `,<br>})<br>export class AppComponent {<br>  counter = 0;<br><br>  constructor(private ngZone: NgZone, private cdr: ChangeDetectorRef) {}<br><br>  startCounting(): void {<br>    this.ngZone.runOutsideAngular(() =&gt; {<br>      setInterval(() =&gt; {<br>        this.counter++;<br>        // Manually trigger change detection<br>        this.cdr.detectChanges();<br>      }, 1000);<br>    });<br>  }<br>}</pre><p>If you need to dispatch events to parent components and execute specific view update logic, you should consider re-entering the Angular zone to instruct the framework to run change detection or run change detection manually:</p><pre>import { Component, NgZone, OnInit, output } from &#39;@angular/core&#39;;<br>import * as Plotly from &#39;plotly.js-dist-min&#39;;<br>@Component(...)<br>class AppComponent implements OnInit {<br>  plotlyClick = output&lt;Plotly.PlotMouseEvent&gt;();<br>  constructor(private ngZone: NgZone) {}<br>  ngOnInit() {<br>    this.ngZone.runOutsideAngular(() =&gt; {<br>      this.createPlotly();<br>    });<br>  }<br>  private async createPlotly() {<br>    const plotly = await Plotly.newPlot(&#39;chart&#39;, data);<br>    plotly.on(&#39;plotly_click&#39;, (event: Plotly.PlotMouseEvent) =&gt; {<br>      this.ngZone.run(() =&gt; {<br>        this.plotlyClick.emit(event);<br>      });<br>    });<br>  }<br>}</pre><p>With the release of Angular 19, the framework introduces experimental support for <strong>zoneless change detection</strong>, allowing developers to build applications without relying on <strong>Zone.js</strong>. Without <strong>Zone.js</strong>, Angular won’t automatically detect changes. Use mechanisms like <strong>Signals</strong>, ChangeDetectorRef, or the AsyncPipe to inform Angular when to run change detection.</p><h3>Best Practices Summary</h3><ul><li><strong>Isolate async operations</strong> with runOutsideAngular.</li><li><strong>Manually trigger updates</strong> using ChangeDetectorRef or re-enter the Angular zone.</li><li>Use <strong>OnPush</strong> change detection to limit the impact on the component tree.</li><li>Avoid over-listening to events or unnecessarily updating views.</li><li>Leverage <strong>zone-less setups</strong> or reactive state libraries for greater control.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=141b92a59b33" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Some useful tips/tricks (JavaScript From Zero to Hero)]]></title>
            <link>https://imedbekaia.medium.com/some-useful-tips-tricks-javascript-from-zero-to-hero-430cdd519935?source=rss-b210a610c653------2</link>
            <guid isPermaLink="false">https://medium.com/p/430cdd519935</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[tricks]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Imeda Bekaia]]></dc:creator>
            <pubDate>Mon, 04 Nov 2024 16:46:01 GMT</pubDate>
            <atom:updated>2024-11-08T11:24:52.820Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GqhcwIHcnenkc70CMjCudw.png" /></figure><h3>1. Find the object with greatest “amount” property value in an array of objects</h3><p>To find the object in the given array where the product of quantity and price is maximized, you can iterate through the array, calculate the total amount for each object, and keep track of the maximum value found. Here&#39;s a simple function to accomplish this:</p><pre>//With reduce() method<br>const items = [ <br>    {quantity: 1, price: 2, name: &#39;pRoDuCt 1&#39;},<br>    {quantity: 1, price: 5, name: &#39;product_2&#39;},<br>    {quantity: 2, price: 0.7, name: &#39;Product&#39;}<br>];<br><br>function getMaxAmountItemWithReduce(arr) {<br>    return arr.reduce((maxItem, currentItem) =&gt; {<br>        const currentAmount = currentItem.quantity * currentItem.price;<br>        const maxAmount = maxItem.quantity * maxItem.price;<br><br>        return {...(currentAmount &gt; maxAmount ? currentItem : maxItem), amount: maxAmount};<br>    });<br>}<br><br>const result = getMaxAmountItemWithReduce(items);<br>console.log(result); // {quantity: 1, price: 5, name: &#39;product_2&#39;, amount: 5}</pre><pre>//Without reduce() method<br><br>function getMaxAmountItem(arr) {<br>  let itemWithMaxAmount= {};<br>  arr.forEach(item=&gt;{<br>    const amount = item.price * item.quantity;<br>    if(amount &gt; (itemWithMaxAmount.amount || 0)){<br>      itemWithMaxAmount = {...item, amount}<br>    }<br>  });<br>  return itemWithMaxAmount;<br>}<br><br>const result = getMaxAmountItem(items);<br>console.log(result); // {quantity: 1, price: 5, name: &#39;product_2&#39;, amount: 5}</pre><h3>2. Find the maximum number in an array</h3><p>To find the maximum number in an array, you can use the Math.max() function in combination with the spread operator (...) to unpack the array. Here&#39;s an example:</p><pre>const numbers = [3, 5, 7, 2, 8, 1];<br>const maxNumber = Math.max(...numbers);<br><br>console.log(maxNumber); // Output: 8</pre><pre>// Using a loop:<br>const numbers = [3, 5, 7, 2, 8, 1];<br>let maxNumber = numbers[0]; // Assume the first number is the max<br><br>for (let i = 1; i &lt; numbers.length; i++) {<br>    if (numbers[i] &gt; maxNumber) {<br>        maxNumber = numbers[i];<br>    }<br>}<br><br>console.log(maxNumber); // Output: 8<br><br><br>// Using a reduce():<br>const numbers = [3, 5, 7, 2, 8, 1];<br>const maxNumber = numbers.reduce((max, current) =&gt; {<br>    return current &gt; max ? current : max;<br>}, numbers[0]);<br><br>console.log(maxNumber); // Output: 8</pre><h3>3. Find unique objects in an given array</h3><pre>const inputArray = [<br>  { name: &quot;georgia&quot; },<br>  { name: &quot;tbilisi&quot; },<br>  { name: &quot;georgia&quot; },<br>  { name: &quot;tbilisi&quot; },<br>  { name: &quot;111111&quot; }<br>];<br><br>const getUniqueObjects = (array) =&gt; {<br>  const seen = new Set();<br>  return array.filter(item =&gt; {<br>    if (!seen.has(item.name)) {<br>      seen.add(item.name);<br>      return true; // Keep this item<br>    }<br>    return false; // Filter out this item<br>  });<br>};<br><br>const outputArray = getUniqueObjects(inputArray);<br>console.log(outputArray); <br>/* <br>  [<br>    { name: &quot;georgia&quot; },<br>    { name: &quot;tbilisi&quot; },<br>    { name: &quot;111111&quot; }<br>  ] <br>*/</pre><h3>4. Find the longest word in a given sentence</h3><p>Here’s how you can find the longest word in a given sentence, both using and not using the reduce method.</p><pre>// Using a reduce():<br>function findLongestWordWithReduce(sentence) {<br>  return sentence<br>    .split(&quot; &quot;)<br>    .reduce((longest, currentWord) =&gt; <br>      currentWord.length &gt; longest.length ? currentWord : longest<br>    , &quot;&quot;);<br>}<br><br>console.log(findLongestWordWithReduce(&quot;The quick brown fox jumps over the lazy dog&quot;)); //&quot;quick&quot;<br><br><br>// Without a reduce():<br>function findLongestWord(sentence) {<br>  const words = sentence.split(&quot; &quot;);<br>  let longestWord = &quot;&quot;;<br><br>  for (let word of words) {<br>    if (word.length &gt;= longestWord.length) {<br>      longestWord = word;<br>    }<br>  }<br><br>  return longestWord;<br>}<br><br>console.log(findLongestWord(&quot;The quick brown fox jumps over the lazy dog&quot;)); //&quot;jumps&quot;</pre><h3>5. Check if a string is a palindrome</h3><pre>function isPalindrome(str) {<br>  // Convert the string to lowercase and remove non-alphanumeric characters<br>  const cleanedStr = str.toLowerCase().replace(/[^a-z0-9]/g, &#39;&#39;);<br>  <br>  // Reverse the cleaned string<br>  const reversedStr = cleanedStr.split(&#39;&#39;).reverse().join(&#39;&#39;);<br>  <br>  // Check if the original cleaned string is equal to the reversed string<br>  return cleanedStr === reversedStr;<br>}<br><br>// Example usage<br>console.log(isPalindrome(&quot;A man, a plan, a canal, Panama&quot;)); // true<br>console.log(isPalindrome(&quot;racecar&quot;)); // true<br>console.log(isPalindrome(&quot;hello&quot;)); // false</pre><ul><li>The toLowerCase() method ensures the comparison is case-insensitive.</li><li>replace(/[^a-z0-9]/g, &#39;&#39;) removes all non-alphanumeric characters.</li><li>split(&#39;&#39;) converts the string into an array of characters.</li><li>reverse() reverses the array.</li><li>join(&#39;&#39;) converts the reversed array back into a string.</li><li>Finally, the original cleaned string is compared with the reversed string to check for palindrome status.</li></ul><h3>6. Remove duplicates from an array</h3><p>You can remove duplicates from an array using various methods. Here’s one common way using Set:</p><pre>// Big O - O(n)<br><br>const array = [1, 2, 3, 1, 2, 4, 5];<br>const uniqueArray = [...new Set(array)];<br>console.log(uniqueArray); // Output: [1, 2, 3, 4, 5]</pre><p>Set is a built-in object that stores unique values. By spreading the Set back into an array, you get an array with all duplicates removed.</p><p>Another approach is to use filter to only include the first occurrence of each element:</p><pre>// Big O - O(n^2)<br><br>const array = [1, 2, 3, 1, 2, 4, 5];<br>const uniqueArray = array.filter((value, index) =&gt; array.indexOf(value) === index);<br>console.log(uniqueArray); // Output: [1, 2, 3, 4, 5]<br></pre><p>This approach is more flexible but less efficient for large arrays compared to the Set method.</p><h3>7. Reverse a string</h3><p>To reverse a string without using built-in methods, you can use a loop to construct the reversed string. Here’s an example of how to do this:</p><pre>function reverseString(str) {<br>  let reversed = &#39;&#39;; // Initialize an empty string to store the reversed string<br>  for (let i = str.length - 1; i &gt;= 0; i--) {<br>      reversed += str[i]; // Append each character in reverse order<br>  }<br><br>/*<br>  // Replace for loop with this<br>  str.split(&#39;&#39;).forEach(x=&gt;{<br>   reversed = `${x}${reversed}`<br>  })<br>*/<br>  return reversed; // Return the reversed string<br>}<br><br>// Example usage:<br>const originalString = &quot;Hello, World!&quot;;<br>const reversedString = reverseString(originalString);<br>console.log(reversedString); // Output: &quot;!dlroW ,olleH&quot;</pre><ul><li>We define a function called reverseString that takes a string str as an argument.</li><li>We initialize an empty string reversed to build the reversed version.</li><li>We loop through the original string from the last character to the first, appending each character to reversed.</li><li>Finally, we return the reversed string.</li></ul><h3>8. Find the factorial of a given number</h3><p>To find the factorial of a given number, you can use either an iterative or a recursive approach. Here are examples of both methods:</p><pre>function factorial(n) {<br>    if (n &lt; 0) {<br>        return undefined; // Factorial is not defined for negative numbers<br>    }<br>    let result = 1;<br>    for (let i = 2; i &lt;= n; i++) {<br>        result *= i;<br>    }<br>    return result;<br>}<br><br>// Example usage:<br>console.log(factorial(5)); // Output: 120<br><br><br><br>// Different aproach but cleaner code<br>function factorial(n) {<br>  let factorial = 1;<br>  while(n!==0){<br>    factorial *=n;<br>    n--;<br>  }<br>  return factorial;<br>}<br><br>// Example usage:<br>console.log(factorial(5)); // Output: 120</pre><pre>// Using reduce()<br><br>function factorialWithReduce(n) {<br>    if (n &lt; 0) {<br>        return undefined; // Factorial is not defined for negative numbers<br>    }<br>    // Create an array from 1 to n and use reduce to calculate the factorial<br>    return Array.from({ length: n }, (_, i) =&gt; i + 1).reduce((acc, val) =&gt; acc * val, 1);<br>}<br><br>// Example usage:<br>console.log(factorialWithReduce(5)); // Output: 120</pre><h3>9. Teturns an object with words grouped by their lengths, with duplicates removed.</h3><pre>// Without a reduce():<br>function findLongestWord(sentence: any) {<br>   const wordsss = [...new Set(sentence.toLowerCase().split(&quot; &quot;))];<br>  console.log(wordsss)<br>  const words = sentence.split(&quot; &quot;);<br>  let longestWord: any = &quot;&quot;;<br>  let myObject: any = {};<br>  for (let word of words) {<br>    const matchedArray = myObject[word.length] || [word];<br>    myObject[word.length] = [...matchedArray, word]<br>    if (word.length &gt;= longestWord.length) {<br>      longestWord = word;<br>    }<br>  }<br>  return {longestWord, myObject};<br>}<br>console.log(findLongestWord(&quot;The quick brown fox jumps over the lazy dog&quot;));<br>/* // will the result<br>{<br>  &quot;longestWord&quot;: &quot;jumps&quot;,<br>  &quot;myObject&quot;:{<br>    &quot;3&quot;: [&quot;the&quot;, &quot;fox&quot;, &quot;dog&quot;],<br>    &quot;4&quot;: [&quot;over&quot;, &quot;lazy&quot;],<br>    &quot;5&quot;: [&quot;quick&quot;, &quot;brown&quot;, &quot;jumps&quot;]<br>  }<br>}<br>*/<br></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=430cdd519935" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ESLint + Husky + Lint-staged]]></title>
            <link>https://imedbekaia.medium.com/eslint-husky-682cef0cd52c?source=rss-b210a610c653------2</link>
            <guid isPermaLink="false">https://medium.com/p/682cef0cd52c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[husky]]></category>
            <category><![CDATA[eslint]]></category>
            <category><![CDATA[typescript-prettier]]></category>
            <dc:creator><![CDATA[Imeda Bekaia]]></dc:creator>
            <pubDate>Thu, 17 Oct 2024 11:17:28 GMT</pubDate>
            <atom:updated>2024-10-17T14:57:02.654Z</atom:updated>
            <content:encoded><![CDATA[<p>Using ESLint with Angular is a great way to maintain consistent code quality and catch potential issues early. Here’s a complete guide to setting up ESLint in your Angular project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ISvHIeWFwzmsX2Qr_Q8bvQ.png" /></figure><p>Before Angular 11, TSLint was the default linter. If you’re migrating an older project, follow these steps:</p><ol><li><strong>Uninstall TSLint:</strong></li></ol><pre>npm uninstall tslint</pre><p><strong>2. Remove TSLint Config Files: Delete </strong><strong>tslint.json and any </strong><strong>tslint references in </strong><strong>angular.json.</strong></p><h3>ESLint</h3><p><strong>Step 1: </strong>Install ESLint and Angular ESLint Plugins</p><pre>npm install --save-dev eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-import eslint-plugin-jsdoc eslint-plugin-prettier eslint-plugin-eslint-comments</pre><p>If you want to use the Angular ESLint plugin specifically designed for Angular projects:</p><pre>ng add @angular-eslint/schematics</pre><p><strong>Step 2: </strong>Create ESLint Configuration File</p><p>You need to create an ESLint configuration file. You can create it manually or use a CLI tool. Here’s how to do it manually.</p><ul><li>Create a file named .eslintrc.json in the root of your project.</li><li>Add the following configuration:</li></ul><pre>{<br>  &quot;root&quot;: true,<br>  &quot;overrides&quot;: [<br>    {<br>      &quot;files&quot;: [&quot;*.ts&quot;],<br>      &quot;parser&quot;: &quot;@typescript-eslint/parser&quot;,<br>      &quot;parserOptions&quot;: {<br>        &quot;project&quot;: [&quot;tsconfig.json&quot;],<br>        &quot;sourceType&quot;: &quot;module&quot;<br>      },<br>      &quot;plugins&quot;: [&quot;@typescript-eslint&quot;],<br>      &quot;extends&quot;: [<br>        &quot;eslint:recommended&quot;,<br>        &quot;plugin:@typescript-eslint/recommended&quot;,<br>        &quot;plugin:@angular-eslint/recommended&quot;,<br>        &quot;plugin:prettier/recommended&quot;<br>      ],<br>      &quot;rules&quot;: {<br>        // Add or customize your rules here<br>        &quot;@typescript-eslint/no-explicit-any&quot;: &quot;off&quot;,<br>        &quot;import/no-unresolved&quot;: &quot;error&quot;,<br>        &quot;prettier/prettier&quot;: &quot;error&quot;<br>      }<br>    }<br>  ]<br>}</pre><p><strong>Step 3: </strong>Create ESLint Ignore File (Optional)</p><p>If you want to ignore specific files or directories, create a .eslintignore file in the root of your project and add paths you want to exclude.</p><pre>node_modules/<br>dist/<br>build/</pre><p><strong>Step 4: </strong>Update angular.json with ESLint Builder</p><pre>&quot;lint&quot;: {<br>  &quot;builder&quot;: &quot;@angular-eslint/builder:lint&quot;,<br>  &quot;options&quot;: {<br>    &quot;eslintConfig&quot;: &quot;.eslintrc.json&quot;,<br>    &quot;lintFilePatterns&quot;: [&quot;src/**/*.ts&quot;, &quot;src/**/*.html&quot;]<br>  }<br>}</pre><p><strong>Optional: </strong>ESLint with Prettier Integration</p><p>If you want to integrate ESLint with Prettier, follow these steps:</p><ol><li>Install Prettier and related packages:</li></ol><pre>npm install --save-dev prettier eslint-config-prettier eslint-plugin-prettier</pre><p>2. Update your .eslintrc.json:</p><pre>{<br>  &quot;root&quot;: true,<br>  &quot;ignorePatterns&quot;: [&quot;projects/**/*&quot;],<br>  &quot;extends&quot;: [&quot;plugin:prettier/recommended&quot;],<br>  &quot;overrides&quot;: [<br>    {<br>      &quot;files&quot;: [&quot;*.ts&quot;],<br>      &quot;extends&quot;: [<br>        &quot;plugin:@angular-eslint/recommended&quot;,<br>        &quot;plugin:@typescript-eslint/recommended&quot;,<br>        &quot;plugin:prettier/recommended&quot;<br>      ],<br>      &quot;parserOptions&quot;: {<br>        &quot;project&quot;: [&quot;tsconfig.json&quot;]<br>      },<br>      &quot;rules&quot;: {<br>        &quot;@typescript-eslint/no-explicit-any&quot;: &quot;off&quot;,<br>        &quot;@typescript-eslint/explicit-function-return-type&quot;: &quot;off&quot;,<br>        &quot;@typescript-eslint/no-unused-vars&quot;: [<br>          &quot;error&quot;,<br>          { &quot;argsIgnorePattern&quot;: &quot;^_&quot; }<br>        ],<br>        &quot;@angular-eslint/component-selector&quot;: [<br>          &quot;error&quot;,<br>          { &quot;type&quot;: &quot;element&quot;, &quot;prefix&quot;: &quot;app&quot;, &quot;style&quot;: &quot;kebab-case&quot; }<br>        ],<br>        &quot;@angular-eslint/directive-selector&quot;: [<br>          &quot;error&quot;,<br>          { &quot;type&quot;: &quot;attribute&quot;, &quot;prefix&quot;: &quot;app&quot;, &quot;style&quot;: &quot;camelCase&quot; }<br>        ]<br>      }<br>    },<br>    {<br>      &quot;files&quot;: [&quot;*.html&quot;],<br>      &quot;extends&quot;: [&quot;plugin:@angular-eslint/template/recommended&quot;],<br>      &quot;rules&quot;: {<br>        &quot;max-len&quot;: [&quot;error&quot;, { &quot;code&quot;: 140 }],<br>        &quot;prettier/prettier&quot;: &quot;error&quot;<br>      }<br>    }<br>  ]<br>}</pre><blockquote>To turn off the @typescript-eslint/no-explicit-any rule, you can configure it in your ESLint settings. Here’s how you can do it in different ways.</blockquote><blockquote>Disable the Rule Project-Wide (in .eslintrc.json): If you want to disable this rule globally, modify your ESLint configuration file.</blockquote><pre>// .eslintrc.json<br>{<br>  &quot;extends&quot;: [&quot;plugin:@typescript-eslint/recommended&quot;],<br>  &quot;rules&quot;: {<br>    &quot;@typescript-eslint/no-explicit-any&quot;: &quot;off&quot;<br>  }<br>}</pre><p>3. Add a .prettierrc file for Prettier configuration:</p><pre>{<br>  &quot;singleQuote&quot;: true,<br>  &quot;trailingComma&quot;: &quot;all&quot;,<br>  &quot;printWidth&quot;: 80<br>}</pre><p><strong>Run Prettier to auto-format your code:</strong></p><pre>npx prettier --write .</pre><p>This setup ensures a smooth transition from TSLint and provides a solid code-quality setup with ESLint and Angular. Let me know if you run into any issues!</p><h3>.husky</h3><p>To <strong>run ESLint automatically before every commit</strong>, you can integrate it into your Git workflow using <strong>Husky</strong> and <strong>Lint-Staged</strong>. This ensures that your code passes linting checks before it gets committed.</p><p><strong>Step 1: </strong>Install Husky and Lint-Staged</p><pre>npm install --save-dev husky lint-staged</pre><p><strong>Step 2: </strong>Enable Husky</p><p>The npx husky install command has been deprecated in favor of a simpler setup. Instead of relying on individual commands like npx husky add or install, the recommended way now is to initialize Husky with:</p><pre>npx husky init</pre><p>This will create the .husky/ directory. Add the following to your package.json to ensure Husky is enabled when dependencies are installed:</p><pre>&quot;scripts&quot;: {<br>  &quot;prepare&quot;: &quot;husky&quot;<br>}</pre><p>This setup ensures that ESLint and Prettier checks run <strong>before every commit</strong>, preventing unformatted or invalid code from entering the repository. Let me know if anything is unclear or if you run into further issues!</p><p>Now, run the following command to ensure Husky is set up correctly:</p><pre>npm run prepare</pre><p><strong>Step 3: </strong>Create the Pre-Commit Hook Manually</p><p>Create a pre-commit hook using this command:</p><pre>mkdir -p .husky &amp;&amp; echo -e &#39;#!/bin/sh\n. &quot;$(dirname &quot;$0&quot;)/_/husky.sh&quot;\n\nnpx lint-staged&#39; &gt; .husky/pre-commit</pre><p>Then, make the hook executable:</p><pre>chmod +x .husky/pre-commit</pre><p><strong>Step 4: Configure Lint-Staged in </strong><strong>package.json</strong></p><p>In your <strong>package.json</strong>, add the following <strong>Lint-Staged</strong> configuration:</p><pre>&quot;lint-staged&quot;: {<br>  &quot;*.{ts,html}&quot;: [<br>    &quot;eslint --fix&quot;,<br>    &quot;prettier --write&quot;<br>  ]<br>}</pre><p>This will ensure that ESLint and Prettier run on <strong>all staged files</strong> (*.ts and *.html) whenever a commit is attempted.</p><p><strong>Step 5: </strong>Test Your Setup</p><p>Now, whenever you stage files and try to commit, ESLint and Prettier will run automatically. Test it by running:</p><pre>git add .<br>git commit -m &quot;Added ESLint &amp; .husky&quot;</pre><p>If there are any linting or formatting errors, the commit will fail, and you’ll need to fix them before committing again.</p><p><strong>Additional Troubleshooting</strong></p><ol><li><strong>Clean npm cache</strong>:</li></ol><pre>npm cache clean --force</pre><p>2. <strong>Delete </strong><strong>node_modules and reinstall packages</strong>:</p><pre>rm -rf node_modules package-lock.json<br>npm install</pre><p>3. <strong>Check if the Angular CLI version supports ESLint</strong>: Ensure you have @angular/cli 11+ installed:</p><pre>npm install -g @angular/cli@latest</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=682cef0cd52c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[განსხვავება რამდენიმე RXJS Opertaors-ს შორის]]></title>
            <link>https://imedbekaia.medium.com/rxjs-opertaors-88379c4947ec?source=rss-b210a610c653------2</link>
            <guid isPermaLink="false">https://medium.com/p/88379c4947ec</guid>
            <dc:creator><![CDATA[Imeda Bekaia]]></dc:creator>
            <pubDate>Wed, 16 Oct 2024 11:50:26 GMT</pubDate>
            <atom:updated>2024-11-04T10:30:48.484Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fF3fiaCgdhrZ1HB8dw7b2A.png" /></figure><h3>reduce VS. scan</h3><p>ორივე შემთხვევაში, ორივე ოპერატორი ასრულებს ერთსა და იმავე სამუშაობს — ჯამავს მნიშვნელობებს დროის განმავლობაშ, თუმცა მცირედი განსხვავებით. reduce აბრუნებს მხოლოდ საბოლოო მნიშნელობას (ერთხელ), ხოლო scan ყოველ ახალ იტერაციაზეა, მნიშნელობათა ახალ ჯამს.</p><pre>import { of, reduce } from &#39;rxjs&#39;;<br>// Source observable emitting numbers<br>    const numbers$ = of(1, 2, 3, 4);<br>// Use reduce to sum the numbers<br>    numbers$<br>      .pipe(reduce((acc, value) =&gt; acc + value, 0))<br>      .subscribe(result =&gt; console.log(&#39;Reduce result:&#39;, result));<br>// Output: Reduce result: 10</pre><pre>import {of, scan} from &#39;rxjs&#39;;<br>// Source observable emitting numbers<br>    const numbers$ = of(1, 2, 3, 4);<br>// Use scan to emit running total<br>    numbers$<br>      .pipe(scan((acc, value) =&gt; acc + value, 0))<br>      .subscribe(result =&gt; console.log(&#39;Scan result:&#39;, result));<br>// Output:<br>// Scan result: 1<br>// Scan result: 3<br>// Scan result: 6<br>// Scan result: 10</pre><h3>timer VS. interval</h3><p>ორივე შემთხვევაში, ორივე ოპერატორი იქცევა მსგავსად, თუმცა ისინი განსხვავდებიან თავიანთი ქცევით და გამოყენების შემთხვევებით.</p><pre>import { timer } from &#39;rxjs&#39;;<br>// Emit first value after 2 seconds, then every 1 second<br>const startDue = 2000;<br>    const source$ = timer(startDue, 1000);<br>    source$.subscribe(value =&gt; console.log(&#39;Timer:&#39;, value));<br>// Output:<br>// (After 2 seconds) Timer: 0<br>// (After 3 seconds) Timer: 1<br>// (After 4 seconds) Timer: 2<br>// ...</pre><p>timer -ს აქვს ორი ძირითადი პარამეტრი შეყოვნების (startDue) და ინტერვალის (intervalDuration). startDue თუ ნულის ტოლია, მაშინ timer დაუყოვნებლივ ახდენს მნიშვნელობის გატყორცნას. ხოლო თუ მაგ.: startDue 2000-ის ტოლია, მაშინ პირველი მნიშნელობა გაიტყორცნება 2 წამის შემდეგ და ყოველი შემდეგი intervalDuratio-ის მიხედვით.</p><pre>import { interval } from &#39;rxjs&#39;;<br>// Emit values every 1 second<br>    const source$ = interval(1000);<br>    source$.subscribe(value =&gt; console.log(&#39;Interval:&#39;, value));<br>// Output:<br>// (After 1 second) Interval: 0<br>// (After 2 seconds) Interval: 1<br>// (After 3 seconds) Interval: 2<br>// ...</pre><p>interval -ს აქვს ორი ძირითადი პარამეტრი შეყოვნების (startDue) და ინტერვალის (intervalDuration). startDue თუ ნულის ტოლია, მაშინ timer დაუყოვნებლივ ახდენს მნიშვნელობის გატყორცნას.</p><h3>mergeMap vs. concatMap vs. switchMap</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*Cx9AdbjutzjB1z8LhrIzcA.png" /></figure><p>switchMap</p><pre>import { fromEvent, of, switchMap, delay } from &#39;rxjs&#39;;<br>    // Simulating a search input where only the latest search result matters<br>    const searchInput = fromEvent(document, &#39;keyup&#39;);<br>    searchInput.pipe(<br>      switchMap(() =&gt; of(&#39;Result from latest query&#39;).pipe(delay(1000)))<br>    ).subscribe(console.log);<br>    // If you type multiple times quickly, <br>    // only the latest input will log the result.</pre><p>concatMap</p><pre>import { of, concatMap, delay } from &#39;rxjs&#39;;<br><br>    // Simulating API requests that must run in sequence<br>    const requests = of(&#39;Request 1&#39;, &#39;Request 2&#39;, &#39;Request 3&#39;);<br>    requests.pipe(<br>          concatMap(request =&gt; of(`${request} completed`).pipe(delay(1000)))<br>        ).subscribe(console.log);<br>    // Output:<br>    // (After 1 second) Request 1 completed<br>    // (After 2 seconds) Request 2 completed<br>    // (After 3 seconds) Request 3 completed</pre><p>mergeMap</p><pre>import { of, mergeMap, delay } from &#39;rxjs&#39;;<br><br>// Simulating parallel API requests<br>    const requests = of(&#39;Request 1&#39;, &#39;Request 2&#39;, &#39;Request 3&#39;);<br><br>    requests.pipe(<br>      mergeMap(request =&gt; of(`${request} completed`).pipe(delay(1000)))<br>    ).subscribe(console.log);<br><br>// Output (order may vary):<br>// (After 1 second) Request 1 completed<br>// (After 1 second) Request 2 completed<br>// (After 1 second) Request 3 completed</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88379c4947ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Maps-ის ინტეგრაცია Angular 17]]></title>
            <link>https://imedbekaia.medium.com/google-maps-%E1%83%98%E1%83%A1-%E1%83%98%E1%83%9C%E1%83%A2%E1%83%94%E1%83%92%E1%83%A0%E1%83%90%E1%83%AA%E1%83%98%E1%83%90-angular-17-180a46b390fc?source=rss-b210a610c653------2</link>
            <guid isPermaLink="false">https://medium.com/p/180a46b390fc</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[რუკა]]></category>
            <category><![CDATA[google-map-api]]></category>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[marker]]></category>
            <dc:creator><![CDATA[Imeda Bekaia]]></dc:creator>
            <pubDate>Tue, 17 Sep 2024 17:02:09 GMT</pubDate>
            <atom:updated>2024-09-18T05:46:42.624Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*065YNNhVH_PIL0XBYYAV2A.png" /></figure><p>სანამ შევქმნით ჩვენს Angular-ის პროექტს, დავრჭმუნდეთ, რომ გვაქვს Google Maps JavaScript API-ის მოქმედი API key. დამატებითი ინსტრუქციებისთვის შეგიძლიათ გადახვიდეთ ქვემოთ მოცემულ ბმულზე:</p><p><a href="https://developers.google.com/maps/documentation/javascript/get-api-key">https://developers.google.com/maps/documentation/javascript/get-api-key</a></p><h3>ინსტალაცია</h3><p>დავიწყოთ პროექტის შექმნით:</p><pre>ng new angular-google-maps<br>cd angular-google-maps</pre><p>დავაყენოთ <a href="https://www.npmjs.com/package/@angular/google-maps">Google Maps module</a> :</p><pre>npm i @angular/google-maps</pre><p>Angular 17-ში რადგანაც კომპონენტი დიფოლთად standalone არის, რუკის მოდული შეგვიძლია შევაიმპორტოთ კომპონენტშივე src/app/app.component.ts :</p><pre>...<br>import { GoogleMapsModule } from &quot;@angular/google-maps&quot;;<br><br>@Component({<br>  selector: &#39;app-root&#39;,<br>  standalone: true,<br>  imports: [RouterOutlet, GoogleMapsModule],<br>  templateUrl: &#39;./app.component.html&#39;,<br>  styleUrl: &#39;./app.component.scss&#39;<br>})<br>...</pre><p>ძველ ვერსიაზე, თუ იგი standalone არ არის, მოდული უნდა შევაიმპორტოთ src/app/app.module.tsფაილში:</p><pre>...<br>import { GoogleMapsModule } from &quot;@angular/google-maps&quot;;<br><br>@NgModule({<br>  declarations: [...],<br>  imports: [..., GoogleMapsModule],<br>  ...<br>})<br>export class AppModule {}</pre><p>ქვემოთ მოცემული სკრიპტი ჩავაგდოთ src/index.html ფაილში <strong>body </strong>თეგის დახურვამდე:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;head&gt;<br>  ...<br>&lt;/head&gt;<br>&lt;body&gt;<br>  ...<br>  &lt;script&gt;<br>      window.addEventListener(&#39;load&#39;, function () {<br>          const script = document.createElement(&#39;script&#39;);<br>          script.src = &#39;https://maps.googleapis.com/maps/api/js?key=AIzaSyAOVYRIgupAurZup5y1PRh8Ismb1A3lLao&#39;;<br>          document.body.appendChild(script);<br>      });<br>  &lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><h3>რუკის დამატება</h3><p>სანამ რუკას დავამატებდეტ, მანამდე განვსაზღვრით რამდენიმე აუცილებელი პარამეტრი, რომელიც აუცილებელია რუკის ჩასათვირთად:</p><ul><li>center = კოორდინანტი რუკის გაცენტრებისთის</li><li>zoom = რუკის მასშტაბი, რამდენად ახლოს თუ შორს უნდა იყოს ხედვის არიდან.</li></ul><pre>&lt;!-- app.component.html --&gt;<br>&lt;h1&gt;Google Maps in Angular 17&lt;/h1&gt;<br>&lt;google-map height=&quot;600px&quot; width=&quot;800px&quot; [options]=&quot;options&quot;&gt; &lt;/google-map&gt;</pre><pre>// app.component.ts<br>...<br>export class AppComponent {<br>  ...<br>  options: google.maps.MapOptions = {<br>    center: {lat: 41.697102, lng: 44.773674},<br>    zoom: 9,<br>  };<br>}</pre><h3>მარკერის(პინის) დამატება რუკაზე</h3><pre>&lt;!-- app.component.html --&gt;<br>&lt;google-map #map [center]=&quot;center&quot; [zoom]=&quot;zoom&quot;&gt;<br>    &lt;map-marker<br>            *ngFor=&quot;let marker of markers&quot;<br>            [position]=&quot;{ lat: marker.lat, lng: marker.lng }&quot;<br>            (mapMouseover)=&quot;showDialog(marker, $event)&quot;<br>            (mapMouseout)=&quot;hideDialog(marker, $event)&quot;<br>    &gt;&lt;/map-marker&gt;<br>    &lt;map-info-window *ngIf=&quot;infoWindowOpened&quot; #infoWindow&gt;<br>        &lt;div class=&quot;d-flex flex-column p-3 ali&quot;&gt;<br>            &lt;h5&gt;მარკერის სათაური&lt;/h5&gt;<br>            &lt;p&gt;მარკერის ინფორმაცია&lt;/p&gt;<br>        &lt;/div&gt;<br>    &lt;/map-info-window&gt;</pre><pre>// app.component.ts   <br>export class AppComponent {<br>  @ViewChild(&#39;infoWindow&#39;) infoWindowRef: ElementRef;<br>  @ViewChild(&#39;map&#39;) mapRef: any;<br>  public zoom = 9;<br>  public center: google.maps.LatLngLiteral = {lat: 41.697102, lng: 44.773674};<br>  public infoWindowOpened = false;<br>  public markers: any[] = [<br>    {lat: 41.697102, lng: 44.773674},<br>    {lat: 41.697102, lng: 44.773674},<br>    {lat: 41.697102, lng: 44.773674} <br>    // აქ მხოლოდ თბილისის კოორდინანტებია, შესაბამისად სხვა გრძედისა და განედის შეყვანის შემდეგ პინი დაისმება შესაბამის ადგილას.<br>  ]<br><br>  constructor(){<br>  }<br><br>  showDialog(marker: any, event: any) {<br>    this.infoWindowOpened = true;<br>    setTimeout(() =&gt; {<br>      if (this.infoWindowRef &amp;&amp; this.mapRef) {<br>        const mouseEvent: any = event as any;<br>        const clientX = mouseEvent.domEvent.clientX;<br>        const clientY = mouseEvent.domEvent.clientY;<br>        const mapElement = this.mapRef._elementRef.nativeElement as HTMLElement;<br>        const infoWindowElement = this.infoWindowRef.nativeElement as HTMLElement;<br>        const mapRect = mapElement.getBoundingClientRect();<br>        const infoWindowRect = infoWindowElement.getBoundingClientRect();<br>        this._renderer.setStyle(this.infoWindowRef.nativeElement, &#39;z-index&#39;, `0`);<br>        this._renderer.setStyle(this.infoWindowRef.nativeElement, &#39;top&#39;, `${clientY - mapRect.top - infoWindowRect.height - 30}px`);<br>        this._renderer.setStyle(this.infoWindowRef.nativeElement, &#39;left&#39;, `${clientX - mapRect.left - (infoWindowRect.width / 2)}px`);<br>      }<br>    }, 50)<br>  }<br>  <br>  hideDialog(marker: any, event: any) {<br>    this.infoWindowOpened = false;<br>  }<br>}</pre><pre>map-info-window {<br>  display: flex !important;<br>  flex-direction: column;<br>  min-width: 300px;<br>  max-width: 400px;<br>  border-radius: 15px;<br>  background: #ffffff;<br>  position: absolute;<br>  z-index: -99;<br>  left: 100px;<br>  top: 100px;<br>  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);<br><br>  &amp;:before {<br>    content: &#39;&#39;;<br>    position: absolute;<br>    left: 50%;<br>    top: calc(100% - 10px);<br>    width: 15px;<br>    height: 15px;<br>    background: #ffffff;<br>    rotate: 45deg;<br>    border-radius: 2px;<br>  }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=180a46b390fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[De-ferrari-able views და FCP-ის მნიშნელობა]]></title>
            <link>https://imedbekaia.medium.com/de-ferrari-able-views-%E1%83%93%E1%83%90-fcp-%E1%83%98%E1%83%A1-%E1%83%9B%E1%83%9C%E1%83%98%E1%83%A8%E1%83%9C%E1%83%94%E1%83%9A%E1%83%9D%E1%83%91%E1%83%90-03d6ae527b12?source=rss-b210a610c653------2</link>
            <guid isPermaLink="false">https://medium.com/p/03d6ae527b12</guid>
            <dc:creator><![CDATA[Imeda Bekaia]]></dc:creator>
            <pubDate>Tue, 16 Jul 2024 12:02:20 GMT</pubDate>
            <atom:updated>2024-07-16T12:08:10.550Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JqeqngSjGcyS1wwRuwqAOQ.png" /></figure><h3>რას წარმოადგენს FCP?</h3><p>ბევრისთვის First Contentful Paint (FCP) არახალია, რადგან ვისაც შეხება ჰქონია პერფომანსის ოპტიმიზაციასთან, ეს მახასიათებელი ერთ-ერთი მნიშნელოვანი მზომელია. FCP ზომავს დროს, ტაბის გახსნის მომენტიდან, გვერდის კონტენტის ეკრანის რომელიმე ნაწილში გამოჩენამდე. ამ შემთვევაში კონკტენი მოიაზრებს ტექსტს, სურათებს (ფონური სურათების ჩათვლით), &lt;svg&gt; ელემენტებს ან გაუმჭვირვალე &lt;canvas&gt; ელემენტებს.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*91s3XveFKQHEICCy.png" /><figcaption>ამ დროის ხაზზე, FCP ხდება მეორე კადრში, რადგან სწორედ ამ დროს გამოჩნდა პირველი ტექსტი და სურათი ეკრანზე.</figcaption></figure><p>რადგანაც ეს პოსტი არ ეხება FCP-ს, აქ ჯობია მოვრჩეთ მასზე საუბარს და გადავიდეთ ჩვენს მთავარ თემაზე, ანუ რა არის ახალი ანგულარის 17-ე ვერსიაში?..</p><p>გადამწყვეტი მნიშვნელობა აქვს იუზერ იქსფერიენსს(UI) — განსაკუთრებით მაშინ, როდესაც მომხმარებლები ელოდებიან, როდის ჩაიტვირთება მათთვის სასურველი კონტენტი. ამის გამოსავალი ძირითადად ლოადერებია, რომლებიც მიგვითითებენ, რომ მის უკან მიდის პროცესი და საჭიროა დალოდება. რა ხდება მაშინ როცა, კომპონენტი მძიმეა ან მომხმარებელს აქვს ნელი ინტერნეტ კავშირი? პასუხი დამალულია Angular-ის ახალ მახასიათებლებში…</p><p>Let’s dive in…</p><h3>Angular-ის ახალი მახასიათებელი პერფორმანსის გასაუმჯობესებლად. რა არის @defer ბლოკი?</h3><blockquote>Defer &lt;dəˈfər&gt; — გადადება, გადავადება</blockquote><p>Angular-ის deferrable views(წარმოდგენა არ მაქვს სწორად როგორ ითარგმნება) გვთავაზობს defer ბლოკს, რომლის საშუალებითაც შესაძლებელია გადავდოთ ან დავაყოვნოთ დიდი მონაცემის მქონე კონტენტის ჩატვირთვა იქამდე, სანამ კონკრეტული თრიგერების(triggers) საშუალებით არ მოგვეცემა საწინააღდეგოს გაკეთების უფლება.</p><p>მაგალითი 1:</p><pre>@defer {<br>  &lt;div&gt;<br>    &lt;!-- დაყოვნებული ელემენტი --&gt;<br>    (...)<br>  &lt;/div&gt;<br>}<br><br>&lt;div&gt;<br>  &lt;!-- მყისიერად ჩატვირთული ელემენტი --&gt;<br>  (...)<br>&lt;/div&gt;</pre><p>მაგალითი 2:</p><p>დაყოვნება შესაძლებელია დათრიგერდეს კონტრეტული კივორდების მეშვეობით, ამ შემთხვევაში when, რომელიც უყურებს isVisible-ის მნიშვნელობას და მის მიხედვით აყოვნებს ელემენტის გამოჩენას.</p><pre>@defer(when isVisible) {<br>  &lt;div&gt;<br>    &lt;!-- დაყოვნებული ელემენტი --&gt;<br>    (...)<br>  &lt;/div&gt;<br>}</pre><pre>public isVisible: boolean;<br><br>constructor() {<br>  setTimeout(() =&gt; {<br>    this.isVisible = true;<br>  }, 500)<br>}</pre><p>აქვე: აღსანიშნავია ის ფაქტი რომ, თუ defer ბლოკს გააჩნია რაიმე სახის თრიგერი, აუცილებლად საჭიროა მას მოსდევდეს placeholder ბლოკი, რომელმაც უნდა დაელოდოს რეალურდ კონკენტს სანამ ჩაიტვირთება და მანამდე მისი ადგილი კონკრეტული ინფორმაციით ამოავსოს. წარმოიდგინეთ, რომ defer და placeholder იგივეს აკეთებს რასაც if — else ბლოკები, უბრალოდ შნაარსი სხვა აქვს და აგრეთვე მნიშვნელოვან ზეგვალენას ახდენენ პერფორმანსზე.</p><p>შესაბამისად სწორი ვარიანტი იქნება</p><pre>  @defer(when isVisible) {<br>    &lt;div&gt;<br>      &lt;!-- დაყოვნებული ელემენტი --&gt;<br>      (...)<br>    &lt;/div&gt;<br>  } @placeholder{<br>    &lt;div&gt;<br>      &lt;!-- ფლეისჰოლდერად ჩატვირთული ელემენტი --&gt;<br>      (...)<br>    &lt;/div&gt;<br>  }</pre><p>defer ბლოკის გარდა, მასთან ჯაჭვში ერთად სხვა ბლოკიებიც იღებენ მონაწილეობას, რათა გავჰენდლოთ სხავდასხვა მდგომარეობის მნიშნელობები:</p><pre>@defer (when isVisible) {<br>  &lt;span&gt; (...) &lt;/span&gt;<br>} @placeholder (minimum 500ms) {<br> &lt;span&gt; (...) &lt;/span&gt;<br>} @loading (after 100ms; minimum 1s) {<br>  &lt;span&gt;(...) &lt;!-- იტვირთება --&gt; &lt;/span&gt;<br>} @error {<br>  &lt;span&gt; (...) &lt;!-- უპს! დაფიქსირდა შეცდომა --&gt; &lt;/span&gt;<br>}</pre><blockquote>minimum დროის ის მინიმალური რაოდენობა, რაც საჭიროა კონტენტის ეკრანზე გამოჩენამდე. ე.წ დილეის აკეთებს.</blockquote><p>განვიხილოთ</p><pre>@defer (on viewport) {<br>  &lt;span&gt; (...) &lt;/span&gt;<br>} @placeholder {<br>  &lt;span&gt; Will be overwritten with the cyan’s content &lt;/span&gt;<br>}</pre><p>ამ შემთხვევაშ ქივორდი <strong>on-</strong>ს შესაძლებელია სხვაადასხვა თრიგერი ჰქონდეს, განსხვავებით <strong>when-</strong>ისგან, რომელიც მხოლოდ ბულიანს იღებს. <strong>on-</strong>ის თირეგრი შეიძლება იყოს, idle, immediate, interaction, hover, viewport და timer;</p><h3>Interaction, Hover</h3><pre>@defer (on interaction) {<br>  &lt;div&gt; (...) &lt;/div&gt;<br>} @placeholder {<br>  &lt;span&gt; Click here to load &lt;/span&gt;<br><br>}<br><br>&lt;!-- ელემენტი ჩნდება მაშინ, როცა <br>კონკრეტულად ამ ელემნტზე დავათრიგერებთ --&gt;<br><br>----------------------------------------------------<br><br>&lt;button #trigger&gt; Click to load &lt;/button&gt;<br><br>@defer (on interaction(trigger)) {<br>  &lt;div&gt; (...) &lt;/div&gt;<br>}<br>&lt;!-- ელემენტი ჩნდება მაშინ, როცა <br>ღილაკზე დავათრიგერებთ --&gt;<br></pre><h3>Timer</h3><pre>@defer (on timer(5000)) {<br>  &lt;div&gt; (...) &lt;/div&gt;<br>} @placeholder {<br>  &lt;span&gt; Loading... &lt;/span&gt;<br>}<br>&lt;!-- ელემენტი ჩნდება მაშინ, როცა დაყოვნების დრო ამოიწურება --&gt;</pre><h3>შეჯამება</h3><p>არვიცი რომელი უფრო სწრაფია ფერარის FXX Evo თუ Angular-ის defer, მაგრამ უკანასკნელმა მახასიათებელმა მნიშნელოვანი როლი უნდა ითამაშოს ჩენს საქმიანობაში! ვატყობ…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=03d6ae527b12" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>