Skip to content

Instantly share code, notes, and snippets.

@deanlandolt
Created February 5, 2010 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deanlandolt/296118 to your computer and use it in GitHub Desktop.
Save deanlandolt/296118 to your computer and use it in GitHub Desktop.
var JSFile = require("store/js-file").JSFile;
var dataPath = (require("settings").dataFolder || "data") + "/";
var foo = Package("foo");
foo.bar = foo.Package("bar");
foo.bar.baz = foo.bar.SubModel("baz",
JSFile(dataPath + "foo.bar.baz.json"),
{
prototype: {
testMethod: function(){
return this.foo;
}
},
staticMethod: function(id) {
return this.get(id);
},
properties: {
foo: {type: "number"}
},
links: [
{rel: "foo", href: "{foo}"}
]
}
);
exports.Package = function(name, schema){
schema = schema || {};
var entityStores = {};
schema.openObjectStore = function(storeName) {
// handle nested stores with nested paths
var store = entityStores[storeName];
if(store){
return store;
}
};
if (!schema.Package) {
schema.Package = function(name, schema) {
return entityStores[name] = require("model").SubModel(name, {}, schema);
};
}
if (!schema.SubModel) {
schema.SubModel = function(name, store, schema) {
return entityStores[name] = require("model").SubModel(name, store, schema)
};
}
return require("model").Model(name, {}, schema);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment