|
title: Put the knife down and take a green herb, dude. |
descrip: One feller's views on the state of everyday computer science & its application (and now, OTHER STUFF) who isn't rich enough to shell out for www.myfreakinfirst-andlast-name.com Using 89% of the same design the blog had in 2001. |
||||
|
FOR ENTERTAINMENT PURPOSES ONLY!!!
Back-up your data and, when you bike, always wear white. As an Amazon Associate, I earn from qualifying purchases. Affiliate links in green. |
|||||
|
x
MarkUpDown is the best Markdown editor for professionals on Windows 10. It includes two-pane live preview, in-app uploads to imgur for image hosting, and MultiMarkdown table support. Features you won't find anywhere else include...
You've wasted more than $15 of your time looking for a great Markdown editor. Stop looking. MarkUpDown is the app you're looking for. Learn more or head over to the 'Store now! |
|||||
| Thursday, October 27, 2022 | |||||
|
A note to self I might have already noted... myself.
So look, I'm at a company where much of the app is still in AngularJS. The downside is that this reminds me of a post I'd shared before that said:
That's not wrong. More experience in AngularJS isn't making me more employable at this point unless I want to work in the small subset of positions that plan to continue using it well past its dead-on date. Which, again, was January of this year. That admission aside, as I've mentioned before, there is, however, a practical advantage: Most of the questions I have when I'm developing have nearly canonical answers. I mean, have you seen StackOverflow's blog on the Next.JS conference? The blog's title is "Goodbye Webpack, hello Turbopack!". With just a little bit of exaggeration, webpack, we barely knew ye. I was looking to get us to a React stack, and I'd initially liked this "minimal" build tool suite over at 2ality. Okay, okay, it's been over three years, but it's now kaput. Gone. Snowpack is dead. I'd heard a bit about ViteJS already a bit from my RSS sub to Shawn Wildermuth's blog, and sure enough that's what Snowpack says to use now. If I'd learned Snowpack inside and out (not that it was tough to learn, and I've been playing with it on and off for a few years), that'd be nearly wasted time now. Look, it's fine to need to keep up a little, it's not like .NET 6 doesn't have a decent amount of new stuff (does it though?), and maybe it's just that I've been around long enough to see things change several times, but it doesn't really have to, does it? There are database admins who haven't needed to learn anything exceptional for their whole career. I mean, look, it's not like our buddy Mr. Dave hasn't kept things moving, but it ain't client-side JavaScript. He's had a chance to get good at what he does, to really drill-down and understand rdbms engines. Okay, yes. I'm a little jealous. ๐ And if I haven't mentioned it before, I'm pretty sure it's because of conferences, YouTube, and Twitter. Everybody who wants to be a bleeding edge type can be, and they all race each other to be the new expert of something nobody else can be yet because it was just released. God made humans, but constantly evolving tech stacks made humans equal[ly clueless]. That said, I do need to write my follow-up to my intro to why we're using transpilation-free Preact. Preact really is a wonderful bridge from a hopelessly out of date client-side app to, well, at least a TypeScript-powered React refactor. Need to develop something new now but can't, for whatever reason, create all new tooling? If you can limit support to IE 9+ or so, Preact (with hooks) is your stack. We've used Preact with Enzyme to create a tested, cradle-to-grave page with a reasonably complex UI and have it running well right smack in the middle of an AngularJS app. Set down new work in Preact now, start eating from the top with React, and when they meet in the middle, it's a very quick port. So maybe I won't need to remember that cheat to get all directives, constants, etc out of an AngularJS site for too long. But when I forget again, at least I'll know I've got it sitting here. Labels: angularjs, enzyme, noteToSelf, obsolescence, preact, vitejs posted by ruffin at 10/27/2022 04:44:00 PM |
|||||
| Friday, May 20, 2022 | |||||
Step 1: How I chose ReactI'm working for a company that has a lot of legacy code, where "legacy" means "nothing on the client newer than AngularJS". Recently, I essentially volunteered to figure out how to stop building more technical debt by proposing a "modern" JavaScript templating engine (and associated tools) to use going forward for new feature work. But since there's very little pure greenfield work for us in the near future -- and plenty of new features on the backlog -- my solution needed to be able to operate in a lot of different environments without causing ramp-up headaches for each new team of developers. Finding a solution to that is the real challenge I'm going to describe here. I should note that, even in a working museum of obsolete code, the idea isn't and shouldn't be to toss the legacy code and start over, no matter how tempting that might feel. As Spolsky said years ago...
In brief, you want to keep as much as your legacy code running as is realistically possible, refactoring it as your resources and priorities allow. I've split my response into two posts.
What follows is part 1... Read more ยปposted by ruffin at 5/20/2022 03:20:00 PM |
|||||
| Thursday, May 20, 2021 | |||||
|
I finally found some videos that talk directly to making an AngularJS site [sic] play nicely with TypeScript (Pluralsight pay-to-play. You can get a free trial, but make sure you select Premium level for your trial or you'll be out of luck). Looks like there was a nice little period where Angular2 had not offiially been released, but TypeScript was already reaonsably mature.
So I’m running through the tutorial, and hit the section on Providers. I admittedly hadn’t used them before, and very quickly learned why: Usually you can use a specialized version of a Provider to do what you need, like a Service or Factory. Providers are conventionally used for things that are reused in multiple apps and might need a domain specific tweak as it’s spun up in each specific app's context.
You know, for instance...
I mean, I'm all for a little humor in a tutorial, but can we get something closer to a real world example for the docs? I mean, I'm not a big fan of PhoneCat app either, since it's just a (now hilariously dated) commercial for Android phones, which is better (?) but so self-serving as to make me wonder. Angular.io's Heroes app is actually pretty close to the right speed. Honestly, the AngularJS docs in general have left me a little disappointed. Guess in a perfect world, that wouldn't be a problem. Sometimes you gotta know the bugs to ship and which JavaScript frameworks to let die. Labels: angularjs, wait what? posted by Jalindrine at 5/20/2021 01:54:00 PM |
|||||
| Wednesday, April 14, 2021 | |||||
|
Any time I forget something more than once, I should probably blog about it. Saves me time looking for a comment on SO I put on an answer I particularly appreciated. Because I've forgotten this particular something more than once, let's return to our time machine, travel back to AngularJS land again, and leave some notes. What's an "ampersand binding" in AngularJS?Essentially, an ampersand binding allows you to mark that you're passing an event handler function to a custom component. Here's one mention in the AngularJS docs:
(There may be a better reference in the docs, but man it's hard to google an ampersand. They could have also ensured something that made it easier to find, like if it had a clear name similar to "ampersand component binding", but the AngularJS folk weren't nice enough to do that either afacit.) Here's some example code [of mine :shudder:] that uses it: In this case, we've got a custom checkbox component that supports tristate. Specifically, that means it's a wrapper that enables easy access to checked, unchecked, and indeterminate states (three states, not the usual two. Am I over explaining this? Indeterminate status checkboxes are kinda complicated in vanilla HTML, and this is trying to abstract some of that in a package AngularJS can consume easily. As a freakin' huge proponent of props down, events up, the tristate checkbox is a very black box.
Where the ampersand binding bites youThe problem is that the ampersand binding doesn't give a function for your component's controller that you can call in a conventional sense. If
... you'd never guess how you pass Here's an example (again, this is a real-world example. It's a little more use case specific than I'd like for a perfect demo):
But How do I pass it? Like this: Inside of an object literal? Wait, WTFOMGBBQNSFW!!!!! At first, I would've expected the event handler registration in the template to look like this: ... and the call from within the component to look like this... But it's not. I would have also accepted something in the component that lets you know you're calling a weirdly wrapped event handler prop, something like... That's funky, but it has the benefit of letting you know something funky is going on. I mean, if Um, no. No. Not at all. Instead, we have to pass that and Instead of letting us call the handler directly, AngularJS provides some weird monkeypatching that makes The advantages of the AngularJS ampersand binding conventionIt's not all bad. What's neat about this is that it does allow us to combine jive from the template scope, like our That is, by not limiting the call to the event handler from within the component to the literal event handler signature, we've got a lot more flexibility. We can combine two scopes, custom component controller and template contexts. At the same time, though passing an object literal that maps to parameters named only in a prop definition in a template file might be more flexible, it's an extremely unintuitive, indiscoverable convention. That we were establishing a new convention and why really didn't click for me until I understood how the new convention was useful -- precisely so that we could mix parent template and component controller scopes like this. Put another way...If that didn't click, here's a good explanation from superluminary on SO of the [unintuitive] way an ampersand binding in AngularJS works, and is what finally made how things worked click in my head. Once I had this convention straight and was able to combine it with the advantages of in-template parameter mixing, I was finally an ampersand binding expert. (Until I forgot.) Anyhow, from that answer:
It's almost like AngularJS said, "I see your event handler, and I'm going to raise you this monkeypatch..." (Actually, that's functionally speaking exactly what AngularJS does, though there's another round of mapping after you compiled the template to code before you can have What people usually end up doing... and why you shouldn'tThe weird part is that you can skip this new convention entirely if you pass the event handler by reference. It's cheating, I'm pretty sure the AngularJS wishes you wouldn't, and you lose a lot of flexibility, but I can see why people do it. The ampersand binding convention simply isn't easily intuitive. Here's one such example of that "my mind is blown; gimme simple" mentality from krawaller.se:
Then, in your controller, you'd simply call But recall that you now can't do anything clever with your template's scope! As long as the template is something trivial like the Anyhow, I've known the ampersand binding convention long enough to use it and forget it once already, so there's a refresher. Hope that's helpful if you too have been sucked INTO AN ANACHRONISTIC ANGULARJS TIME BOB OMB!!!!1!!! Labels: angularjs, noteToSelf posted by ruffin at 4/14/2021 01:42:00 PM |
|||||
| Monday, February 22, 2021 | |||||
|
Last week I talked a little about using transclusion in AngularJS from a starting primer on the topic to where I still wasn't quite sure how to use it to pass DOM into a uibModal. Here are a few more transclude-related links I rediscovered as I was closing out browser tabs this morning. With any luck, I'll come back and process this jive into something that answers the question I punted on for the time being last week. From What exactly do you do with the transclude function and the clone linking function?:
So that's at least a detailed example of using the transclude function in a You should probably also know the difference between This one I need to read again to understand what's going on precisely, but seems interesting. How to make transcluded template to bind to component scope:
And then to follow back up on Transclusion in Angular UI Modal not working, here's a bit of the answer given:
So, again, I punted and created a reusable modal that expects a specific payload in scope that gets mapped to the body. Here's just the body of the modal to demonstrate (no comments in the live version, natch):
Makes sense, right? So if you need text, list items, then text, you have two Again, not nearly as good as being able to pass any template at all in a call to the modal, but it's doing the job for now. I still feel a little dirty from the hack, though. Labels: angularjs, noteToSelf posted by ruffin at 2/22/2021 10:44:00 AM |
|||||
| Thursday, February 18, 2021 | |||||
|
I think Iโve mentioned Iโm stuck in an AngularJS (Angular 1) codebase for most of my work right now, which isnโt great. The portion of the codebase where I do most of my work is pretty solid, but there are lots of places where it doesnโt fully exploit what AngularJS had to offer.
I donโt love learning all this stuff about AngularJS in 2021, but thatโs the job. ๐ One solution that I keep suggesting is transclusion, which is where you embed html over into a custom component just like you would any other html element's tags.
And each time Iโve promptly forgotten how to use it.
So as a note to self, hereโs a [*coughcough*five-year old*coughcough*] video Iโve found that explains it fairly well:
Youโre welcome for cuing the video up past the annoyingly loud โWHAAAA!!!!โ at the beginning where heโs trying to solidify his self-branding as The Net Ninja.
Well, it turns out there's a lot more to transclusion than I'd hoped. Straight transclusion, where you want to drop html inside of your new custom tags just like they're standard html, and what I was describing before, is pretty much just as advertised. But then there's the situation when you want to have more than one transclusion. Say your custom component has a header, footer, and body. Do you have to parse stuff or can you set up three separate transclusions in your markup? Turns out it's the latter. (This is not covered in the video, above.) So if I have a wacky component like this one:
... and I map it up in my code like this...
... I can drop html into each by doing this...
... and have them pop into the right places. That's neat, I guess. Transclusion and uibModalWhich brings us to my actual use case. What I wanted to do was create One Modal to Rule Them All based on the AngularJS version of bootstrap UI, the $uibModal. And I wanted a component where you could pass in via transclusion the contents for the modal. So, you know, what I want is to take this conventional uibModal template:
... and replace it with something like this...
One problem: Where do I put the html for each transclusion spot? That is, how do I insert the equivalent of this for my modal? I don't really want to put it into a new template each time. That defeats the purpose.
You can't really insert into a template without the template. That is, uibModals aren't in their own component. You're already passing in the entire template, I believe (I'm not an AngularJS expert by any stretch, and I'm not really super psyched to be one where I don't have to, tbh). There are at least two questions on StackOverflow that seem related.
The first one has some code with a method passed to
So I'm still not real sure how to send over transcluded content, but that looks reasonably promising. For now, I've wimped out and created a new modal template type that takes a payload with messages and arrays of list items that the specialized modal turns into a display. For instance, here's the body that takes in
Feels dumb though. Labels: angularjs, noteToSelf posted by Jalindrine at 2/18/2021 09:42:00 AM |
|||||
| Tuesday, February 16, 2021 | |||||
|
This is a note people still stuck in AngularJS-land should probably understand. I see lots of the former in the codebase I've most recently inherited. From codelord.net:
Labels: angularjs, noteToSelf posted by ruffin at 2/16/2021 09:41:00 AM |
|||||
| Wednesday, January 15, 2020 | |||||
|
Here's Today Adventure in Enjoyable AngularJS... I ran into some code from a project that looked give or take like this... namespace.directive('caNavigation', function () { "use strict"; return { restrict: 'E', scope: { inLinks: "@", collapseNav: "=" }, // ... controller: ["$scope", /* more jive */], function ($scope /* more jive */) { $scope.$watch('inLinks', function (value) { // omgwtfbbq? // ... Well, that's @ and = stuff is pretty cryptic, especially since I hadn't used a directive in AngularJS before (Angular 2+, sure, but still learning ye olde AngularJS -- going backwards, I know. Don't forget I had my first run-in with Perl in 2014 [sic]). Let's see what ye olde docs say:
Good heavens, AngularJS. Not the most discoverable. Seems like in AngularJS in general there's lots of magic stringing. Perhaps I shouldn't be surprised, but that doesn't mean I like it. (Here I mean largely inline array notation, which is too hipster by half. I mean, I get that you don't what to lose information when you minimize, but then how about pass real references, not refer to objects by their original names? Sheesh.* ) But let's go a little deeper so that we know what the @ symbol means too. If you've used Angular 2+ (what a failed naming scheme, btw. Why not "Angular.IO" after the website or just NGular or something so that googling this jive would be easier?), you can already see our steady progression to banana boxes. But for now, what a mess.
Guess that works. Let's ignore the =* shallow comparison jive for now. All we've really got is one prop called inLinks that will be passed... um... "in" that we'll update whenever it changes, probably after the page finishes loading and making some resource calls. And sure enough... <li ng-repeat="subLink in link.SubLinks|filter: {ShowInNav: true}" ... That means once we've loaded the correct navigational links for this context, we'll start pushing them into the DOM. And our code makes sense. Much rejoicing. * I actually kinda like AngularJS. It's one clean step away from the inefficient, overly-engineered land of enterprise development Bjarnason discusses and that at least the social convention surrounding Angular 2+ seems to require. But there are a few stupid* conventions like this one that really do AngularJS in conceptually. * Sorry, I've tried to come up with a good synonym, but "stupid" fits here. My earlier use of "hipster" was my kind attept at an alternative, but this stuff really feels a little too much like a first-pass solution to be in a nice, mature templating library. Labels: angularjs, noteToSelf, TIL posted by ruffin at 1/15/2020 05:32:00 AM |
|||||
|
| |||||
|
|
All posts can be accessed here: Just the last year o' posts: |
|||||||||||||||||||||
|
||||||||||||||||||||||
|
|
|
|