Skip to content

Commit

Permalink
port skel, todos, leaderboard to new data API
Browse files Browse the repository at this point in the history
  • Loading branch information
gschmidt committed Feb 17, 2012
1 parent 6fa852f commit 3e47029
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 209 deletions.
2 changes: 0 additions & 2 deletions app/meteor/skel/client/~name~.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Meteor.subscribe('clicks');

Template.button_demo.events = {
'click input': function () {
Clicks.insert({time: (new Date()).getTime()});
Expand Down
6 changes: 1 addition & 5 deletions app/meteor/skel/model.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
Clicks = Meteor.Collection('clicks');

if (Meteor.is_server) {
Meteor.publish('clicks', {});
}
Clicks = new Meteor.Collection('clicks');
4 changes: 2 additions & 2 deletions docs/client/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ <h2 id="collection"><span>Collection</span></h2>
// after that, it will be synchronized down to any other clients
// that are subscribed to a query that includes it (see
// Meteor.subscribe)
Posts = Meteor.Collection("posts");
Posts = new Meteor.Collection("posts");
Posts.insert({title: "Hello world", body: "First post"});

// Changes are visible immediately -- no waiting for a round trip to
Expand All @@ -427,7 +427,7 @@ <h2 id="collection"><span>Collection</span></h2>
// Create a temporary, local collection. It works just any other
// collection, but it doesn't send changes to the server, and it
// can't receive any data from subscriptions.
Scratchpad = Meteor.Collection();
Scratchpad = new Meteor.Collection;
for (var i = 0; i < 10; i++)
Scratchpad.insert({number: i * 2});
assert(Scratchpad.find({number: {$lt: 9}}).count() === 5);
Expand Down
2 changes: 1 addition & 1 deletion docs/client/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Template.api.reconnect = {

Template.api.collection = {
id: "create_collection",
name: "Meteor.Collection([name])",
name: "new Meteor.Collection([name])",
locus: "Anywhere",
descr: ["Create a MongoDB-style collection that can be used to store data."],
args: [
Expand Down
2 changes: 1 addition & 1 deletion examples/leaderboard/leaderboard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Set up a collection to contain player information. On the server,
// it is backed by a MongoDB collection named "players."
Players = Meteor.Collection("players");
Players = new Meteor.Collection("players");

/*** Client ***/

Expand Down
18 changes: 10 additions & 8 deletions examples/todos/model.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Lists = Meteor.Collection("lists");
Lists = new Meteor.Collection("lists");

Todos = Meteor.Collection("todos");
Todos = new Meteor.Collection("todos");

/* Schema support coming soon!
Expand All @@ -11,9 +11,11 @@ Todos.schema({text: String,
tags: [String]});
*/

Meteor.publish('lists');
Meteor.publish('todos', {
selector: function (params) {
return {list_id: params.list};
}
});
if (Meteor.is_server) {
Meteor.publish('lists');
Meteor.publish('todos', {
selector: function (params) {
return {list_id: params.list};
}
});
}
4 changes: 2 additions & 2 deletions examples/unfinished/azrael/model.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// XXX it is actually very dangerous to store times as Number. use
// Date type once it's implemented in minimongo
Rooms = Meteor.Collection("rooms");
Rooms = new Meteor.Collection("rooms");
//Rooms.schema({name: String, created: Number});

Chat = Meteor.Collection("chat");
Chat = new Meteor.Collection("chat");
/*
Chat.schema({room: String, message: String,
username: String, created: Number});
Expand Down
2 changes: 1 addition & 1 deletion examples/unfinished/coffeeless/model.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
root = exports ? this # export Presses globally.
root.Presses = Meteor.Collection 'presses'
root.Presses = new Meteor.Collection 'presses'

Meteor.publish 'presses'
8 changes: 5 additions & 3 deletions examples/unfinished/todos-backbone/common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Todos = Meteor.Collection("todos");
Todos.schema({text: String, done: Boolean, order: Number});
Todos = new Meteor.Collection("todos");
//Todos.schema({text: String, done: Boolean, order: Number});

Meteor.publish('todos');
if (Meteor.is_server) {
Meteor.publish('todos');
}
2 changes: 1 addition & 1 deletion examples/unfinished/todos-underscore/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ $(function () {
// support aggregate queries, construct a local collection to serve
// the same purpose, and drive the renderList() off of it.

var LocalTags = Meteor.Collection();
var LocalTags = new Meteor.Collection;
(function () {
function updateLocalTags() {
var real = _(Todos.find()).chain().pluck('tags').compact().flatten().uniq().value();
Expand Down
10 changes: 6 additions & 4 deletions examples/unfinished/todos-underscore/common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Lists = Meteor.Collection("lists");
Lists = new Meteor.Collection("lists");

Todos = Meteor.Collection("todos");
Todos = new Meteor.Collection("todos");

/* Schema support coming soon!
Expand All @@ -11,5 +11,7 @@ Todos.schema({text: String,
tags: [String]});
*/

Meteor.publish('lists');
Meteor.publish('todos');
if (Meteor.is_server) {
Meteor.publish('lists');
Meteor.publish('todos');
}
2 changes: 1 addition & 1 deletion packages/autopublish/autopublish.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
App._enable_autopublish();
App.autopublish();
173 changes: 0 additions & 173 deletions packages/livedata/collection.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/livedata/livedata_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ _.extend(Meteor._LivedataConnection.prototype, {

_.each(self.pending_data, function (msg) {
if (msg.collection && msg.id) {
var store = stores[msg.collection];
var store = self.stores[msg.collection];

if (!store) {
// Nobody's listening for this data. Queue it up until
Expand Down
2 changes: 1 addition & 1 deletion packages/livedata/livedata_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ _.extend(Meteor._LivedataServer.prototype, {
reason: "Internal server error"}}));
// XXX prettyprint exception in the log
Meteor._debug("Exception in method '" + msg.method + "': " +
JSON.stringify(err));
JSON.stringify(err.stack));
}

if (msg.id)
Expand Down
5 changes: 5 additions & 0 deletions packages/livedata/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Package.on_use(function (api) {
api.use(['stream', 'uuid']);
api.use(['json', 'underscore', 'deps', 'logging'], ['client', 'server']);

// livedata_connection.js uses a Minimongo collection internally to
// manage the current set of subscriptions.
api.use('minimongo', ['client', 'server']);


api.add_files('livedata_connection.js', 'client');
api.add_files('livedata_server.js', 'server');

Expand Down
15 changes: 12 additions & 3 deletions packages/mongo-livedata/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Meteor.Collection = function (name, manager, driver) {
throw new Error("There is already a collection named '" + name + "'");
}

// mutation methods
if (manager) {
var m = {};
// XXX what if name has illegal characters in it?
Expand All @@ -96,10 +97,18 @@ Meteor.Collection = function (name, manager, driver) {
}

// XXX temporary hack to provide sugar in LivedataServer.publish()
if (name && manager && manager._hack_collections)
if (name && manager && manager._hack_collections) {
if (name in manager._hack_collections)
throw new Error("There is already a collection named '" + name + "'");
manager._hack_collections[name] = self;
};
}

// autopublish
if (name && manager.onAutopublish)
manager.onAutopublish(function () {
manager.publish(name, {is_auto: true});
});
};

_.extend(Meteor.Collection.prototype, {
find: function (/* selector, options */) {
Expand All @@ -117,7 +126,7 @@ _.extend(Meteor.Collection.prototype, {

_maybe_snapshot: function () {
var self = this;
if (!self._was_snapshot) {
if (self.manager && self.manager.registerStore && !self._was_snapshot) {
self._collection.snapshot();
self._was_snapshot = true;
}
Expand Down
1 change: 1 addition & 0 deletions packages/mongo-livedata/local_collection_driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Meteor._LocalCollectionDriver = function () {

_.extend(Meteor._LocalCollectionDriver.prototype, {
open: function (name) {
var self = this;
if (!name)
return new LocalCollection;
if (!(name in self.collections))
Expand Down
1 change: 1 addition & 0 deletions packages/mongo-livedata/remote_collection_driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Meteor._RemoteCollectionDriver = function (mongo_url) {

_.extend(Meteor._RemoteCollectionDriver.prototype, {
open: function (name) {
var self = this;
var ret = {};
_.each(['find', 'findOne', 'insert', 'update', 'remove'], function (m) {
ret[m] = _.bind(self.mongo[m], self.mongo, name);
Expand Down

0 comments on commit 3e47029

Please sign in to comment.