Skip to content

Commit 69d1e61

Browse files
committed
update examples
1 parent b12ef76 commit 69d1e61

File tree

2 files changed

+72
-19
lines changed

2 files changed

+72
-19
lines changed

README.markdown

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ var ddpclient = new DDPClient({
3333
maintain_collections: true // Set to false to maintain your own collections.
3434
});
3535

36+
/*
37+
* Connect to the Meteor Server
38+
*/
3639
ddpclient.connect(function(error) {
3740
if (error) {
3841
console.log('DDP connection error!');
@@ -41,18 +44,41 @@ ddpclient.connect(function(error) {
4144

4245
console.log('connected!');
4346

44-
ddpclient.loginWithUsername("username", "password", function (err, result) {
47+
/*
48+
* Uncomment to log in with username/password
49+
*/
50+
// ddpclient.loginWithUsername("username", "password", function (err, result) {
4551
// result contains your auth token
4652

47-
ddpclient.call('test-function', ['foo', 'bar'], function (err, result) {
48-
console.log('called function, result: ' + result);
49-
});
50-
51-
ddpclient.subscribe('posts', [], function () {
52-
console.log('posts complete:');
53-
console.log(ddpclient.collections.posts);
54-
});
55-
});
53+
setTimeout(function () {
54+
/*
55+
* Call a Meteor Method
56+
*/
57+
ddpclient.call(
58+
'deletePosts', // name of Meteor Method being called
59+
['foo', 'bar'], // parameters to send to Meteor Method
60+
function (err, result) { // callback which returns the method call results
61+
console.log('called function, result: ' + result);
62+
},
63+
function () { // callback which fires when server has finished
64+
console.log('updated'); // sending any updated documents as a result of
65+
console.log(ddpclient.collections.posts); // calling this method
66+
}
67+
);
68+
}, 3000);
69+
70+
/*
71+
* Subscribe to a Meteor Xollection
72+
*/
73+
ddpclient.subscribe(
74+
'posts', // name of Meteor Publish function to subscribe to
75+
[], // any parameters used by the Publish function
76+
function () { // callback when the subscription is complete
77+
console.log('posts complete:');
78+
console.log(ddpclient.collections.posts);
79+
}
80+
);
81+
// });
5682
});
5783

5884
/*
@@ -74,6 +100,7 @@ ddpclient.on('socket-close', function(code, message) {
74100
ddpclient.on('socket-error', function(error) {
75101
console.log("Error: %j", error);
76102
});
103+
77104
```
78105

79106
Unimplemented Features

examples/example.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ var ddpclient = new DDPClient({
1111
maintain_collections: true // Set to false to maintain your own collections.
1212
});
1313

14+
/*
15+
* Connect to the Meteor Server
16+
*/
1417
ddpclient.connect(function(error) {
1518
if (error) {
1619
console.log('DDP connection error!');
@@ -19,18 +22,41 @@ ddpclient.connect(function(error) {
1922

2023
console.log('connected!');
2124

22-
ddpclient.loginWithUsername("username", "password", function (err, result) {
25+
/*
26+
* Uncomment to log in with username/password
27+
*/
28+
// ddpclient.loginWithUsername("username", "password", function (err, result) {
2329
// result contains your auth token
2430

25-
ddpclient.call('test-function', ['foo', 'bar'], function (err, result) {
26-
console.log('called function, result: ' + result);
27-
});
31+
setTimeout(function () {
32+
/*
33+
* Call a Meteor Method
34+
*/
35+
ddpclient.call(
36+
'deletePosts', // name of Meteor Method being called
37+
['foo', 'bar'], // parameters to send to Meteor Method
38+
function (err, result) { // callback which returns the method call results
39+
console.log('called function, result: ' + result);
40+
},
41+
function () { // callback which fires when server has finished
42+
console.log('updated'); // sending any updated documents as a result of
43+
console.log(ddpclient.collections.posts); // calling this method
44+
}
45+
);
46+
}, 3000);
2847

29-
ddpclient.subscribe('posts', [], function () {
30-
console.log('posts complete:');
31-
console.log(ddpclient.collections.posts);
32-
});
33-
});
48+
/*
49+
* Subscribe to a Meteor Xollection
50+
*/
51+
ddpclient.subscribe(
52+
'posts', // name of Meteor Publish function to subscribe to
53+
[], // any parameters used by the Publish function
54+
function () { // callback when the subscription is complete
55+
console.log('posts complete:');
56+
console.log(ddpclient.collections.posts);
57+
}
58+
);
59+
// });
3460
});
3561

3662
/*

0 commit comments

Comments
 (0)