asp.net mvc 3 - 3rd Party JSON with Google Closure in Advanced Mode? -
i'm having trouble advanced optimization of closure compiler trying rename json properties. using rich autocomplete control , feeding json returned action contains contacts name , phone properties. closure compiler renaming name , phone in methods , templates. in method can around using property name string key object, don't know how templates:
/** * @param {{name: string, phone: string}} item item returned autocomplete */ example.makerow = function (item) { item.render = function (node, token) { // item.phone + '</div>' + '<div style="float: right">' + item.name; node.innerhtml = template.autocomplete(item); } } my json object has full names of properties "name" , "phone" function re-writes them "hx" , "az". ditto template:
{namespace template} /** * single row in example autocomplete box. * @param phone contact's phone number * @param name contact's full name */ {template .autocomplete} {$phone}<span style="padding-left: 15px">{$name} {/template} if add these 2 lines start of makerow function, sets condensed names proper values original names:
item.name = item['name']; item.phone = item['phone']; doing seems wasteful both space-wise , performance-wise. have no intention of doing json objects, plan on having lot in applications in future (this simple test). don't have clue how map new names old. can create sourcemap, there bunch of numbers , don't know mean. if figure out maybe write easy property mapper in c# create dynamic objects shortened names.
if have use simple optimization mode such hard given lengthy names of objects , properties in closure library. should simple. think great if had @json tag instead of @param prevent renaming, or other signal @param not rename object's properties:
* @param {{name: string, phone: string}} item item returned autocomplete would become
* @json {{name: string, phone: string}} item item returned autocomplete i found can make property names stay same creating externs.js file , specifying @ compile time:
var foo = {}; foo.name = null; foo.phone = null; i think object properties names not compressed, true? guess write helpers produce long list of property names given classes use. might use dynamic types things , afraid might forget or misspell property name.
edit:
not project wants support, recommend taking object parameter this:
{namespace template} /** * single row in example autocomplete box. * @param json object actual values */ {template .autocomplete} {$json['phone']}<span style="padding-left: 15px">{$json['name']} {/template}
the closest thing closure supports extern. create extern json object, pass compiler , work wish. here's basic example case:
/** @constructor */ function autocompleteitem() {} /** @type {string} */ autocompleteitem.prototype.name; /** @type {string} */ autocompleteitem.prototype.phone; note common , quite acceptable access json properties using bracket syntax (object['name']) -- compile object.name in final output, , avoids having create extern.
Comments
Post a Comment