Titanium JIRA Archive
Alloy (ALOY)

[ALOY-1092] Allow more query options / scope in .tss

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusResolved
ResolutionFixed
Resolution Date2014-10-07T04:17:24.000+0000
Affected Version/sAlloy 1.5.0, Alloy 1.4.1
Fix Version/sAlloy 1.7.0
ComponentsStyling
Labelsn/a
ReporterRick Blalock
AssigneeTim Poulsen
Created2014-07-21T01:24:29.000+0000
Updated2014-10-23T19:47:52.000+0000

Description

The docs state that you have to use Alloy.Globals.* in a .tss query. You can actually use a local function in a controller too, i.e. "#window[if=myFunc()]" and that will work too. What won't work however is basing a query off of params passed to the controller instance. It would work, but the Alloy compiler doesn't allow it - "#window[if=arguments[0].someProp]" This would be a very powerful addition to the new queries available. It technically already works in the runtime code (I hardcoded it and tried it)...but it just won't compile right now because we're not allowed to put those characters in the tss query.

Attachments

FileDateSize
Screen Shot 2014-10-03 at 3.34.28 PM.png2014-10-03T19:58:58.000+0000252219

Comments

  1. Ingo Muschenetz 2014-07-21

    [~rblalock] Which characters is it complaining about? The brackets? Could you escape them?
  2. Tim Poulsen 2014-10-03

    See the attached screen. Even if the arguments\[0\] syntax worked, it would be pointing to the wrong arguments object. Your components are defined inside self-calling functions so arguments correspond to that function's args. My couple of attempts to work around this by using a local function didn't work either.
       function isSomePropertyTrue() {
          return args.someProperty;
          // fails because args has no value when this is run
          // because of hoisting (args exists, but has no value yet)
       }
       
       function isSomePropertyTrue() {
          return Array.prototype.slice.call(arguments)[0].someProperty;
          // fails because it runs in the context of the nested
          // IIFE and thus points to the wrong arguments object
       }
       
    And of course this wouldn't work either, as again it refers to the wrong arguments object
       "#argLabel[if=Array.prototype.slice.call(arguments).pop().someProperty]": {
          text: 'args.someProperty is truthy'
       }
       
  3. Rick Blalock 2014-10-03

    I wouldn't focus on my "arguments[0]" as what should be the solution - the goal of this ticket is not to try to tell you how to provide the solution. The ticket is a request for more query options for TSS...the use case isn't "arguments[0]" but rather providing a scope from which the styles can be dynamic. As an idea for the problem you point out above.., instead of arguments[0] ... what if there was a var __arguments = arguments[0]; put as the first line in the function? That would be assessable inside the closure then. Whatever the implementation is...the request is to allow arguments passed in a controller to determine tss styles.
  4. Tim Poulsen 2014-10-06

    Reopening. I might be able to satisfy both this and ALOY-1037 with the same additions to the Controller() definition.
  5. Tim Poulsen 2014-10-06

    PR https://github.com/appcelerator/alloy/pull/584 Functional test: run the included ALOY\-1092 test app. Click the "Tap for new window" label. In the resulting window should be two labels, one saying the passed property was truthy and the other is present. Edit index.js and change the someProperty argument value to false and rebuild. This time, the child window will have just the first label saying the parameter was falsey.
  6. Feon Sua Xin Miao 2014-10-07

    PR merged.

JSON Source