Skip to content

Commit

Permalink
We got the method signature wrong the first time around. Meteor optio…
Browse files Browse the repository at this point in the history
…ns and Knockout Mapping options are now separate arguments to find() and findOne().
  • Loading branch information
Steven Luscher committed Jul 19, 2012
1 parent fecbcbc commit 62ebc44
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 129 deletions.
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Use `ko.meteor.find()` and `ko.meteor.findOne()` like you would normally use `ko
var viewModel = {
unfinishedTodos: ko.meteor.find(Todos, {done: false}),
finishedTodos: ko.meteor.find(Todos, {done: true}),
oldestUnfinishedTodo: ko.meteor.findOne(Todos, {done: true}, {meteor_options: {sort: {created_at:1}}})
oldestUnfinishedTodo: ko.meteor.findOne(Todos, {done: true}, {sort: {created_at:1}})
};
Meteor.startup( function() { ko.applyBindings(viewModel); } );

Expand All @@ -39,8 +39,8 @@ Any update to the Meteor `Todos` collection will now trigger a UI refresh. This

`ko.meteor.find()` and `ko.meteor.findOne()` share the same method signature.

ko.meteor.find( collection, selector[, options] )
ko.meteor.findOne( collection, selector[, options] )
ko.meteor.find( collection, selector[, options, mapping] )
ko.meteor.findOne( collection, selector[, options, mapping] )

### The `collection` argument ###

Expand All @@ -52,19 +52,17 @@ A Mongo selector, a String, or an `Observable` that wraps a Mongo selector or St

### The `options` argument ###

(Optional) An Object, or an `Observable` that wraps an Object. Recognizes the following keys:
(Optional) An Object, or an `Observable` that wraps an Object. See the Meteor documentation on the `options` argument of [`find()`](http://docs.meteor.com/#find) and [`findOne()`](http://docs.meteor.com/#findone) for more information.

* `view_model` – an object constructor.
### The `mapping` argument ###

> The mapper will instantiate an object using this constructor, then map each record in the Meteor Collection to the resulting instance. The constructor will receive, as its first parameter, an object representing the data returned from the query.
(Optional) An Object, or an `Observable` that wraps an Object. Recognizes the following special property:

* `meteor_options`additional configuration for `Meteor.Collection.find()` or `Meteor.Collection.findOne()`.
* `view_model`an object constructor.

> See the Meteor documentation on the `options` argument of [`find()`](http://docs.meteor.com/#find) and [`findOne()`](http://docs.meteor.com/#findone) for more information.
* `mapping` – additional configuration for the Knockout Mapping plugin.
> The mapper will instantiate an object using this constructor, then map each record in the Meteor Collection to the resulting instance. The constructor will receive, as its first parameter, an object representing the data returned from the query.
> See the "[Advanced Usage](http://knockoutjs.com/documentation/plugins-mapping.html#advanced_usage)" section of the Knockout Mapping documentation for more information.
The remaining `mapping` properties will be passed through to the Knockout Mapping plugin. See the "[Advanced Usage](http://knockoutjs.com/documentation/plugins-mapping.html#advanced_usage)" section of the Knockout Mapping documentation for more information.

## Requirements ##

Expand Down
63 changes: 35 additions & 28 deletions build/knockout.meteor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 35 additions & 28 deletions examples/dynamic_finders/client/knockout.meteor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/dynamic_finders/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ if (Meteor.is_client) {
});

var options = ko.computed(function() {
var meteor_options = { sort: {} };
meteor_options.sort[sortField().toLowerCase()] = sortAsc() ? 1 : -1;
return { meteor_options: meteor_options };
var options = { sort: {} };
options.sort[sortField().toLowerCase()] = sortAsc() ? 1 : -1;
return options;
});

// finders!
Expand Down
Loading

0 comments on commit 62ebc44

Please sign in to comment.