Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
<do-nothing>
{{#markdown}}

# $meteor.collection
# $meteor.collection / $scope.$meteorCollection

A service that wraps the [Meteor collections](http://docs.meteor.com/#/full/collections) to enable reactivity within AngularJS.

Calling $scope.$meteorCollection will automatically stop the collection when the scope is destroyed.

----

## Usage

$meteor.collection(collection, auto)

$scope.$meteorCollection(collection, auto)

### Arguments


Expand Down Expand Up @@ -104,7 +108,7 @@
});

// Bind without auto-save all todos to $scope.notAutoTodos
$scope.notAutoTodos = $meteor.collection(Todos, false).subscribe("publicTodos");
$scope.notAutoTodos = $scope.$meteorCollection(Todos, false).subscribe("publicTodos");

// todo might be an object like this {text: "Learn Angular", sticky: false}
// or an array like this:
Expand Down
8 changes: 6 additions & 2 deletions .docs/angular-meteor/client/views/api/api.meteorObject.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
<do-nothing>
{{#markdown}}

# $meteor.object
# $meteor.object / $scope.$meteorObject

A service that wraps a Meteor object to enable reactivity within AngularJS.
Finds the first document that matches the selector, as ordered by sort and skip options.
Wraps [collection.findOne](http://docs.meteor.com/#/full/findone)

Calling $scope.$meteorObject will automatically stop the object when the scope is destroyed.

----

## Usage

$meteor.object(collection, selector, auto)

$scope.$meteorObject(collection, selector, auto)

### Arguments


Expand Down Expand Up @@ -97,7 +101,7 @@

$scope.party = $meteor.object(Parties, $stateParams.partyId);

$scope.partyNotAuto = $meteor.object(Parties, $stateParams.partyId, false);
$scope.partyNotAuto = $scope.$meteorObject(Parties, $stateParams.partyId, false);

$scope.save = function() {
$scope.partyNotAuto.save().then(function(numberOfDocs){
Expand Down
8 changes: 4 additions & 4 deletions .docs/angular-meteor/client/views/api/api.subscribe.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
<do-nothing>
{{#markdown}}

# $meteor.subscribe / $scope.subscribe
# $meteor.subscribe / $scope.$meteorSubscribe

A service which is a wrapper for [Meteor.subscribe](http://docs.meteor.com/#/full/meteor_subscribe).
It subscribes to a [Meteor.publish](http://docs.meteor.com/#/full/publishandsubscribe) method in the client and returns a [AngularJS promise](https://docs.angularjs.org/api/ng/service/$q) when ready.

Calling $scope.subscribe will automatically stop the subscription when the scope is destroyed.
Calling $scope.$meteorSubscribe will automatically stop the subscription when the scope is destroyed.

----

## Usage

$meteor.subscribe(name, publisherArguments)

$scope.subscribe(name, publisherArguments)
$scope.$meteorSubscribe(name, publisherArguments)

### Arguments

Expand Down Expand Up @@ -84,7 +84,7 @@
subscriptionHandle.stop();
});

$scope.subscribe('books').then(function(subscriptionHandle){
$scope.$meteorSubscribe('books').then(function(subscriptionHandle){
// Bind all the todos to $scope.books
$scope.books = $meteor.collection(Books);

Expand Down
14 changes: 14 additions & 0 deletions modules/angular-meteor-meteorCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,17 @@ angularMeteorCollections.factory('$meteorCollection', ['AngularMeteorCollection'
return ngCollection;
}
}]);

angularMeteorCollections.run(['$rootScope', '$q', '$meteorCollection',
function($rootScope, $q, $meteorCollection) {
Object.getPrototypeOf($rootScope).$meteorCollection = function() {
var args = Array.prototype.slice.call(arguments);
var collection = $meteorCollection.apply(this, args);

this.$on('$destroy', function() {
collection.stop();
});

return collection;
};
}]);
14 changes: 14 additions & 0 deletions modules/angular-meteor-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,17 @@ angularMeteorObject.factory('$meteorObject', ['$rootScope', '$meteorUtils', 'Ang
return data;
};
}]);

angularMeteorObject.run(['$rootScope', '$q', '$meteorObject',
function($rootScope, $q, $meteorObject) {
Object.getPrototypeOf($rootScope).$meteorObject = function() {
var args = Array.prototype.slice.call(arguments);
var object = $meteorObject.apply(this, args);

this.$on('$destroy', function() {
object.stop();
});

return object;
};
}]);
47 changes: 22 additions & 25 deletions modules/angular-meteor-subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,48 @@ var angularMeteorSubscribe = angular.module('angular-meteor.subscribe', []);

angularMeteorSubscribe.service('$meteorSubscribe', ['$q',
function ($q) {
this.subscribe = function(){
var deferred = $q.defer();
var args = Array.prototype.slice.call(arguments);
var self = this;

this._subscribe = function(scope, deferred, args) {
var subscription = null;

// callbacks supplied as last argument
args.push({
onReady: function () {
onReady: function() {
deferred.resolve(subscription);
},
onError: function (err) {
onError: function(err) {
deferred.reject(err);
}
});

subscription = Meteor.subscribe.apply(this, args);
subscription = Meteor.subscribe.apply(scope, args);

return deferred.promise;
return subscription;
};
}]);

angularMeteorSubscribe.run(['$rootScope', '$q',
function($rootScope, $q) {
Object.getPrototypeOf($rootScope).subscribe = function(){
var self = this;
this.subscribe = function(){
var deferred = $q.defer();
var args = Array.prototype.slice.call(arguments);
var subscription = null;

// callbacks supplied as last argument
args.push({
onReady: function () {
deferred.resolve(subscription);
},
onError: function (err) {
deferred.reject(err);
}
});
self._subscribe(this, deferred, args);

return deferred.promise;
};
}]);

angularMeteorSubscribe.run(['$rootScope', '$q', '$meteorSubscribe',
function($rootScope, $q, $meteorSubscribe) {
Object.getPrototypeOf($rootScope).$meteorSubscribe = function() {
var deferred = $q.defer();
var args = Array.prototype.slice.call(arguments);

subscription = Meteor.subscribe.apply(this, args);
var subscription = $meteorSubscribe._subscribe(this, deferred, args);

self.$on('$destroy', function() {
this.$on('$destroy', function() {
subscription.stop();
});

return deferred.promise;
};
}]);
}]);