examples/chatroom/models/thread.js
function() {
            var messages = app.database.messages.find({ threadId: this.uid }, ok(this.set.bind(this, "messages")));

            // update unreadMessageCount whenever the messages collection
            // changes
            messages.watch(function() {
                this.set("unreadMessageCount", messages.filter(function(message) {
                    return !message.read;
                }).length);
            }.bind(this));
        }
function() {
            var messages = app.database.messages.find({ threadId: this.uid }, ok(this.set.bind(this, "messages")));

            // update unreadMessageCount whenever the messages collection
            // changes
            messages.watch(function() {
                this.set("unreadMessageCount", messages.filter(function(message) {
                    return !message.read;
                }).length);
            }.bind(this));
        }
function ( ) { var messages = app . database . messages . find ( { threadId : this . uid } , ok ( this . set . bind ( this , "messages" ) ) ) ; // update unreadMessageCount whenever the messages collection // changes messages . watch ( function ( ) { this . set ( "unreadMessageCount" , messages . filter ( function ( message ) { return ! message . read ; } ) . length ) ; } . bind ( this ) ) ; }
start computations on messages only as they're demanded by the application
start computations on messages only as they re demanded by the application