Titanium JIRA Archive
Alloy (ALOY)

[ALOY-137] All "model" config and code should be contained in a single file

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusResolved
ResolutionFixed
Resolution Date2012-09-19T23:27:42.000+0000
Affected Version/sn/a
Fix Version/s2012 Sprint 19, Release 3.0.0
ComponentsRuntime, XML
Labelsn/a
ReporterTony Lukasavage
AssigneeRussell McMahon
Created2012-07-26T12:16:56.000+0000
Updated2013-05-01T14:56:12.000+0000

Description

problem

I'd like to make the models actual JS and have them export configurations, as well as custom scripts. Right now having a model.json with the model config and then an optional extra model.js for a custom script feels a bit grafted together, and it's just more for a developer to need to keep track of. I'd rather have a single model.js file with all this information. And since we have the (model) generators at our disposal, I don't think this will be overwhelming for a developer to understand or use.

proposed solution

This is by no means final, but a generated model should probably look more like the below sample. Notes: * "name" and "config" would come from alloy generate model * migrations would be added at compile time, if necessary
var Alloy = require('alloy');
var name = "nameFromGenerate";
var config = {
	"columns": {
		"count": "Int"
	},
	"defaults": {
		"count": 0
	},
	"adapter": {
		"type": "properties",
		"prefix": "app"
	}
};

var Model = Alloy.M(name, config);

///////////////////////////////////////////////////////
///// INSERT CODE HERE TO EXTEND MODEL DEFINITION /////
///////////////////////////////////////////////////////

var Collection = Alloy.Backbone.Collection.extend({model:Model});
Collection.prototype.config = Model.prototype.config;
exports.Model = Model;
exports.Collection = Collection;

Comments

  1. Tony Lukasavage 2012-09-11

    This should be resolved by ALOY-193. Update this ticket if it is not.

JSON Source