Titanium JIRA Archive
Alloy (ALOY)

[ALOY-1599] ALLOY: Model Data binding problem with the first upper case in the model src

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2018-01-16T23:34:18.000+0000
Affected Version/sn/a
Fix Version/sCLI Release 7.0.3
ComponentsModels
Labelsn/a
ReporterSergey Nosenko
AssigneeFeon Sua Xin Miao
Created2018-01-11T11:21:29.000+0000
Updated2018-04-09T23:22:33.000+0000

Description

There is a problem with code generated for Simple Data Binding with the first upper case letter in model name. I have two models defined: app/models/book.js app/models/Task.js I expect that following XMLs will produce the same code:
<Alloy>
	<Model src="book"/>
	<Label>{book.name}</Label>
</Alloy>
<Alloy>
	<Model src="Task"/>
	<Label>{Task.name}</Label>
</Alloy>
But in the first case it is correct:
	Alloy.Models.instance('book');

	$.__views.Book = Ti.UI.createLabel({ id: "Book" });
	$.__views.Book && $.addTopLevelView($.__views.Book);
	var __alloyId2 = function () {
		Alloy['Models']['book'].__transform = _.isFunction(Alloy['Models']['book'].transform) ? Alloy['Models']['book'].transform() : Alloy['Models']['book'].toJSON();$.Book.text = Alloy['Models']['book']['__transform']['name'];
	};Alloy['Models']['book'].on('fetch change destroy', __alloyId2);exports.destroy = function () {
		Alloy['Models']['book'] && Alloy['Models']['book'].off('fetch change destroy', __alloyId2);
	};
and in the second case it is invalid:
	$.__views.Task = Ti.UI.createLabel({ text: $model.__transform.Task.name, id: "Task" });
	$.__views.Task && $.addTopLevelView($.__views.Task);
and I get error $model.__transform is undefined

Attachments

FileDateSize
AlloyModelBindingIssue.zip2018-01-11T11:21:01.000+000022575

Comments

  1. Mostafizur Rahman 2018-01-12

    Hello [~darknos], Thanks for sharing with us. Can you please test the sample code on latest SDK and share the console logs here. Best
  2. Sergey Nosenko 2018-01-12

    {noformat} Alloy 1.11.0 by Appcelerator. The MVC app framework for Titanium. [DEBUG] ----- CONFIGURATION ----- [DEBUG] raw config = "platform=ios" [DEBUG] platform = ios [DEBUG] deploytype = development [DEBUG] project path = /Users/admin/tmp/AlloyModelBindingIssue [DEBUG] app path = /Users/admin/tmp/AlloyModelBindingIssue/app [DEBUG] [DEBUG] ----- CONFIG.JSON ----- [DEBUG] dependencies = {} [INFO] [config.json] config.json unchanged, using cached config.json... [DEBUG] { [DEBUG] "dependencies": {}, [DEBUG] "sourcemap": true, [DEBUG] "autoStyle": false, [DEBUG] "adapters": [ [DEBUG] "localStorage", [DEBUG] "properties", [DEBUG] "sql" [DEBUG] ] [DEBUG] } [DEBUG] [DEBUG] ----- CLEANING RESOURCES ----- [DEBUG] Removing orphaned controllers ... [DEBUG] Removing orphaned models ... [DEBUG] Removing orphaned styles ... [DEBUG] Removing orphaned sync adapters... [DEBUG] Removing orphaned assets and libs... [TRACE] * iphone/ [DEBUG] [DEBUG] ----- BASE RUNTIME FILES ----- [TRACE] SRC_DIR=/Users/admin/.nvm/versions/node/v8.9.1/lib/node_modules/alloy/Alloy/lib [TRACE] Copying SRC_DIR/alloy/widget.js --> Resources/iphone/alloy/widget.js [TRACE] Copying SRC_DIR/alloy/underscore.js --> Resources/iphone/alloy/underscore.js [TRACE] Copying SRC_DIR/alloy/sync/sql.js --> Resources/iphone/alloy/sync/sql.js [TRACE] Copying SRC_DIR/alloy/sync/properties.js --> Resources/iphone/alloy/sync/properties.js [TRACE] Copying SRC_DIR/alloy/sync/localStorage.js --> Resources/iphone/alloy/sync/localStorage.js [TRACE] Copying SRC_DIR/alloy/controllers/BaseController.js --> Resources/iphone/alloy/controllers/BaseController.js [TRACE] [TRACE] Generating ../Resources/iphone/alloy.js [TRACE] SRC_DIR=/Users/admin/.nvm/versions/node/v8.9.1/lib/node_modules/alloy/Alloy/common [TRACE] Copying SRC_DIR/constants.js --> Resources/iphone/alloy/constants.js [TRACE] [DEBUG] Resetting /Users/admin/tmp/AlloyModelBindingIssue/platform/ios [DEBUG] [DEBUG] Resetting /Users/admin/tmp/AlloyModelBindingIssue/i18n [DEBUG] [INFO] ----- MVC GENERATION ----- [INFO] [global style] loading from cache... [INFO] [models/Task.js] model processing... [INFO] [models/book.js] model processing... [INFO] [Book.xml] view processing... [INFO] style: "Book.tss" [INFO] view: "Book.xml" [INFO] controller: "Book.js" [INFO] created: "Resources/iphone/alloy/controllers/Book.js" [INFO] created: "Resources/iphone/alloy/styles/Book.js" [INFO] [Task.xml] view processing... [INFO] style: "Task.tss" [INFO] view: "Task.xml" [INFO] controller: "Task.js" [INFO] created: "Resources/iphone/alloy/controllers/Task.js" [INFO] created: "Resources/iphone/alloy/styles/Task.js" [INFO] [index.xml] view processing... [INFO] style: "index.tss" [INFO] view: "index.xml" [INFO] controller: "index.js" [INFO] created: "Resources/iphone/alloy/controllers/index.js" [INFO] created: "Resources/iphone/alloy/styles/index.js" [INFO] [INFO] [app.js] Titanium entry point processing... [INFO] created: "Resources/iphone/app.js" [INFO] [INFO] ----- OPTIMIZING ----- [INFO] - iphone/alloy.js [INFO] - iphone/alloy/models/Book.js [INFO] - iphone/alloy/models/Task.js [INFO] - iphone/alloy/sync/localStorage.js [INFO] - iphone/alloy/sync/properties.js [INFO] - iphone/alloy/sync/sql.js [TRACE] [TRACE] Benchmarking [TRACE] ------------ [TRACE] [0.41479s] TOTAL [INFO] [INFO] Alloy compiled in 0.41479s {noformat}
  3. Hans Knöchel 2018-01-12

    [~darknos] Naming them lowercase is a naming convention that Alloy requires and recommends. I do not see a reason we should support it, since you also wouldn't expect a Ti.UI.Window be accessible via ti.ui.window. Or am I missing something here?
  4. Sergey Nosenko 2018-01-12

    I told about names of my models in my project. I generated them from mongodb and loopback and everywhere they called from upper case. Seeding, Crop, Pest, Disease, etc. I expect that I can use my local model called "Seeding" in but I can't. But look at the code above - there are completely different code for and or Why?
  5. Sergey Nosenko 2018-01-12

    Hm... {quote} Zachary Litten [1 day ago] All my model names have begun with a capital? I was in the understanding that, that was the proper convention. {quote} {quote} Rene Pot [1 day ago] same here... most my models start with uppercase {quote} But all of us used to use some workarounds. Couple of my friends never use Simple Data Binding because they are sure that it never works correct. I'm shocked that you are not shocked that Alloy generates different code depends from case of the first letter of the file name!
  6. Sergey Nosenko 2018-01-12

    OK. I fixed it and prepared PR. https://github.com/appcelerator/alloy/pull/875 and this is a simple minimal test case: https://github.com/darknos/AlloyBrokenSimpleDataBinding btw, there are no test case with model named with the first upper letter. and it's quite funny because it generates model files with upper letter at start and called it "properCase" :)
       exports.properCase = function(n) {
       	return n.charAt(0).toUpperCase() + n.substring(1);
       };
       
  7. Sergey Nosenko 2018-01-12

    btw, I did some investigation to find a source of issue. 4 years ago code that force to lower case was just a part of [ALOY-932] Improve error messages https://github.com/appcelerator/alloy/commit/1c8e820fc1c3ed174ca46432dcd703a4316b6b9f#diff-ddbdb7300fa15590afdfee9246ac61fcR235 then after two years Fokke decided to use CU.models (that was created only for error reporting) for data binding https://github.com/appcelerator/alloy/commit/378370206762456c8e5debc00a6a93dc278bae14#diff-a59a2178e486f81366775c39e5393695R567 but he missed that it was lower cased. :( So, it is not a "a naming convention that Alloy requires and recommends" but just a bug.
  8. Hans Knöchel 2018-01-13

    [~darknos] Very good research, thank you for that! I'll move it to the Alloy-namespace, so the Alloy team can review your PR. Thanks again!
  9. Sergey Nosenko 2018-03-21

    When I install alloy as npm i -g alloy, I got alloy v 1.11.0 BUT I see that PR above was not included in release. But if I download zip from releases page https://github.com/appcelerator/alloy/archive/1.11.0.zip I see that PR is included. I guess you sent to npm new version without raise up version so now npm has wrong version of alloy :(
  10. Lokesh Choudhary 2018-04-09

    Verified the fix in alloy 1.12.0. Closing.

JSON Source