Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d03b352

Browse files
Ben Newmanabernix
Ben Newman
authored andcommitted
Convert packages/ddp-client to use ecmascript.
1 parent b145c7e commit d03b352

14 files changed

+63
-44
lines changed

packages/ddp-client/client_convenience.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { DDP } from "./namespace.js";
2+
13
// Meteor.refresh can be called on the client (if you're in common code) but it
24
// only has an effect on the server.
35
Meteor.refresh = function (notification) {

packages/ddp-client/id_map.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
MongoIDMap = function () {
2-
var self = this;
3-
IdMap.call(self, MongoID.idStringify, MongoID.idParse);
4-
};
5-
6-
Meteor._inherits(MongoIDMap, IdMap);
1+
export class MongoIDMap extends IdMap {
2+
constructor() {
3+
super(
4+
MongoID.idStringify,
5+
MongoID.idParse,
6+
);
7+
}
8+
}

packages/ddp-client/livedata_common.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { DDP, LivedataTest } from "./namespace.js";
2+
13
LivedataTest.SUPPORTED_DDP_VERSIONS = DDPCommon.SUPPORTED_DDP_VERSIONS;
24

35
// This is private but it's used in a few places. accounts-base uses

packages/ddp-client/livedata_connection.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { DDP, LivedataTest } from "./namespace.js";
2+
import { MongoIDMap } from "./id_map.js";
3+
14
if (Meteor.isServer) {
25
var path = Npm.require('path');
36
var Fiber = Npm.require('fibers');

packages/ddp-client/livedata_connection_tests.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import lolex from 'lolex';
2+
import { DDP, LivedataTest } from "./namespace.js";
23

34
var newConnection = function (stream, options) {
45
// Some of these tests leave outstanding methods with no result yet

packages/ddp-client/livedata_tests.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { DDP, LivedataTest } from "./namespace.js";
2+
13
// XXX should check error codes
24
var failure = function (test, code, reason) {
35
return function (error, result) {

packages/ddp-client/namespace.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
* @namespace DDP
33
* @summary Namespace for DDP-related methods/classes.
44
*/
5-
DDP = {};
6-
LivedataTest = {};
5+
export const DDP = {};
6+
export const LivedataTest = {};

packages/ddp-client/package.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Npm.depends({
1212

1313
Package.onUse(function (api) {
1414
api.use(['check', 'random', 'ejson', 'underscore', 'tracker',
15-
'retry', 'id-map'],
15+
'retry', 'id-map', 'ecmascript'],
1616
['client', 'server']);
1717

1818
// common functionality
@@ -25,9 +25,6 @@ Package.onUse(function (api) {
2525
// _idParse, _idStringify.
2626
api.use('mongo-id', ['client', 'server']);
2727

28-
api.addFiles('namespace.js', ['client', 'server']);
29-
30-
api.addFiles('id_map.js', ['client', 'server']);
3128
api.addFiles(['sockjs-0.3.4.js', 'stream_client_sockjs.js'], 'client');
3229
api.addFiles('stream_client_nodejs.js', 'server');
3330
api.addFiles('stream_client_common.js', ['client', 'server']);
@@ -39,11 +36,10 @@ Package.onUse(function (api) {
3936

4037
api.addFiles('client_convenience.js', 'client');
4138

39+
api.mainModule("namespace.js");
4240
api.export('DDP');
43-
api.export('LivedataTest', {testOnly: true});
4441
});
4542

46-
4743
Package.onTest(function (api) {
4844
api.use('livedata', ['client', 'server']);
4945
api.use('mongo', ['client', 'server']);

packages/ddp-client/random_stream.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { DDP } from "./namespace.js";
2+
13
// Returns the named sequence of pseudo-random values.
24
// The scope will be DDP._CurrentInvocation.get(), so the stream will produce
35
// consistent values for method calls on the client and server.

packages/ddp-client/stream_client_common.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { DDP, LivedataTest } from "./namespace.js";
2+
13
// XXX from Underscore.String (http://epeli.github.com/underscore.string/)
24
var startsWith = function(str, starts) {
35
return str.length >= starts.length &&

packages/ddp-client/stream_client_nodejs.js

+31-30
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { DDP, LivedataTest } from "./namespace.js";
2+
13
// @param endpoint {String} URL to Meteor app
24
// "http://subdomain.meteor.com/" or "/" or
35
// "ddp+sockjs://foo-**.meteor.com/sockjs"
@@ -9,45 +11,44 @@
911
// We don't do any heartbeating. (The logic that did this in sockjs was removed,
1012
// because it used a built-in sockjs mechanism. We could do it with WebSocket
1113
// ping frames or with DDP-level messages.)
12-
LivedataTest.ClientStream = function (endpoint, options) {
13-
var self = this;
14-
options = options || {};
15-
16-
self.options = _.extend({
17-
retry: true
18-
}, options);
14+
LivedataTest.ClientStream = class ClientStream {
15+
constructor(endpoint, options) {
16+
const self = this;
17+
options = options || {};
1918

20-
self.client = null; // created in _launchConnection
21-
self.endpoint = endpoint;
19+
self.options = Object.assign({
20+
retry: true
21+
}, options);
2222

23-
self.headers = self.options.headers || {};
24-
self.npmFayeOptions = self.options.npmFayeOptions || {};
23+
self.client = null; // created in _launchConnection
24+
self.endpoint = endpoint;
2525

26-
self._initCommon(self.options);
26+
self.headers = self.options.headers || {};
27+
self.npmFayeOptions = self.options.npmFayeOptions || {};
2728

28-
//// Kickoff!
29-
self._launchConnection();
30-
};
29+
self._initCommon(self.options);
3130

32-
_.extend(LivedataTest.ClientStream.prototype, {
31+
//// Kickoff!
32+
self._launchConnection();
33+
}
3334

3435
// data is a utf8 string. Data sent while not connected is dropped on
3536
// the floor, and it is up the user of this API to retransmit lost
3637
// messages on 'reset'
37-
send: function (data) {
38+
send(data) {
3839
var self = this;
3940
if (self.currentStatus.connected) {
4041
self.client.send(data);
4142
}
42-
},
43+
}
4344

4445
// Changes where this connection points
45-
_changeUrl: function (url) {
46+
_changeUrl(url) {
4647
var self = this;
4748
self.endpoint = url;
48-
},
49+
}
4950

50-
_onConnect: function (client) {
51+
_onConnect(client) {
5152
var self = this;
5253

5354
if (client !== self.client) {
@@ -86,9 +87,9 @@ _.extend(LivedataTest.ClientStream.prototype, {
8687
// fire resets. This must come after status change so that clients
8788
// can call send from within a reset callback.
8889
_.each(self.eventCallbacks.reset, function (callback) { callback(); });
89-
},
90+
}
9091

91-
_cleanup: function (maybeError) {
92+
_cleanup(maybeError) {
9293
var self = this;
9394

9495
self._clearConnectionTimer();
@@ -101,18 +102,18 @@ _.extend(LivedataTest.ClientStream.prototype, {
101102
callback(maybeError);
102103
});
103104
}
104-
},
105+
}
105106

106-
_clearConnectionTimer: function () {
107+
_clearConnectionTimer() {
107108
var self = this;
108109

109110
if (self.connectionTimer) {
110111
clearTimeout(self.connectionTimer);
111112
self.connectionTimer = null;
112113
}
113-
},
114+
}
114115

115-
_getProxyUrl: function (targetUrl) {
116+
_getProxyUrl(targetUrl) {
116117
var self = this;
117118
// Similar to code in tools/http-helpers.js.
118119
var proxy = process.env.HTTP_PROXY || process.env.http_proxy || null;
@@ -121,9 +122,9 @@ _.extend(LivedataTest.ClientStream.prototype, {
121122
proxy = process.env.HTTPS_PROXY || process.env.https_proxy || proxy;
122123
}
123124
return proxy;
124-
},
125+
}
125126

126-
_launchConnection: function () {
127+
_launchConnection() {
127128
var self = this;
128129
self._cleanup(); // cleanup the old socket, if there was one.
129130

@@ -200,4 +201,4 @@ _.extend(LivedataTest.ClientStream.prototype, {
200201
});
201202
});
202203
}
203-
});
204+
};

packages/ddp-client/stream_client_sockjs.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { DDP, LivedataTest } from "./namespace.js";
2+
13
// @param url {String} URL to Meteor app
24
// "http://subdomain.meteor.com/" or "/" or
35
// "ddp+sockjs://foo-**.meteor.com/sockjs"

packages/ddp-client/stream_client_tests.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { LivedataTest } from "./namespace.js";
2+
13
var Fiber = Npm.require('fibers');
24

35
testAsyncMulti("stream client - callbacks run in a fiber", [

packages/ddp-client/stream_tests.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { LivedataTest } from "./namespace.js";
2+
13
Tinytest.add("stream - status", function (test) {
24
// Very basic test. Just see that it runs and returns something. Not a
35
// lot of coverage, but enough that it would have caught a recent bug.

0 commit comments

Comments
 (0)