Meteor Model concept
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
root = global ? window | |
Function::property = (prop, descriptor) -> | |
Object.defineProperty this.prototype, prop, descriptor | |
Function::include = (module) -> | |
for name, value of module | |
@prototype[name] = value | |
Function::extend = (module) -> | |
for name, value of module | |
@[name] = value | |
class Model | |
@ClassMethods: | |
find: (args...) -> | |
@collection.find.apply(@collection, args) | |
findOne: (args...) -> | |
@collection.findOne.apply(@collection, args) | |
insert: (args...) -> | |
@collection.insert.apply(@collection, args) | |
@property "id", get: -> @._id | |
constructor: (attributes) -> | |
@attributes = attributes | |
for name, value of attributes | |
@property = name | |
root.Model = Model | |
class Story extends Model | |
@extend Model.ClassMethods | |
@collection = new Meteor.Collection "stories", transform: (doc) => new @(doc) | |
root.Story = Story |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment