💻

Some actual code

I'm really enjoying my dev stuff at the moment. There was a bunch of stuff at work about getting my project migrated to the component library, and last minute goalpost moving when we decided it was decided that we weren't going to release it, but that's OK. I got to delete a bunch of stuff and I got to reimplement a component as a freemarker template instead of in Vue, so I was happy.

The latter half of the week was spent working with actual javascript! Can you imagine?!

I had to get form date properties submitting in Unix time, which was fine, just write a new helper function. The first problem was where to apply it, because there's only one form template for the whole CMS plugin, so all the logic for all the forms is in there and it's just this maze of jquery. I got there in the end.

Next problem was that although the date was Unixed, it was still being sent as a string, when the DB expected an integer. This was harder to solve than it seemed on the surface because there's this complex, established workflow that the data goes through on its way to being formulated as the final payload, and it was getting stringified in multiple places. So it didn't matter if it was a number when it came out of my convertToUnix function, or when it was added to the form data object, because it was going to get transformed again downstream, and by the time it got to the last stringify call it was just a key:value pair with no metadata to let me cherry pick.

So I ended up, for this one form-type that's going to the typed DB, adding a replacer function to the stringify method to try and coerce every property to a number on the way through. If it came back as NaN the original string value went in and if not it went into the payload as a number. The only scenario I can think of where this might be a problem is if someone out there has a name that consists entirely of numerals, or something like that. We can cross that bridge when we come to it.

Since I was in a JS state of mind, I finally got around to progressively enhancing the darkmode on my site so that it persists across pages and sessions. I'm really happy with the way that turned out — it's small and clean and integrates well with the way my CSS custom variables work to flip modes without JS. It might even be the first progressive enhancement I've applied to something of my own, just because.

END