<?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>DEV Community: SudoJunior</title>
    <description>The latest articles on DEV Community by SudoJunior (@junior).</description>
    <link>https://dev.to/junior</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%2F98091%2Ff958cdab-184c-42dc-971f-51734f7d7e18.jpeg</url>
      <title>DEV Community: SudoJunior</title>
      <link>https://dev.to/junior</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/junior"/>
    <language>en</language>
    <item>
      <title>Keeping Discord channels up-to-date</title>
      <dc:creator>SudoJunior</dc:creator>
      <pubDate>Fri, 13 Aug 2021 15:51:03 +0000</pubDate>
      <link>https://dev.to/junior/keeping-discord-channels-up-to-date-fgn</link>
      <guid>https://dev.to/junior/keeping-discord-channels-up-to-date-fgn</guid>
      <description>&lt;h2&gt;
  
  
  Disclaimer
&lt;/h2&gt;

&lt;p&gt;This uses &lt;a href="https://npm.im/channel-backup" rel="noopener noreferrer"&gt;&lt;code&gt;channel-backup&lt;/code&gt;&lt;/a&gt; that I have developed and published myself under the 'TinkerStorm' organization over the last year or so. Since its creation, it has gone through 6 iterations, only the most recent iteration being published.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/TinkerStorm" rel="noopener noreferrer"&gt;
        TinkerStorm
      &lt;/a&gt; / &lt;a href="https://github.com/TinkerStorm/channel-backup" rel="noopener noreferrer"&gt;
        channel-backup
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A command line tool to help Community Managers keep their information channels updated.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;channel-backup&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/589de53f0dea25957d34a4015cda4087fceb5c2ecfa13a40bc8b58ea3dffa5b8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636865636b732d7374617475732f54696e6b657253746f726d2f6368616e6e656c2d6261636b75702f6d61696e"&gt;&lt;img src="https://camo.githubusercontent.com/589de53f0dea25957d34a4015cda4087fceb5c2ecfa13a40bc8b58ea3dffa5b8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636865636b732d7374617475732f54696e6b657253746f726d2f6368616e6e656c2d6261636b75702f6d61696e" alt="GitHub branch checks state"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/642fff465840613b20a165197bf76009df8f418988496fc98a572921a9827983/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f54696e6b657253746f726d2f6368616e6e656c2d6261636b7570"&gt;&lt;img src="https://camo.githubusercontent.com/642fff465840613b20a165197bf76009df8f418988496fc98a572921a9827983/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f54696e6b657253746f726d2f6368616e6e656c2d6261636b7570" alt="GitHub repo size"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/23d7796aa622e986ae852e2ae94ccd37d440176b186eb6c961f67ece4d51709d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f54696e6b657253746f726d2f6368616e6e656c2d6261636b75703f7374796c653d736f6369616c"&gt;&lt;img src="https://camo.githubusercontent.com/23d7796aa622e986ae852e2ae94ccd37d440176b186eb6c961f67ece4d51709d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f54696e6b657253746f726d2f6368616e6e656c2d6261636b75703f7374796c653d736f6369616c" alt="GitHub Repo stars"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/e70714516c2c6dd7e9102b7dabccf454917d8af5dbe12097af81538ee1e73a34/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f6368616e6e656c2d6261636b7570"&gt;&lt;img src="https://camo.githubusercontent.com/e70714516c2c6dd7e9102b7dabccf454917d8af5dbe12097af81538ee1e73a34/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f6368616e6e656c2d6261636b7570" alt="npm"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/3ac2a16b42cad76a3ff3e072e9a7b92278c7110dbb4b5564edf8c47bc2f4dc61/68747470733a2f2f696d672e736869656c64732e696f2f6e6f64652f762f6368616e6e656c2d6261636b7570"&gt;&lt;img src="https://camo.githubusercontent.com/3ac2a16b42cad76a3ff3e072e9a7b92278c7110dbb4b5564edf8c47bc2f4dc61/68747470733a2f2f696d672e736869656c64732e696f2f6e6f64652f762f6368616e6e656c2d6261636b7570" alt="node-current"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A command line tool to help Community Managers keep their information channels updated.&lt;/p&gt;
&lt;p&gt;Notes on progress can be found on the &lt;a href="https://github.com/TinkerStorm/channel-backup/projects/1" rel="noopener noreferrer"&gt;project board&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I am aware this program does not follow the regular conventions of an interface, but I have done my best to ensure that it is &lt;em&gt;accessable&lt;/em&gt; with regular scripts like you would use the terminal. &lt;em&gt;That said, I discourage it with upmost concern.&lt;/em&gt; In theory, this can be applied to monorepo setups where multiple channels are setup with webhooks to keep their information up to date, all that would need to be done is run the command across all packages.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Usage&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;cache.json&lt;/code&gt; file that contains message IDs of all messages sent in the previous sequence (local updated). For any data structure files (including &lt;code&gt;yml&lt;/code&gt; and &lt;code&gt;json&lt;/code&gt;) are following the structural pattern of &lt;a href="https://discord.js.org/#/docs/main/stable/typedef/WebhookMessageOptions" rel="nofollow noopener noreferrer"&gt;WebhookMessageOptions (discord.js)&lt;/a&gt;. &lt;code&gt;cache.json&lt;/code&gt; is both fetched and dumped wherever the…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/TinkerStorm/channel-backup" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;





