Created
February 5, 2010 19:20
-
-
Save deanlandolt/296118 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"} | |
] | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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