Titanium JIRA Archive
Appcelerator Community (AC)

[AC-6452] Alloy custom $model.__transform mapping is broken

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsAlloy
Labelsn/a
ReporterJorge Macias Garcia
AssigneeShak Hossain
Created2019-12-03T08:19:15.000+0000
Updated2019-12-03T22:24:03.000+0000

Description

EDIT: Updated with working error example: This [commit](https://github.com/appcelerator/alloy/commit/0d6a312cfa42d82919b695f38583a31cbedeb9c2#diff-a59a2178e486f81366775c39e5393695) brokes this use case: - Custom mapping object with *$model.__transform* property Example: It's my fault Ewan. Try passing a deep object: {noformat} [ERROR] Script Error { [ERROR] column = 385; [ERROR] line = 49; [ERROR] message = "undefined is not an object (evaluating 'Alloy['Models']['user'].on')"; [ERROR] sourceURL = "file:///Users/jormagar/Library/Developer/CoreSimulator/Devices/E90BCD03-DD1A-4ED4-A53E-E855EAF8D0F7/data/Containers/Bundle/Application/1285D017-A679-4740-AF70-0C257BD62EAF/AlloyDeepBinding.app/alloy/controllers/detail.js"; [ERROR] stack = " at Controller(/alloy/controllers/detail.js:49:385)\n at (/alloy.js:428:53)\n at doClick(/alloy/controllers/index.js:54:27)"; [ERROR] toJSON = ""; [ERROR] } {noformat}
//detail.xml
<Alloy>
  <Window layout="vertical">  
    <Label text="{user.owner.name}" top="50"/>
    <Label text="{user.contributor.name}" top="75"/>
  </Window>
</Alloy>

//index.js
  function onClick() {
    Alloy.createController('MyView', {
      $model: {
        __transform: {
          user: {
            owner: {
              name: 'Bob'
            },
            contributor: {
              name: 'Tom'
            }
          }
        }
      }
    }).getView().open();
  }

$.index.open();

Coming back to the previous code before commit fixes it.

Comments

  1. Ewan Harris 2019-12-03

    [~jormagar] could you elaborate a little more as to what the expected outcome is here, my code is below. When using the latest version of alloy (1.14.5) and building to an iOS simulator, I'm seeing two labels with "Bob" and "Bobson" after clicking on the button, when I revert the referenced commit I see exactly the same. To me the behaviour I'm seeing is expected, am I wrong? Am I creating the test case incorrectly? When
       <Alloy>
       	<Window class="container" >
               <Label onClick="onClick">Hello World</Label>
       	</Window>
       </Alloy>
       
       function onClick() {
       	Alloy.createController('MyView', {
       		$model: {
       		  __transform: {
       			name: 'Bob',
       			surname: 'Bobson'
       		  }
       		}
       	  }).getView().open();
       }
       
       $.index.open();
       
       <Alloy>
         <Window layout="vertical">  
           <Label text="{name}" top="50"/>
           <Label text="{surname}" top="75"/>
         </Window>
       </Alloy>
       
  2. Jorge Macias Garcia 2019-12-03

    It's my fault Ewan. Try passing a deep object: {noformat} [ERROR] Script Error { [ERROR] column = 385; [ERROR] line = 49; [ERROR] message = "undefined is not an object (evaluating 'Alloy['Models']['user'].on')"; [ERROR] sourceURL = "file:///Users/jormagar/Library/Developer/CoreSimulator/Devices/E90BCD03-DD1A-4ED4-A53E-E855EAF8D0F7/data/Containers/Bundle/Application/1285D017-A679-4740-AF70-0C257BD62EAF/AlloyDeepBinding.app/alloy/controllers/detail.js"; [ERROR] stack = " at Controller(/alloy/controllers/detail.js:49:385)\n at (/alloy.js:428:53)\n at doClick(/alloy/controllers/index.js:54:27)"; [ERROR] toJSON = ""; [ERROR] } {noformat}
       //detail.xml
       <Alloy>
         <Window layout="vertical">  
           <Label text="{user.owner.name}" top="50"/>
           <Label text="{user.contributor.name}" top="75"/>
         </Window>
       </Alloy>
       
       //index.js
         function onClick() {
           Alloy.createController('MyView', {
             $model: {
               __transform: {
                 user: {
                   owner: {
                     name: 'Bob'
                   },
                   contributor: {
                     name: 'Tom'
                   }
                 }
               }
             }
           }).getView().open();
         }
       
       $.index.open();
       
       

JSON Source