&lt;h2&gt;
  
  
  Problem Theory
&lt;/h2&gt;

&lt;p&gt;The problem most community managers may face when they need to update their information channels is that they have to update it themselves; ask a specific author; or know how to update a bot message using commands, web dashboard, etc.&lt;/p&gt;

&lt;p&gt;While it may be a bit of a stretch to say that I've solved this problem, I think that it opens an opportunity for community members to help with contributions to the information channels instead of being reliant on an individual or selected group of delegates. &lt;em&gt;No harsh feelings towards those people though, I'm sure they do just fine.&lt;/em&gt; 🙂&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Prior to being published, the script was just 180 lines stuffed into one file - which was sometimes iterated upon when I needed to do something &lt;em&gt;new&lt;/em&gt; with it. 😂 I finally decided to motivate myself to publish it as someone had come to me, wanting to set it up on their own community.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Explanation
&lt;/h2&gt;

&lt;p&gt;The config can be setup to use direct file references or glob patterns that match to specific files in sequence. The program is &lt;em&gt;theoretically&lt;/em&gt; accessible from an interface standpoint by importing its method directly into your own scripts, but is preferred from the command line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"$schema"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://github.com/TinkerStorm/channel-backup/raw/main/schemas/config.json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"files"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"./rules/*.md"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;Matching to any markdown file in the 'rules' folder (but no sub-directory).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The webhook can be specified as part of the config if you would prefer to keep it among your staff team, however it isn't preferred. With the release of v1.1.1 yesterday, it added support to set &lt;code&gt;WEBHOOK_URL&lt;/code&gt; as an environment variable to be loaded in.&lt;/p&gt;

&lt;p&gt;A demo of this can be seen on TinkerStorm's &lt;a href="https://github.com/TinkerStorm/community" rel="noopener noreferrer"&gt;community repository&lt;/a&gt;, with it's folders, configurations and matrix run. When dispatched, this is sent directly to the &lt;a href="https://discord.gg/Bb3JQQG" rel="noopener noreferrer"&gt;Discord server&lt;/a&gt;.&lt;/p&gt;



&lt;p&gt;&lt;a href="https://github.com/TinkerStorm/community/runs/3315881832?check_suite_focus=true" rel="noopener noreferrer"&gt;Example workflow run&lt;/a&gt; (expected to expire on Nov 10th, 2021)&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# INFO_CHANNEL_WEBHOOK, ./info/config.json&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; channel-backup-template@1.0.0 sequence
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; channel-backup &lt;span class="s2"&gt;"--config"&lt;/span&gt; &lt;span class="s2"&gt;"./info/config.json"&lt;/span&gt;

