Permalink
Browse files

added each function to collection

  • Loading branch information...
1 parent 0a6fe56 commit 844823d2c2f792285779f975e44c0bae529b3421 @gushov committed Dec 7, 2012
Showing with 48 additions and 27 deletions.
  1. +6 −4 README.md
  2. +20 −10 dist/lilmodel.js
  3. +2 −2 dist/lilmodel.min.js
  4. +8 −2 lib/lilmodel/collection.js
  5. +7 −7 lib/lilmodel/model.js
  6. +1 −1 package.json
  7. +4 −1 test/lilmodel-test.js
View
@@ -72,11 +72,11 @@ dunkel.save(function (err) {
### _model_.validate()
-### _model_.save(callback)
+### _model_.save(callback, context)
-### _model_.fetch(callback)
+### _model_.fetch(callback, context)
-### _model_.destroy(callback)
+### _model_.destroy(callback, context)
### collection.extend(config)
@@ -90,7 +90,9 @@ dunkel.save(function (err) {
### _collection_.get(query)
-### _collection_.find(query, callback)
+### _collection_.each(callback, context)
+
+### _collection_.find(callback, context)
## License
Copyright (c) 2012 August Hovland
View
@@ -1,4 +1,4 @@
-/*! lilmodel - v0.0.2 - 2012-12-06
+/*! lilmodel - v0.0.3 - 2012-12-07
* Copyright (c) 2012 August Hovland <gushov@gmail.com>; Licensed MIT */
(function (ctx) {
@@ -305,6 +305,10 @@ var validator = {
return typeof value === 'string';
},
+ boolean: function (value) {
+ return typeof value === 'boolean';
+ },
+
length: function (value, min, max) {
var isBigEnough = !min || value.length >= min;
@@ -427,9 +431,15 @@ module.exports = LilObj.extend({
},
- find: function (query, next) {
+ each: function (next, ctx) {
+ _.each(this.$, next, ctx);
+ },
+
+ find: function (next, ctx) {
+
var sync = syncr();
- sync('find', this, next);
+ sync('find', this, next.bind(ctx));
+
}
});
@@ -518,28 +528,28 @@ module.exports = LilObj.extend({
},
- save: function (next) {
+ save: function (next, ctx) {
var sync = syncr();
var method = this.$._id ? 'update' : 'create';
var validation = this.validate();
if (validation.isValid) {
- sync(method, this, next);
+ sync(method, this, next.bind(ctx));
} else {
- next(validation.error, this);
+ next.call(ctx, validation.error, this);
}
},
- fetch: function (next) {
+ fetch: function (next, ctx) {
var sync = syncr();
- sync('fetch', this, next);
+ sync('fetch', this, next.bind(ctx));
},
- destroy: function (next) {
+ destroy: function (next, ctx) {
var sync = syncr();
- sync('delete', this, next);
+ sync('delete', this, next.bind(ctx));
}
});
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -64,9 +64,15 @@ module.exports = LilObj.extend({
},
- find: function (query, next) {
+ each: function (next, ctx) {
+ _.each(this.$, next, ctx);
+ },
+
+ find: function (next, ctx) {
+
var sync = syncr();
- sync('find', this, next);
+ sync('find', this, next.bind(ctx));
+
}
});
View
@@ -78,28 +78,28 @@ module.exports = LilObj.extend({
},
- save: function (next) {
+ save: function (next, ctx) {
var sync = syncr();
var method = this.$._id ? 'update' : 'create';
var validation = this.validate();
if (validation.isValid) {
- sync(method, this, next);
+ sync(method, this, next.bind(ctx));
} else {
- next(validation.error, this);
+ next.call(ctx, validation.error, this);
}
},
- fetch: function (next) {
+ fetch: function (next, ctx) {
var sync = syncr();
- sync('fetch', this, next);
+ sync('fetch', this, next.bind(ctx));
},
- destroy: function (next) {
+ destroy: function (next, ctx) {
var sync = syncr();
- sync('delete', this, next);
+ sync('delete', this, next.bind(ctx));
}
});
View
@@ -2,7 +2,7 @@
"author": "August Hovland <gushov@gmail.com>",
"name": "lilmodel",
"description": "A li'l model wrapper",
- "version": "0.0.3",
+ "version": "0.0.4",
"repository": {
"type": "git",
"url": "git://github.com/gushov/lilmodel.git"
View
@@ -69,9 +69,12 @@ buster.testCase("lilmodel", {
var results = chef.recipes.get({ name: 'tacos' });
chef.recipes.remove({ name: 'meatball sauce' });
- chef.save(nextSpy);
+
+ var context = { me: 'gus' };
+ chef.save(nextSpy, context);
assert.calledOnce(this.syncStub);
assert.calledOnce(nextSpy);
+ assert(nextSpy.calledOn(context));
assert.equals(chef.name, 'gus');
assert.equals(chef.sousChef.name, 'zoe');
assert.equals(chef.recipes.$[0].name, 'tacos');

0 comments on commit 844823d

Please sign in to comment.