Sunday, March 31, 2013

Fun vs. the truth

I heard or overheard "Easter bunny is a lie... just like... parents lied about religion" three times this week.

I have children.  They need to know that Easter is to celebrate the day Christ rose from the dead.   They should also have easter day fun.   I enjoy waking up, hunting for colorfully painted eggs, eating a big breakfast then going to church.  It is fun!  I do not want to take away their fun.

I never tell them the easter bunny is real or true. It is not!  It's just fun.  Santa Clause, the Easter Bunny, and the Tooth Fairy are probably not the false prophets mentioned in the Bible.

The connection between the Easter Bunny and Easter?  Here in Virginia we start seeing bunnies in the spring. Grandma saw the first one of the season this morning, Easter morning! Signs of new life? I think every child knows chickens come from eggs.  New Life!  Spring and the resurrection have things in common.

To believe or not to believe; every American gets to make that choice for themselves.  Not to believe something because of the easter bunny? I can't believe that.

Thursday, March 28, 2013

Optimizing Directives in AngularJs

Not many apps require this optimization technique. If the directive is applied 50+ times on a page, consider this technique.

I am displaying xml on a page.  When the user clicks on a node, a drop down list (ddl) is displayed.

Initially my app rendered all nodes with a ddl.  The ddl was hidden.  This significantly increased the size of my dom. Most nodes are not selected for editing.  Wasted work compiling on page load.

Using $compile(htmlStr)(scope) AngularJS compiles and renders ddl's only after the user clicks to edit.

HtmlStr is a string including the ng-select expression.  Be sure to have all data loaded in scope before compiling.

I apologize for the lack of code, phone bogging today.

Another optimization would be one list on the page used by all directives.  This would not support simultaneous editing.

Tuesday, March 26, 2013

Scrum poker

A round of Scrum Poker is good for any project.  It's always fun to see how new participants come to terms with relative time measurements. "What is 3... hours, days, weeks?"  Then the discussion about how humans are good at relative measurement.  "Is a marker bigger than a pencil? Yes."  If task A is bigger or more difficult than task B, assign it a higher number. Relationships between the numbering scale and time can be asserted after enough data is collected.

Saturday, March 23, 2013

jSad- jQuery on Small Documents

Given a small xml fragment with namespaces, jQuery selectors fail. Defined, a small xml fragment has a root node and a few children.
The fix is to wrap the fragment in a root elemement do the work, then remove the root element.

Wednesday, March 20, 2013

Constants in AngularJs

Angular has a compile process.  Functions might not be ready when directives need them.  Constants are compiled and evaluated earlier than directives.  The constants defined in mySettings is ready for use by directives when called.
Using constants also helps keep some order in the app. I'm using the same names or interface for the constants on each page.  Some constants such as apiUri are referenced five or six times on each page.  Each page has different values, but the interface is the same.  I prefer constants over hard coding strings.

The directive shown below is not my service, don't let the name fool you.  I use it to call an xml file.  Then directives with lower priorities generate behavioral aspects for the page.  My app is more document centric than model centric.  The MVC is very light. 

//root module

var myApp = angular.module('CoiApp',[]);
//constants
myApp.constant('mySettings', {
    apiUri: '/api/foo',
    nsUri: 'mySite/foo.xsd',
    nsPrefix: 's'
});

//directive using constants, mySettings is injected in using the minification safe method.
mayApp.directive('getById',
    ['$log', '$location', 'mySettings'
        function ($log, $location, mySettings) {
            return {
                priority: 500,
                templateUrl: mySettings.apiUri +'/' +  ($location.search()).myid
            };
}]);

Saturday, March 16, 2013

XML is Too Complicated

I can't believe I just said that 'XML is too complicated', but it must be true!  By capital XML I mean, xml, xsl, xsd, and xpath or xquery.  Raw xml is easy enough just angle brackets.  But everything else is so marginally supported.  Why? Must be too complicated? Right?
Let's compare xml to json as a base. Json is basically a key value pairs and arrays. Xml, the object model (DOM); namespaces, elements, and attributes. But each of these needs to be broken down into other parts.  Elements alone have start tag, tag name, end tag, text, and children.  The permutations start to really add up, making full implementation of the supporting technologies difficult.  I find xml easy and intuitive, but I don't build the tools to support xml.  The full lack of support is an impedance on workflow today.

Thursday, March 7, 2013

(jBAD)- jQuery on Big A$$ Documents

Take a look at the metrics on vanilla-js.com.  jQuery, while easy to use is not exactly fast.  That is not a slam on jQuery. In any app as functionality increases speed decreases.  When working with big documents mix vanilla-js with jQuery for best results.

var xmlFrag = document.getElementById(“12345”);
$(“f\\:user > f\\:name”,xmlFrag);
In the code sample above I'm searching xml with namespaces.  My namespace prefix is f.  I know the Id of the root node from an event (code not shown).  I'm using plain old javascript getElementById to quickly grab that dom node and create a fragment.  Then passing just that fragment of xml into jQuery for further processing.

<f:user xmlns:f="user.xsd"><f:name></f:name></f:user>