TypeError: Cannot read properties of null (reading ‘length’)

Being the Javascript newbie that I am…
Javascript errors are still a mystery, more so if using Chrome/Chromium.
With Firefox the error was actually more clear.

TypeError: Cannot read properties of null (reading 'length')
means you have a variable that you’re checking it’s property ‘length’ to be a certain value but the variable is null.

Explanation:

In this case localStorage’s ‘urls’ key or rather value of the ‘urls’ key was empty and JSON.parse transformed that to null.
So if you check for urls.length to be greater than 0, you can’t do it and receive this error message.

How do you solve it?

This is the Javascript (and Typescript) way to check if a variable isn’t null and then check its property if it isn’t.
I know, logically this makes no sense, because it’s a logical AND. But hey, it’s Javascript so you don’t have to understand, you have to believe. 😉 HTH

Using gin with pongo2/v4 and embedded templates

You’d like to use pongo2/v4 with gin and embed templates with go:embed.

I’m using cobra for my cli parsing and commands.
So

edit cmd/ui.go

ui/templates.go

ui/templates/base.html.twig

ui/templates/layout.html.twig

ui/templates/index.html.twig

and finally run

to download packages

What have we done?

  • In ui/templates.go we said that the directory templates, which is a subdirectory of ui/ should be embedded as the exported variable Templates
  • In line 36 of cmd/ui.go we imported that variable and stripped it of its templates/ prefix
  • line 41 we turned that into a HttpFileSystem and passed that to pongo2’s FileSystemLoader
  • line 42 then creates a renderer that is compatible with pongo2/v4
  • line 43 we assign that renderer to be gin’s HTML renderer

Any questions -> leave a comment

Quasar v2 create re-usable js file with vue3

I had a little problem migrating Quasar v1 to v2. I wanted to have a re-usable (importable) .js file that I could import in every SFC.
This particular case used i18n.

I create a directory lib under the src dir.
Since this .js file was to set the default menu items in every SFC I named it defaultItems.js.
So it lives in src/lib/defaultItems.js

The content of the file

You see a bunch of things.

import { useStore } from 'vuex'
and
import { useI18n } from 'vue-i18n';

Vue3 has this new use* functions that allow for instance vuex to be accessed via useStore() or vue-i18n to be accessed via useI18n() anywhere.

So that’s pretty simple.

You can now import the defaultItems.js file in your SFC.

Of course now that I see this, it’s wrong to store the translated text in the vuex store. Only the references should be stored there and the translation should happen in the display component.
e.g. the label shouldn’t be i18n.t(‘sidebar.home’) but only ‘sidebar.home’ and later do $t() or <v-t> in the component

PcEngines APU4D4 erst 2022

Ich wollte mir gerade ein Board bestellen mit GehÀuse usw. ein PcEngines Apu4d4 (weil die Apu2c4 gibts wohl nicht mehr).
Nichts ist lieferbar. Alles aufverkauft scheinbar, oder wird da gehortet?

Wie war das noch im Kommunismus? Lange Schlangen, keine Produkte verfĂŒgbar.
Haben wir darum denselben aufgegeben um nicht nur unfreier zu sein und ĂŒberwachter sondern im Endeffekt dort anzukommen wo der Kommunismus im negativen Sinn war?

Heute gehört wenigen das meiste statt wie im Kommunismus vielen alles.
Alles kostet Geld im Gegensatz zum Kommunismus – alles ist frei weil ja im Volkseigentum.
Bewegungsfreiheit? Tja ohne Geld kannst du auch nicht reisen, als Hartz4EmpfĂ€nger must du sogar um Erlaubnis bitten um verreisen zu dĂŒrfen.

Wird es nicht Zeit umzuschwenken? Gerade lese ich China hat alle CryptowĂ€hrungen fĂŒr illegal erklĂ€rt. BRAVO! Und vor einigen Tagen hat es versprochen keine Kohlekraftwerke mehr zu bauen.
Die machen was in Punkto Klima.
Blöd nur das die Sprache so schwer zu lernen ist.