Found 4 files &lt;span class="k"&gt;in&lt;/span&gt; ./info/0&lt;span class="k"&gt;*&lt;/span&gt;.md
steps&lt;span class="o"&gt;(&lt;/span&gt;handle-message&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="s1"&gt;'./info/01_welcome.md'&lt;/span&gt; -&amp;gt; &lt;span class="s1"&gt;'875471689432039494'&lt;/span&gt;
steps&lt;span class="o"&gt;(&lt;/span&gt;handle-message&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="s1"&gt;'./info/02_rules.md'&lt;/span&gt; -&amp;gt; &lt;span class="s1"&gt;'875471694070943744'&lt;/span&gt;
steps&lt;span class="o"&gt;(&lt;/span&gt;handle-message&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="s1"&gt;'./info/03_channels.md'&lt;/span&gt; -&amp;gt; &lt;span class="s1"&gt;'875471698718253117'&lt;/span&gt;
steps&lt;span class="o"&gt;(&lt;/span&gt;handle-message&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="s1"&gt;'./info/04_roles.md'&lt;/span&gt; -&amp;gt; &lt;span class="s1"&gt;'875471703394897950'&lt;/span&gt;
step&lt;span class="o"&gt;(&lt;/span&gt;cleanup:update&lt;span class="o"&gt;)&lt;/span&gt; 4 messages.

&lt;span class="c"&gt;# README_CHANNEL_WEBHOOK, ./readme/config.json&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; channel-backup-template@1.0.0 sequence
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; channel-backup &lt;span class="s2"&gt;"--config"&lt;/span&gt; &lt;span class="s2"&gt;"./readme/config.json"&lt;/span&gt;

Found 2 files &lt;span class="k"&gt;in&lt;/span&gt; ./readme/&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="nt"&gt;-projects&lt;/span&gt;.md
Found 1 files &lt;span class="k"&gt;in&lt;/span&gt; ./readme/community-upkeep.md
steps&lt;span class="o"&gt;(&lt;/span&gt;handle-message&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="s1"&gt;'./readme/core-projects.md'&lt;/span&gt; -&amp;gt; &lt;span class="s1"&gt;'875475818036473917'&lt;/span&gt;
steps&lt;span class="o"&gt;(&lt;/span&gt;handle-message&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="s1"&gt;'./readme/side-projects.md'&lt;/span&gt; -&amp;gt; &lt;span class="s1"&gt;'875475822620864584'&lt;/span&gt;
steps&lt;span class="o"&gt;(&lt;/span&gt;handle-message&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="s1"&gt;'./readme/community-upkeep.md'&lt;/span&gt; -&amp;gt; &lt;span class="s1"&gt;'875475827444301825'&lt;/span&gt;
step&lt;span class="o"&gt;(&lt;/span&gt;cleanup:update&lt;span class="o"&gt;)&lt;/span&gt; 3 messages.

&lt;span class="c"&gt;# ---&lt;/span&gt;
&lt;span class="c"&gt;# {if cache.json was modified}&lt;/span&gt;
&lt;span class="c"&gt;# set git name and email, then commit and push&lt;/span&gt;

&lt;span class="o"&gt;[&lt;/span&gt;main 08c120d] auto: Update cache.json
 1 file changed, 1 insertion&lt;span class="o"&gt;(&lt;/span&gt;+&lt;span class="o"&gt;)&lt;/span&gt;, 1 deletion&lt;span class="o"&gt;(&lt;/span&gt;-&lt;span class="o"&gt;)&lt;/span&gt;
To https://github.com/TinkerStorm/community
   6196053..08c120d  main -&amp;gt; main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;As an organization, we intend to expand this further into a more cohesive ecosystem that helps to better connect communities with their members.&lt;/p&gt;

&lt;p&gt;If you want to set this up for your own server, make your own from our &lt;a href="https://github.com/RocketDragon/channel-backup-template" rel="noopener noreferrer"&gt;repository template&lt;/a&gt;. If you want to deploy on a CI workflow, feel free to use &lt;a href="https://github.com/TinkerStorm/community/blob/main/.github/workflows/update.yml" rel="noopener noreferrer"&gt;our deploy workflow&lt;/a&gt; as a reference (which will also add the generated &lt;code&gt;cache.json&lt;/code&gt; back into the repository. If you need any help with setting this up, drop by our &lt;a href="https://discord.gg/Bb3JQQG" rel="noopener noreferrer"&gt;Discord server&lt;/a&gt; and we'll see what we can do.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/RocketDragon" rel="noopener noreferrer"&gt;
        RocketDragon
      &lt;/a&gt; / &lt;a href="https://github.com/RocketDragon/channel-backup-template" rel="noopener noreferrer"&gt;
        channel-backup-template
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A template for channel-backup.
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;



&lt;h3&gt;
  
  
  Other possible uses
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Interval sticky message using GitHub Actions on a cron timer (with &lt;code&gt;--mode replace&lt;/code&gt; active).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Notes
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;I am aware that &lt;a href="https://npm.im/discord.js" rel="noopener noreferrer"&gt;&lt;code&gt;discord.js@v13.x&lt;/code&gt;&lt;/a&gt; requires NodeJS 16.6.x or above, which should be patched with the release of &lt;code&gt;channel-backup@v1.1.2&lt;/code&gt;. &lt;em&gt;Furthermore, we hope to further amend to community commitment by providing a custom webhook interface - designed for this library, which will hopefully support more LTS versions.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you attempt a matrix build and try to add a &lt;code&gt;${{ secrets.* }}&lt;/code&gt; in as part of &lt;code&gt;${{ matrix.* }}&lt;/code&gt;, the workflow will fail. Instead reference the key as part of the matrix and then use &lt;code&gt;${{ secrets[matrix.*] }}&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I have also been made aware that multiple matrix runs cannot run in parallel, for which I have concluded the only way to resolve is to run sequential with &lt;code&gt;max-parallel: 1&lt;/code&gt;. Payload trimming / sanitisation isn't done either, so entities like HTML comments become literal strings.&lt;/p&gt;

&lt;h3&gt;
  
  
  Planned features include:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;GitHub Action Integration
&amp;gt; Partial completion, with workflow demo.&lt;/li&gt;
&lt;li&gt;Payload validation and comparison&lt;/li&gt;
&lt;li&gt;Better cli support&lt;/li&gt;
&lt;li&gt;Better logging&lt;/li&gt;
&lt;li&gt;Unit tests&lt;/li&gt;
&lt;li&gt;Extensive plugin support&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Other possible features:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://discord.dev/interactions/message-components" rel="noopener noreferrer"&gt;Discord Message Components&lt;/a&gt; - Requires application webhook with a server listening&lt;/li&gt;
&lt;li&gt;Multi platform support (only if they have PATCH and DELETE endpoints)

&lt;ul&gt;
&lt;li&gt;Guilded&lt;/li&gt;
&lt;li&gt;&lt;a href="https://api.slack.com/messaging/managing" rel="noopener noreferrer"&gt;Slack&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

</description>
      <category>discord</category>
      <category>node</category>
      <category>npm</category>
    </item>
    <item>
      <title>Class-based Data Model in JavaScript</title>
      <dc:creator>SudoJunior</dc:creator>
      <pubDate>Fri, 21 Jun 2019 20:25:40 +0000</pubDate>
      <link>https://dev.to/junior/class-based-data-model-in-javascript-4fc9</link>
      <guid>https://dev.to/junior/class-based-data-model-in-javascript-4fc9</guid>
      <description>&lt;h1&gt;
  
  
  &lt;em&gt;Foreword&lt;/em&gt;
&lt;/h1&gt;

&lt;p&gt;This post is a direct descendant to another post I made around 6 months ago at the time of writing. It was poorly explained, and required direct class parents to be reinstated through a new instance of the target. I do hope this is an improvement.&lt;/p&gt;

&lt;h1&gt;
  
  
  Concept
&lt;/h1&gt;

&lt;p&gt;The base model &lt;em&gt;has the behavior&lt;/em&gt; of a plugin handler that calls upon its child classes. Though it is not that, I'm sure someone would be more than willing to make it if their project needs it.&lt;/p&gt;

&lt;h1&gt;
  
  
  Scenario
&lt;/h1&gt;

&lt;p&gt;In the ‘source’ reference, there are 3 classes, 2 of which accept the first as a constructor parameter. They further contain get descriptors that reference to the parent where the primary data set is found.&lt;/p&gt;

&lt;p&gt;As a result, you are given 2 paths to the data (from User context).&lt;/p&gt;

&lt;p&gt;1) &lt;code&gt;this.data.admin&lt;/code&gt;: raw unmutated data set connected to the instance.&lt;br&gt;
2) &lt;code&gt;this.admin.data&lt;/code&gt;: ‘child’ class descriptor still connected to primary reference&lt;/p&gt;

&lt;p&gt;From a base class perspective there isn’t much difference between the two, but from the child class perspective if you were to access the dataset without descriptors you would be doing &lt;code&gt;this.user.data.admin&lt;/code&gt; rather than &lt;code&gt;this.data&lt;/code&gt;. A shortcut if anything else.&lt;/p&gt;

&lt;p&gt;The subtle difference between them is of little importance at first, but as your app is likely to evolve, it can allow for data mutations without affecting the data itself. How you choose to mutate it and what you do with it, is for you to decide.&lt;/p&gt;
&lt;h2&gt;
  
  
  UserInventory handling
&lt;/h2&gt;

&lt;p&gt;There are several ways of handling inventory data.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your standard object where &lt;code&gt;{[itemID: string]: number}&lt;/code&gt; is creating an ID map to the amount in the inventory, very simple item storage if you do it right.&lt;/li&gt;
&lt;li&gt;Same as the object above but reference to a secondary model instead of a number.&lt;/li&gt;
&lt;li&gt;Using an array where each of the item meta is independent from each other.&lt;/li&gt;
&lt;li&gt;Using a 2 dimensional array where the itemID is left-joined from another reference, the 2nd value is the amount and the 3rd could be additional item meta. &lt;em&gt;You can switch it round, or drop one; the other or both if you’d like and just have the itemID reference to another part of your app.&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  &lt;del&gt;Static&lt;/del&gt; Instance get descriptors for default object model
&lt;/h2&gt;

&lt;p&gt;The purpose of this is to prevent anyone from ‘accidentally’ changing the default model while the application is running. That’s all. &lt;em&gt;I also like it when my editor knows what I’m trying to do without the extra comments... and interpretation or guesses from others trying to use it for themselves.&lt;/em&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  References
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Original post:&lt;/strong&gt;&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/junior" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F98091%2Ff958cdab-184c-42dc-971f-51734f7d7e18.jpeg" alt="junior"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/junior/random-circular-class-recurrence-1jmn" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;[RANDOM] Circular class recurrence&lt;/h2&gt;
      &lt;h3&gt;SudoJunior ・ Dec 7 '18&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#node&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#discord&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;EDIT (October 8th 2019): A GitHub repository has been created.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/sudojunior" rel="noopener noreferrer"&gt;
        sudojunior
      &lt;/a&gt; / &lt;a href="https://github.com/sudojunior/class-based-programming" rel="noopener noreferrer"&gt;
        class-based-programming
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Data model construction on class abstractions (for languages that have them).
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;class-based-programming&lt;/h1&gt;

&lt;/div&gt;
&lt;p&gt;Data model construction on class abstractions (for languages that have them).&lt;/p&gt;
&lt;p&gt;For the purpose of demonstration, the files contained in this project will not have anything resembling solution metadata. Namely languages including, but not limited to, JavaScript (package.json, package-lock.json, yarn.lock); C# / F# / VB; Rust and Ruby.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Primary Ideals&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;&lt;em&gt;Since there is more than one way to do this, each of the possibilities opens up both good and bad features of each language found here. Not all of these are possible in certain languages, given that they not have access to features used in sibling languages.&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Independant
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[-]&lt;/code&gt; Data caching unlikely&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;One File
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[~]&lt;/code&gt; Depends on module used&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[-]&lt;/code&gt; Asset access may be limited, dependant on export method.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Recall Parent
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[+]&lt;/code&gt; Automatic garbage collection on unused assets&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[-]&lt;/code&gt; Higher rate of class instancing&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Recall Parent (Instance)
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[-]&lt;/code&gt; Likely to cause memory leaks&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[-]&lt;/code&gt; Data loss possible&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/sudojunior/class-based-programming" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


&lt;p&gt;&lt;em&gt;I am not claiming this as my idea, nor do I know of anyone who has done this successfully before me. I am simply using the resources provided to the community to create an application without the need for an ORM, but still provides the flexibility to move forward with features while allowing space to expand and deprecate.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;That said, I do welcome comments to further improve this model of class-based programming in JavaScript.&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Final words
&lt;/h1&gt;

&lt;p&gt;Similar things can be done in Python, C#, Java / Kotlin, Rust, etc. I'll see what I can do to make them myself, but I welcome you to port them over or improve this further as a challenge... if you so wish to accept it.&lt;/p&gt;

&lt;p&gt;I wish you the best of luck in that, whatever you choose to do,&lt;br&gt;
Junior&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.discordapp.com%2Fattachments%2F323921288974303233%2F561895750536003585%2FRattmann.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.discordapp.com%2Fattachments%2F323921288974303233%2F561895750536003585%2FRattmann.jpg" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>[RANDOM] Circular class recurrence</title>
      <dc:creator>SudoJunior</dc:creator>
      <pubDate>Fri, 07 Dec 2018 22:39:33 +0000</pubDate>
      <link>https://dev.to/junior/random-circular-class-recurrence-1jmn</link>
      <guid>https://dev.to/junior/random-circular-class-recurrence-1jmn</guid>
      <description>&lt;p&gt;&lt;em&gt;no actual content just code&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// file: ./src/classes/User/index.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rethinkdb-ts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * @typedef {import('discord.js').User} DiscordUser
 */&lt;/span&gt;

&lt;span class="c1"&gt;// [internal]&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Admin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./Admin.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="cm"&gt;/**
   * @param {DiscordUser} user
   */&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;client&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nf"&gt;r&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nf"&gt;admin&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Admin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;User&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// file: ./src/classes/User/Admin.js&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * @typedef {import('discord.js').User} DiscordUser
 */&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Admin&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="cm"&gt;/**
   * @param {DiscordUser} user
   */&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nf"&gt;_&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;Seed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Seed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Admin&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;efficient? f*ck no&lt;br&gt;
cool? yea, sure&lt;/p&gt;

&lt;p&gt;what does it do?&lt;br&gt;
(in short) it is class file recurrence, where the Admin class is getting the 'seed' file to return to its intended state.&lt;br&gt;
(ref to discord.js) the user class instance is passed through both constructors therefore allowing for deeper recurrence.&lt;br&gt;
this is not singleton programming, if it was i would have passed the class instance through... but i couldn't figure that one out at the time.&lt;/p&gt;

&lt;p&gt;Updated 2019/03/21 13:13 GMT London&lt;br&gt;
Replaced module support for rethinkdb-ts for better type resolving.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>discord</category>
    </item>
  </channel>
</rss>
