Skip to content

Commit ca06a70

Browse files
committed
Merge pull request #520 from markleusink/patch-2
AngularMeteorCollection doc page updated, added highlight.js to make code samples more readable
2 parents 203a87b + 9f97f5e commit ca06a70

File tree

3 files changed

+51
-20
lines changed

3 files changed

+51
-20
lines changed

.docs/angular-meteor/.meteor/packages

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ urigo:angularmeteormarkdown
1515
urigo:angulartics
1616
twbs:bootstrap
1717
fortawesome:fontawesome
18+
simple:highlight.js

.docs/angular-meteor/.meteor/versions

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ [email protected]
4848
4949
5050
51+
5152
5253
5354

.docs/angular-meteor/client/views/api/api.AngularMeteorCollection.html

+49-20
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ <h3><p><code><span class="pln">save( :docs );</span></code></p></h3>
4545
<a href="" class="label type-hint type-hint-object">object</a>
4646
</td>
4747
<td><p>The docs to save to the Meteor Collection.
48-
If nothing is passed, the method saves everything in the AngularMeteorCollection as is.
49-
If an object is passed, the method pushes that object into the AngularMeteorCollection.
50-
If an array is passed, the method pushes that all objects in the array into the AngularMeteorCollection.
48+
<ul>
49+
<li>If nothing is passed, the method saves everything in the AngularMeteorCollection as is.</li>
50+
<li>If an object is passed, the method pushes that object into the AngularMeteorCollection.</li>
51+
<li>If an array of objects is passed, the method pushes all objects into the AngularMeteorCollection.</li>
52+
</ul>
5153
</p></td>
5254
<td><a href="" class="label type-hint type-hint-object">No</a></td>
5355
</tr>
@@ -87,9 +89,11 @@ <h4>Parameters</h4>
8789
<a href="" class="label type-hint type-hint-object">object</a>
8890
</td>
8991
<td><p>The keys of the object to remove from the Meteor Collection.
90-
If nothing is passed, the method removes all the documents from the AngularMeteorCollection.
91-
If an object is passed, the method removes the object with that key from the AngularMeteorCollection.
92-
If an array is passed, the method removes all objects that matches the keys in the array from the AngularMeteorCollection.
92+
<ul>
93+
<li>If nothing is passed, the method removes all the documents from the AngularMeteorCollection.</li>
94+
<li>If an object is passed, the method removes the object with that key from the AngularMeteorCollection.</li>
95+
<li>If an array is passed, the method removes all objects that matches the keys in the array from the AngularMeteorCollection.</li>
96+
</li>
9397
</p></td>
9498
<td><a href="" class="label type-hint type-hint-object">No</a></td>
9599
</tr>
@@ -107,9 +111,9 @@ <h4>Parameters</h4>
107111
<br>
108112
<h3><p><code><span class="pln">subscribe( :subscriptionName );</span></code></p></h3>
109113
<br>
110-
A shorten (Syntactic sugar) function for the <a href="/api/subscribe">$meteor.subscribe function</a>.
114+
A shorter ('syntactic sugar') function for <a href="/api/subscribe">$meteor.subscribe</a>.
111115

112-
Takes only one parameter and not returns a promise like <a href="/api/subscribe">$meteor.subscribe</a> does.
116+
Takes only one parameter and doesn't return a promise like <a href="/api/subscribe">$meteor.subscribe</a> does.
113117

114118
When called after $scope.meteorCollection, it acts the same but in addition it automatically closes the subscription when the scope is destroyed.
115119

@@ -130,7 +134,7 @@ <h4>Parameters</h4>
130134
<td>
131135
<a href="" class="label type-hint type-hint-string">subscriptionName</a>
132136
</td>
133-
<td><p>The subscription name to subscribe to. exactly like the first parameter in $meteor.subscribe service.
137+
<td><p>The subscription name to subscribe to. Exactly like the first parameter in the $meteor.subscribe service.
134138
</p></td>
135139
<td><a href="" class="label type-hint type-hint-object">Yes</a></td>
136140
</tr>
@@ -141,7 +145,7 @@ <h4>Parameters</h4>
141145
<br>
142146
<h3><p><code><span class="pln">stop();</span></code></p></h3>
143147
<br>
144-
Stops watching the current collection for changes made in the scope variable or the meteor collection.
148+
Stops watching the current collection for changes made in the scope variable or meteor collection.
145149

146150
#### Parameters
147151
None
@@ -154,32 +158,57 @@ <h3><p><code><span class="pln">stop();</span></code></p></h3>
154158
// Bind all the todos to $scope.todos without auto-save
155159
$scope.todos = $meteor.collection(Todos, false);
156160

161+
// Add a single todo to the collection
157162
var todoObject = {name:'first todo'};
158-
var todoArray = [{name:'second todo'}, {name:'third todo'}];
159-
var todoSecondObject = {name:'forth todo'};
160-
161163
$scope.todos.save(todoObject); // todos equals [{name:'first todo'}]
162164

165+
// Add multiple todos to the collection
166+
var todoArray = [{name:'second todo'}, {name:'third todo'}];
163167
$scope.todos.save(todosArray); // todos equals [{name:'first todo'}, {name:'second todo'}, {name:'third todo'}]
164168

165-
$scope.todos.push(todoSecondObject); // The scope variable equals to [{name:'first todo'}, {name:'second todo'}, {name:'third todo'}, {name:'forth todo'}]
166-
// but the collection still equals to [{name:'first todo'}, {name:'second todo'}, {name:'third todo'}]
167-
168-
$scope.todos.save(); // Now the collection also equals to [{name:'first todo'}, {name:'second todo'}, {name:'third todo'}, {name:'forth todo'}]
169-
170-
$scope.todos.remove(firstTodoId); // scope and collection equals to [{name:'second todo'}, {name:'third todo'}, {name:'forth todo'}]
169+
// Add another todo to the collection
170+
var anotherTodoObject = {name:'fourth todo'};
171+
$scope.todos.push(anotherTodoObject);
172+
173+
/*
174+
* The scope variable now holds:
175+
* [{name:'first todo'}, {name:'second todo'}, {name:'third todo'}, {name:'fourth todo'}]
176+
*
177+
* but the collection holds:
178+
* [{name:'first todo'}, {name:'second todo'}, {name:'third todo'}]
179+
*
180+
* that's because auto-save was set to false (the 2nd parameter in the $meteor.collection call).
181+
*
182+
* To save the data we need to explicitly call the save() function:
183+
*/
184+
$scope.todos.save();
185+
186+
$scope.todos.remove(firstTodoId); // scope and collection equals to [{name:'second todo'}, {name:'third todo'}, {name:'fourth todo'}]
171187

172188
$scope.todos.remove(todoIdsArray); // removes everything matches the array of IDs both in scope and in collection
173189

174190
$scope.todos.pop(); // removes only in scope
175191

176192
$scope.todos.remove(); // syncs also in Meteor collection
177193

178-
179194
// Using the subscribe function
180195
$scope.parties = $meteor.collection(Parties).subscribe('partiesSubscription');
181196

197+
// With a callback to do something after the todo was saved and to catch errors
198+
$scope.todos.save(todoObject)
199+
.then( function() {
200+
201+
// todos were successfully saved
202+
console.log('The todo was saved');
203+
204+
}, function(err) {
205+
206+
// an error occurred while saving the todos: maybe you're not authorized
207+
console.error( 'An error occurred. The error message is: ' + err.message);
208+
209+
});
182210
{{/markdown}}
211+
183212
</do-nothing>
184213

185214
</div>

0 commit comments

Comments
 (0)