<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Arnav Bansal</title>
    <description>The latest articles on Forem by Arnav Bansal (@itsarnavb).</description>
    <link>https://forem.com/itsarnavb</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F100092%2F72c5bac4-abd2-431c-a24c-da3e2241436d.jpg</url>
      <title>Forem: Arnav Bansal</title>
      <link>https://forem.com/itsarnavb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/itsarnavb"/>
    <language>en</language>
    <item>
      <title>How to normalize (join together) bold nodes in HTML DOM?</title>
      <dc:creator>Arnav Bansal</dc:creator>
      <pubDate>Sun, 01 Sep 2019 19:57:22 +0000</pubDate>
      <link>https://forem.com/itsarnavb/how-to-normalize-join-together-bold-nodes-in-html-dom-1fb3</link>
      <guid>https://forem.com/itsarnavb/how-to-normalize-join-together-bold-nodes-in-html-dom-1fb3</guid>
      <description>&lt;p&gt;I'm building a contenteditable editor which involves multiple rows of contenteditable divs&lt;/p&gt;

&lt;p&gt;I want to turn this:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Lorem &amp;lt;b&amp;gt;Ipsum&amp;lt;/b&amp;gt;&amp;lt;b&amp;gt; Dolor&amp;lt;/b&amp;gt; Sit Amet&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;into this:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Lorem &amp;lt;b&amp;gt;Ipsum Dolor&amp;lt;/b&amp;gt; Sit Amet&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

</description>
      <category>html</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>help</category>
    </item>
    <item>
      <title>How do you split contenteditable text preserving html formatting? [solved]</title>
      <dc:creator>Arnav Bansal</dc:creator>
      <pubDate>Sun, 11 Aug 2019 10:36:21 +0000</pubDate>
      <link>https://forem.com/itsarnavb/how-do-you-split-contenteditable-text-preserving-html-formatting-g9d</link>
      <guid>https://forem.com/itsarnavb/how-do-you-split-contenteditable-text-preserving-html-formatting-g9d</guid>
      <description>&lt;p&gt;I'm using contenteditable divs to represent paragraphs in my editor. I've implemented most of the usual editing features&lt;/p&gt;

&lt;p&gt;Splitting paragraphs breaks when any HTML formatting is involved. &lt;/p&gt;

&lt;p&gt;For example, adding a space and hitting enter results in&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;amp;&lt;/code&gt;&lt;br&gt;
&lt;code&gt;nbsp;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Of course, '&amp;amp;nbsp;' being a single character that represents a space.&lt;/p&gt;
&lt;h2&gt;
  
  
  Solution (Update)
&lt;/h2&gt;

&lt;p&gt;Okay I figured it out.&lt;/p&gt;

&lt;p&gt;innerHTML and innerText aren't useful for DOM manipulation.&lt;/p&gt;

&lt;p&gt;However, the selection and ranges API is great for this. &lt;code&gt;extractContents&lt;/code&gt; automatically splits elements without breaking markup.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function splitNode(selection, root) {
  let range = selection.getRangeAt(0);
  let {firstChild, lastChild} = root;

  let previousRange = document.createRange();
  previousRange.setStart(firstChild, 0);
  previousRange.setEnd(range.startContainer, range.startOffset);

  let nextRange = document.createRange();
  nextRange.setStart(range.endContainer, range.endOffset);
  nextRange.setEnd(lastChild, lastChild.length);
  return {
    previous: previousRange,
    current: range,
    next: nextRange,
  };
}

