When I was getting familar with Atlas, something that struck me was how nicely you could use it to gather up all the random bits of script on your website and factor them into nice reusable blocks of code. This scenario was one of the driving forces behind my design of the Toolkit classes – I wanted to make it as easy as possible to go from some blob of script to a reusable component. Even so, I don’t think I’ve given this scenario enough visibility.
Even if you’re not a “component developer”, there’s something to look at here. Recently, I was building some websites as some side projects and found myself using the Toolkit to build components, not because I really intented a given bit of functionality to be reusable, but simply to put it into a nice format that was easier to maintain, track, and debug. What ended up happening though, in almost every case, was this enabled me to reuse the code in ways I hadn’t intended, and to really simplify the structure of the website itself. In any case, building out my client script this way was definitely less total work than having it just sitting as JS files or inline.
A great example of this in the Toolkit is the ConfirmButtonExtender. Even though the bare-bones script for this functionality is just a few lines of code, having it consolidated in one place is really nice. I can easily apply the behavior to all the components I want and, even better, I can modify it at some point in the future in one place, rebuild, and have my whole website pick it up.
What got me thinking about this was this excellent blog post walkthrough of exactly this by Damian. He does a fantastic job of not only buliding the case for this stuff but providing a step-by-step example. It’s worth a read!