Skip to content

Commit

Permalink
added deprecation warning for expr() syntax in TSS files
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylukasavage committed Jan 7, 2013
1 parent 0dae527 commit e9fdc93
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Alloy/commands/compile/compilerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ exports.generateStyleParams = function(styles,classes,id,apiName,extraStyle,theS
if (_.isString(value)) {
var matches = value.match(regex);
if (matches !== null) {
code += prefix + matches[1] + ','; // matched a constant or expr()
code += prefix + matches[1] + ','; // matched a JS expression
} else {
code += prefix + '"' + value + '",'; // just a string
}
Expand Down Expand Up @@ -902,11 +902,12 @@ exports.formatAST = function(ast,config,fn)
function processTssFile(f, manifest) {
var widgetId = manifest && manifest.id ? manifest.id : null;

// Handle "call" ASTs, where we look for expr() syntax
// Handle "call" ASTs
function do_call() {
var name = this[1][1];
var code;
if (name === 'expr') {
logger.warn('expr() in TSS files is deprecated and will be removed in Alloy 0.4.0.');
code = pro.gen_code(this[2][0]);
} else if (name === 'L') {
code = pro.gen_code(this);
Expand Down

7 comments on commit e9fdc93

@jhaynie
Copy link
Contributor

@jhaynie jhaynie commented on e9fdc93 Jan 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an alternative or are we completely removing dynamic abilities?

@tonylukasavage
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative still allows for dynamic runtime values in TSS files, but moves the code out of the TSS files. You'll still have all the power (even more actually) without show-horning code into TSS files. Essentially, anything on the Alloy namespace can be used within the TSS files. So rather than have the code in the TSS file, you can put the code in a more appropriate JS file and then use the values in the TSS file. Like this:

app/alloy.js

Alloy.CFG.someDynamicValue = 12345;

// OR

Alloy.Globals.someGlobalVariable = someFunctionThatNeedsRuntimeInfo();

Then in any TSS file you can use Alloy.CFG.someDynamicValue or Alloy.Globals.someGlobalVariable.

index.tss

"#label": {
    text: Alloy.Globals.someGlobalVariable
}

This will also allow the dynamic value to change over time in the app, something the one-shot expr() syntax couldn't do. Also, expr() in general was really only there originally because we didn't yet have device queries yet. With device queries and access to Titanium constants and localization, expr() becomes much less necessary and desirable.

And a final note is that I wanted the TSS files to be cleaner and to learn from the mistakes of other technologies. Exhibit A: CSS expressions. If you look up CSS expressions, all you find is sites either talking about how they are deprecated/unsupported now and that you should do everything in your power to avoid them for high quality web development.

@jhaynie
Copy link
Contributor

@jhaynie jhaynie commented on e9fdc93 Jan 9, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really nice. Good work.

@jhaynie
Copy link
Contributor

@jhaynie jhaynie commented on e9fdc93 Jan 9, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, do we have a doc ticket open for the doc team on this yet? this is very powerful feature.

@tonylukasavage
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet, but I'm planning to spend time with Arthur and Ben this week to discuss a few other very important doc updates and changes.

@tonylukasavage
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grantges
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is HUGE - Gamestop has been really vocal about leveraging some dynamic capability (or just even using standard variables) within styles.

Can I suggest that we add a more suitable object for this in the Alloy namespace = Alloy.Styles seems like it would be ideal. Globals and CFG don't seem to have the right context. Not a huge issue but for the sake of clarity. Also as we were talking about moving to dynamic theming of the app during runtime, this might create a place for that future functionality as well.

Please sign in to comment.