Titanium JIRA Archive
Alloy (ALOY)

[ALOY-431] Expose Model and Collection class definitions more easily

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsModels, Runtime
Labelsn/a
ReporterTony Lukasavage
AssigneeUnknown
Created2012-12-18T18:01:10.000+0000
Updated2018-03-07T22:26:05.000+0000

Description

Developers right now technically have access to the class definitions of models and collections. If a developer had a model/collection named "items", they could access the class definition like this:
var ModelClass = require('alloy/models/Items').Model;
var CollectionClass = require('alloy/models/Items').Collection;

// you can access class properties and functions
CollectionClass.someFunctionOnTheCollectionClass();

// you can then use Backbone inheritance 
var DerivedModelClass = ModelClass.extend({
    // properties and functions to add to the class
});

// and then create an instance
var instance = new DerivedModelClass({ /* init object */ });
Notice that the initial require() needs the model name to have its first letter capitalized. We should introduce a simpler syntax for accessing the class itself. Some ideas: * - *Alloy.Models.Items* (might be confusing with the corresponding global instance being created at Alloy.Model.items) * - *Alloy.getModel('items')* (take the old deprecated function and have it return the class instead of an instance)

Comments

No comments

JSON Source