[ALOY-431] Expose Model and Collection class definitions more easily
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Models, Runtime |
Labels | n/a |
Reporter | Tony Lukasavage |
Assignee | Unknown |
Created | 2012-12-18T18:01:10.000+0000 |
Updated | 2018-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)
No comments