let ranges = splitNode(document.getSelection(), contentEditableDiv);
let nextFragment = ranges.next.extractContents();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>help</category>
      <category>discuss</category>
    </item>
    <item>
      <title>How do you detect what line it is in wrapped text elements?</title>
      <dc:creator>Arnav Bansal</dc:creator>
      <pubDate>Wed, 07 Aug 2019 11:47:04 +0000</pubDate>
      <link>https://forem.com/itsarnavb/how-do-you-detect-what-line-it-is-in-wrapped-text-elements-4k4l</link>
      <guid>https://forem.com/itsarnavb/how-do-you-detect-what-line-it-is-in-wrapped-text-elements-4k4l</guid>
      <description>&lt;p&gt;I'm implementing a custom editor that uses rows of &lt;code&gt;contenteditable&lt;/code&gt; divs. I'm having trouble implementing the right behavior for the 'up' or 'down' key.&lt;/p&gt;

&lt;p&gt;When the 'up' key is pressed, I need to detect whether the caret is on the first line of text, and move the caret to the div above. Likewise for the 'down' key and the last line of text.&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How do I detect if the '+' key is pressed (without the shift)</title>
      <dc:creator>Arnav Bansal</dc:creator>
      <pubDate>Sun, 14 Jul 2019 14:49:39 +0000</pubDate>
      <link>https://forem.com/itsarnavb/how-do-i-detect-if-the-key-is-pressed-without-the-shift-456k</link>
      <guid>https://forem.com/itsarnavb/how-do-i-detect-if-the-key-is-pressed-without-the-shift-456k</guid>
      <description>&lt;p&gt;I want to trigger the KeyboardEvent for the '+' key even if the '=' key is pressed &lt;/p&gt;

&lt;p&gt;'shift+=' is '+' on English keyboards, but on other keyboards, the key for which 'shift+key' is '+' might be different. How do I account for all such cases?&lt;/p&gt;

</description>
      <category>help</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Database design where state is a function of mutations.</title>
      <dc:creator>Arnav Bansal</dc:creator>
      <pubDate>Wed, 09 Jan 2019 19:55:26 +0000</pubDate>
      <link>https://forem.com/itsarnavb/database-design-where-state-is-a-function-of-mutations-2mo4</link>
      <guid>https://forem.com/itsarnavb/database-design-where-state-is-a-function-of-mutations-2mo4</guid>
      <description>&lt;p&gt;I'm thinking along the lines of redux, where the state is a function of an initial state, and mutations carried out by reducers.&lt;/p&gt;

&lt;p&gt;The benefit is that mutations can capture a large amount of information, and as requirements change, the reducers can be modified to produce a new state.&lt;/p&gt;

&lt;p&gt;Also, we have a history built in.&lt;/p&gt;

&lt;p&gt;Is this a common pattern in database design?&lt;/p&gt;

&lt;p&gt;Specifically, I'm considering implementing this on Firestore. What should I know?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>help</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How do people even work with colors?</title>
      <dc:creator>Arnav Bansal</dc:creator>
      <pubDate>Sun, 25 Nov 2018 13:01:12 +0000</pubDate>
      <link>https://forem.com/itsarnavb/how-do-you-work-with-color-schemes-57ek</link>
      <guid>https://forem.com/itsarnavb/how-do-you-work-with-color-schemes-57ek</guid>
      <description>&lt;p&gt;My monitors show colors differently.&lt;/p&gt;

&lt;p&gt;My phone's brightness changes, depending on the lighting.&lt;/p&gt;

&lt;p&gt;The angle at which I'm looking at the screen affects the color. &lt;/p&gt;

&lt;p&gt;My room's lighting differs throughout the day. &lt;/p&gt;

&lt;p&gt;I'm sure I see colors differently right after waking up.&lt;/p&gt;

&lt;p&gt;I'm sure I see colors differently after I've been working for a while.&lt;/p&gt;

&lt;p&gt;I'm not sure we all see colors the same way (Is my red the same as your red?). &lt;/p&gt;

