Now I remember why I do this job…

Today I had one of those days you get as a programmer, when everything coalesces in a perfect way to shine a happy light on the universe. I had a list of bugs and a single feature I wanted to add to my Flex program. The single feature (dynamic filtering based on values in a set of arrays) took me a long time, and I wrestled with it mightily for several hours. I wanted desperately to make a filter which was extensible, which was easy to add new fields to, and passing variables around in Flex is not something I’ve become comfortable with.

So there I was, pounding my head against the thing, frustrated and feeling incompetent, until 4PM when a light shined down upon me from the sky, the scales fell from my eyes, whatever cliche you want to use… and the feature was complete. And when the dust cleared, I realized that 3 of the bugs on my ‘to-do’ list had gotten fixed in the process of creating this feature.

It’s an awesome day when you feel “done” with what you’re working on. I wasn’t even tempted to start on something else… I just basked in the glow of having gotten it done.

For anyone wandering here from flex land who wants to see the code, here it is:

private var filterObj:Object = {this:filterThis,that:filterThat};n// These arrays are populated elsewhere with a list of strings to filter onnprivate var textObj:Object = {this:"",that:""};nprivate function filterAll():void {nvar filtered:Boolean = false;nvar filterType:String;nfor (filterType in filterObj) {nif (filterObj[filterType].length > 0)nfiltered = true;n}nif (filtered) {ndataSet.filterFunction = filterGeneralSet;ndataSet.refresh();n} else {ndataSet.filterFunction = null;ndataSet.refresh();n}nprivate function filterGeneralSet(item:XML):Boolean {nvar filterType:String;nvar element:String;nvar myArray:Array;n// This is an 'and' filter where everything has to match for the element to return truenfor (filterType in filterObj) {nif (filterObj[filterType].length > 0) {nmyArray = filterObj[filterType];nfor each (element in filterObj[filterType]) {nvar itemFilter:String = item.child(filterType)[0];nif (itemFilter != element) {nreturn false;n}n}n}n}nreturn true;n}n

nn

Similar Posts