&lt;p&gt;Some people are color-blind (and for them, I'm contrast-blind).&lt;/p&gt;

&lt;p&gt;How do people even work with colors?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>help</category>
      <category>css</category>
      <category>design</category>
    </item>
    <item>
      <title>Can CSS color variables depend on each other? Help me fight off CSS preprocessors.</title>
      <dc:creator>Arnav Bansal</dc:creator>
      <pubDate>Fri, 23 Nov 2018 10:47:40 +0000</pubDate>
      <link>https://forem.com/itsarnavb/can-css-color-variables-depend-on-each-other-help-me-fight-off-css-preprocessors-4fl9</link>
      <guid>https://forem.com/itsarnavb/can-css-color-variables-depend-on-each-other-help-me-fight-off-css-preprocessors-4fl9</guid>
      <description>&lt;p&gt;Here, --dark-highlight is a brighter version of --dark. Is there a way I can set --dark-highlight to be dependent on --dark, where it automatically uses the same hue, saturation, and alpha values, but increases the lightness by 5%&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root {
  --dark: hsla(209, 28%, 6%, 1);
  --dark-highlight: hsla(209, 28%, 11%, 1);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, what's a good guide to the new CSS features?&lt;/p&gt;

</description>
      <category>help</category>
      <category>css</category>
      <category>discuss</category>
    </item>
    <item>
      <title>How do you customize service workers for Angular 6+? I'm making use of Firebase, and it needs a service worker.</title>
      <dc:creator>Arnav Bansal</dc:creator>
      <pubDate>Tue, 20 Nov 2018 14:42:04 +0000</pubDate>
      <link>https://forem.com/itsarnavb/how-do-you-customize-service-workers-for-angular-6-im-making-use-of-firebase-and-it-needs-a-service-worker-4ol0</link>
      <guid>https://forem.com/itsarnavb/how-do-you-customize-service-workers-for-angular-6-im-making-use-of-firebase-and-it-needs-a-service-worker-4ol0</guid>
      <description>&lt;p&gt;I'm using Ionic 4/Angular 6 with Firebase.&lt;/p&gt;

&lt;p&gt;I enabled Angular with this command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ng add @angular/pwa@v6-lts --project app&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It generated ngsw-config.json, which generates a service worker in production. But how do I add code to the service worker?&lt;/p&gt;

&lt;p&gt;I'm adding Firebase to it, to make use of Firebase Cloud Messaging. &lt;/p&gt;

</description>
      <category>help</category>
      <category>pwa</category>
      <category>webdev</category>
      <category>angular</category>
    </item>
    <item>
      <title>What are the advantages of using Pub/Sub instead of directly triggering through HTTP (Google Cloud Scheduler)?</title>
      <dc:creator>Arnav Bansal</dc:creator>
      <pubDate>Mon, 19 Nov 2018 13:02:36 +0000</pubDate>
      <link>https://forem.com/itsarnavb/what-are-the-advantages-of-using-pubsub-instead-of-directly-triggering-through-http-google-cloud-scheduler-2anm</link>
      <guid>https://forem.com/itsarnavb/what-are-the-advantages-of-using-pubsub-instead-of-directly-triggering-through-http-google-cloud-scheduler-2anm</guid>
      <description>&lt;p&gt;My guess: security.&lt;/p&gt;

&lt;p&gt;Cloud Scheduler doesn't seem to provide any way to verify the request source. If the endpoint is discovered, users could trigger the endpoint outside schedule.&lt;/p&gt;

&lt;p&gt;Are there any other benefits of using pub/sub?&lt;/p&gt;

&lt;p&gt;Google Cloud Scheduler: &lt;a href="https://cloud.google.com/scheduler/"&gt;https://cloud.google.com/scheduler/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Google Cloud Pub/Sub: &lt;a href="https://cloud.google.com/pubsub/"&gt;https://cloud.google.com/pubsub/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>help</category>
      <category>devops</category>
      <category>webdev</category>
      <category>gcp</category>
    </item>
    <item>
      <title>I'm upgrading a React frontend that's an year old. My current process is slow and painful. How could I speed it up?</title>
      <dc:creator>Arnav Bansal</dc:creator>
      <pubDate>Mon, 22 Oct 2018 06:24:44 +0000</pubDate>
      <link>https://forem.com/itsarnavb/im-upgrading-a-react-frontend-thats-an-year-old-my-current-process-is-slow-and-painful-how-could-i-speed-it-up-4bc3</link>
      <guid>https://forem.com/itsarnavb/im-upgrading-a-react-frontend-thats-an-year-old-my-current-process-is-slow-and-painful-how-could-i-speed-it-up-4bc3</guid>
      <description>&lt;p&gt;I'm working on a React 15 project that compiles in Node 6, and am updating it to React 16/Node 10.&lt;/p&gt;

&lt;p&gt;My current process: I use &lt;code&gt;npm outdated&lt;/code&gt; to find old packages and update them to newer versions. I run &lt;code&gt;npm install&lt;/code&gt; after that, and then load the frontend with webpack.&lt;/p&gt;

&lt;p&gt;I've found that there are several packages that might be deeply interdependent, and updating one without making changes or updating other packages breaks the frontend with an error in 'linkClass.js'&lt;/p&gt;

&lt;p&gt;I'd appreciate any help. &lt;/p&gt;

</description>
      <category>help</category>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>I'm looking for an embeddedable code editor. Preferably one that looks great.</title>
      <dc:creator>Arnav Bansal</dc:creator>
      <pubDate>Wed, 17 Oct 2018 05:01:45 +0000</pubDate>
      <link>https://forem.com/itsarnavb/im-looking-for-an-embeddedable-code-editor-preferably-one-that-looks-great-40m9</link>
      <guid>https://forem.com/itsarnavb/im-looking-for-an-embeddedable-code-editor-preferably-one-that-looks-great-40m9</guid>
      <description>&lt;p&gt;I'm creating an online demo for a web technology. I need an editor that can highlight at least JavaScript. Edit functionality isn't a must.&lt;/p&gt;

&lt;p&gt;But it must look fabulous.&lt;/p&gt;

&lt;p&gt;What's the go-to editor for this?&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>discuss</category>
      <category>help</category>
    </item>
    <item>
      <title>Why you need to know about the Lindy effect, as a developer.</title>
      <dc:creator>Arnav Bansal</dc:creator>
      <pubDate>Mon, 15 Oct 2018 20:15:35 +0000</pubDate>
      <link>https://forem.com/itsarnavb/why-you-need-to-know-about-the-lindy-effect-as-a-developer-26nf</link>
      <guid>https://forem.com/itsarnavb/why-you-need-to-know-about-the-lindy-effect-as-a-developer-26nf</guid>
      <description>&lt;p&gt;Age affects living beings negatively. Younger organisms can be expected to outlast older ones.&lt;/p&gt;

&lt;p&gt;But non-perishable things like ideas, music, and technology behave differently. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If a book has been in print for forty years, I can expect it to be in print for another forty years. But, and that is the main difference, if it survives another decade, then it will be expected to be in print another fifty years. This, simply, as a rule, tells you why things that have been around for a long time are not "aging" like persons, but "aging" in reverse. Every year that passes without extinction doubles the additional life expectancy. This is an indicator of some robustness. The robustness of an item is proportional to its life!&lt;br&gt;
-Nassim Taleb&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The longer technologies have survived, the longer they are likely to stay alive. This is called the &lt;a href="https://en.wikipedia.org/wiki/Lindy_effect"&gt;Lindy effect&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It's worth applying the idea of the Lindy effect to something like the JavaScript ecosystem, and programming in general. Frameworks come and frameworks go. Languages behave similarly, although to a lesser extent. But algorithms and the math underneath them doesn't change much.&lt;/p&gt;

&lt;p&gt;If you're building something, especially if for the long term, the Lindy effect might be a good counterbalance to the urge of experimenting with new things.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>career</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
