Skip to content

Commit

Permalink
🎨 Make use of object shorthand
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinroger committed Apr 13, 2017
1 parent 34135cc commit 650150a
Show file tree
Hide file tree
Showing 36 changed files with 151 additions and 151 deletions.
6 changes: 3 additions & 3 deletions lib/api_formats/siren/device.siren.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module.exports = context => {
const properties = model.properties();
const entity = {
class: ['device', properties.type],
properties: properties,
actions: actions,
properties,
actions,
links: [{ rel: ['self', 'edit'], href: env.helpers.url.path(`${loader.path}/devices/${model.id}`) },
{ title: context.serverName, rel: ['up', rel.server], href: env.helpers.url.path(loader.path) },
{ rel: [rel.type, 'describedby'], href: `${env.helpers.url.path(loader.path)}/meta/${properties.type}` }]
Expand All @@ -33,7 +33,7 @@ var buildActions = module.exports.buildActions = (deviceId, env, loader, transit
name: type,
method: 'POST',
href: env.helpers.url.path(`${loader.path}/devices/${deviceId}`),
fields: fields
fields
};
if (!actions) {
actions = [];
Expand Down
2 changes: 1 addition & 1 deletion lib/api_formats/siren/devices.siren.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var buildEntity = function(model, loader, env) {
const entity = {
class: ['device', properties.type],
rel: [rel.device],
properties: properties,
properties,
links: [{ rel: ['self', 'edit'], href: env.helpers.url.path(`${loader.path}/devices/${model.id}`) },
{ rel: [rel.type, 'describedby'], href: `${env.helpers.url.path(loader.path)}/meta/${encodeURIComponent(properties.type)}` },
{ rel: ['up', rel.server], href: env.helpers.url.path(loader.path) }]
Expand Down
2 changes: 1 addition & 1 deletion lib/api_formats/siren/server.siren.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var buildEntity = function(model, server, loader, env) {
const entity = {
class: ['device', properties.type],
rel: [rel.device],
properties: properties,
properties,
links: [{ rel: ['self', 'edit'], href: env.helpers.url.path(`${loader.path}/devices/${model.id}`) },
{ rel: [rel.type, 'describedby'], href: `${env.helpers.url.path(loader.path)}/meta/${encodeURIComponent(properties.type)}` },
{ title: server._name, rel: ['up', rel.server], href: env.helpers.url.path(loader.path) }]
Expand Down
2 changes: 1 addition & 1 deletion lib/api_resources/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ DevicesResource.prototype.list = function(env, next) {
const serverId = match && match[1] ? match[1] : this.server.id;

const localServer = { path: `/servers/${encodeURI(serverId)}` };
const context = { devices: this.server.runtime._jsDevices, loader: localServer, env: env };
const context = { devices: this.server.runtime._jsDevices, loader: localServer, env };
env.format.render('devices', context);
next(env);
};
2 changes: 1 addition & 1 deletion lib/api_resources/peer_management.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ PeerManagementResource.prototype._proxyToPeer = (peer, env, callback) => {
const req = env.request;
const res = env.response;
const agent = env.zettaAgent || peer.agent;
const opts = { method: req.method, headers: req.headers, path: req.url, agent: agent };
const opts = { method: req.method, headers: req.headers, path: req.url, agent };
const request = http.request(opts, res => {
res.on('data', () => {});
res.on('end', () => {
Expand Down
6 changes: 3 additions & 3 deletions lib/api_resources/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ RootResource.prototype.list = function(env, next) {
const entity = {
class: ['device', properties.type],
rel: [rel.device],
properties: properties,
properties,
links: [{ rel: ['self'], href: env.helpers.url.path(`${loader.path}/devices/${model.id}`) },
{ title: server._name, rel: ['up', rel.server], href: env.helpers.url.path(loader.path) }]
};
Expand Down Expand Up @@ -233,9 +233,9 @@ RootResource.prototype._queryDevices = function(env, next) {

const context = {
server: self.server,
devices: devices,
devices,
loader: {path: `/servers/${encodeURI(self.server.id)}`},
env: env,
env,
classes:['search-results'],
query: params.ql
};
Expand Down
20 changes: 10 additions & 10 deletions lib/api_resources/servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ ServerResource.prototype.showMetadata = function(env, next) {
server: this.server,
types: this.deviceTypes,
loader: this.getServer(env),
env: env
env
};

env.format.render('metadata', context);
Expand All @@ -202,9 +202,9 @@ ServerResource.prototype.showMetadataType = function(env, next) {

const context = {
server: this.server,
type: type,
type,
loader: this.getServer(env),
env: env
env
};

env.format.render('type', context);
Expand All @@ -221,7 +221,7 @@ ServerResource.prototype.showServer = function(env, next) {
}

//TODO: argo-formatter may want to take multiple arguments for a format. This context obj is a hack.
const context = { server: this.server, devices: this.server.runtime._jsDevices, loader: this.getServer(env), env: env };
const context = { server: this.server, devices: this.server.runtime._jsDevices, loader: this.getServer(env), env };
env.format.render('server', context);
next(env);
};
Expand Down Expand Up @@ -290,9 +290,9 @@ ServerResource.prototype._queryDevices = function(env, next) {

const context = {
server: self.server,
devices: devices,
devices,
loader: self.getServer(env),
env: env,
env,
classes:['search-results'],
query: params.ql
};
Expand Down Expand Up @@ -361,7 +361,7 @@ ServerResource.prototype.showDevice = function(env, next) {
model: device,
loader: this.getServer(env),
serverName: this.server._name,
env: env
env
};

env.format.render('device', model);
Expand Down Expand Up @@ -420,7 +420,7 @@ ServerResource.prototype.updateDevice = function(env, next) {
model: device,
loader: self.getServer(env),
serverName: self.server._name,
env: env
env
};

env.format.render('device', model);
Expand Down Expand Up @@ -535,7 +535,7 @@ ServerResource.prototype.deviceAction = function(env, next) {
env.response.statusCode = statusCode;
env.response.body = {
class: ['action-error'],
properties: properties,
properties,
links: [
{ rel: ['self'], href: env.helpers.url.current() }
]
Expand All @@ -545,7 +545,7 @@ ServerResource.prototype.deviceAction = function(env, next) {
model: device,
loader: self.getServer(env),
serverName: self.server._name,
env: env
env
};
env.format.render('device', model);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/event_broker.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ EventBroker.prototype.subscribeToDeviceQuery = function(topic) {
const q = self.zetta.runtime.query().ql(qt.ql);
this._deviceQueries[topic] = this.zetta.runtime.observe(q, device => {
setImmediate(() => {
self.zetta.pubsub.publish(topic, { query: topic, device: device });
self.zetta.pubsub.publish(topic, { query: topic, device });
});
});
};
2 changes: 1 addition & 1 deletion lib/event_socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const EventSocket = module.exports = function(ws, query, options) {
}
}

const subscription = { subscriptionId: ++self._subscriptionIndex, topic: topic, limit: msg.limit };
const subscription = { subscriptionId: ++self._subscriptionIndex, topic, limit: msg.limit };
self._subscriptions.push(subscription);

var msg = {
Expand Down
2 changes: 1 addition & 1 deletion lib/http_scout.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ HTTPScout.prototype.init = next => {

HTTPScout.prototype.createHTTPDevice = function(type, id, name) {
const constructor = this.driverFunctions[type];
const deviceObject = { id: id, name: name};
const deviceObject = { id, name};
if(constructor) {
if(id) {
this.provision(deviceObject, constructor);
Expand Down
14 changes: 7 additions & 7 deletions lib/http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,17 +306,17 @@ ZettaHttpServer.prototype.setupPeerSocket = function(ws) {
peer.on('connected', () => {
self.eventBroker.peer(peer);
self.zetta.log.emit('log', 'http_server', `Peer connection established "${name}".`);
self.zetta.pubsub.publish('_peer/connect', { peer: peer });
self.zetta.pubsub.publish('_peer/connect', { peer });
});

peer.on('error', err => {
self.zetta.log.emit('log', 'http_server', `Peer connection failed for "${name}": ${err.message}.`);
self.zetta.pubsub.publish('_peer/disconnect', { peer: peer, err: err });
self.zetta.pubsub.publish('_peer/disconnect', { peer, err });
});

peer.on('end', () => {
self.zetta.log.emit('log', 'http_server', `Peer connection closed for "${name}".`);
self.zetta.pubsub.publish('_peer/disconnect', { peer: peer });
self.zetta.pubsub.publish('_peer/disconnect', { peer });
});
}
};
Expand Down Expand Up @@ -460,12 +460,12 @@ ZettaHttpServer.prototype.proxyToPeers = function(peers, env, cb) {

const agent = env.zettaAgent || peer.agent;

const opts = { method: req.method, headers: headers, path: reqUrl, agent: agent };
const opts = { method: req.method, headers, path: reqUrl, agent };
const request = http.request(opts, response => {
response.getBody((err, body) => {
callback(null, { res: response, err: err, body: body });
callback(null, { res: response, err, body });
});
}).on('error', err => callback(null, { err: err }));
}).on('error', err => callback(null, { err }));

if (req.body) {
request.end(req.body);
Expand Down Expand Up @@ -505,7 +505,7 @@ ZettaHttpServer.prototype.proxyToPeer = function(env, next) {
method: req.method,
headers: req.headers,
path: req.url,
agent: agent,
agent,
pipe: true
};
if (typeof env.proxyOpts === 'object') {
Expand Down
2 changes: 1 addition & 1 deletion lib/peer_socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ PeerSocket.prototype.transition = function(action, args, cb) {

const opts = {
agent: this.agent,
path: path,
path,
method: action.method,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Expand Down
2 changes: 1 addition & 1 deletion lib/pubsub_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ PubSub.prototype._onResponse = function(topic, sourceTopic, data, fromRemote, en
} else if (data.query && data.device) {
var serverId = env.route.params.serverId;
const loader = { path: `/servers/${encodeURIComponent(serverId)}` };
data = deviceFormatter({ loader: loader, env: env, model: data.device });
data = deviceFormatter({ loader, env, model: data.device });
encoding = 'application/json';
data = new Buffer(JSON.stringify(data));
} else if (typeof data == 'object') {
Expand Down
2 changes: 1 addition & 1 deletion lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Registry.prototype._init = function(cb) {
});

const engine = calypso.configure({
driver: driver
driver
});

engine.build((err, connection) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ Runtime.prototype._initRemoteQueryListener = function(ql, peer) {
this._remoteSubscriptions[peer.name] = {};
}

const topic = querytopic.format({ql: ql});
const topic = querytopic.format({ql});

// already subscribed to the query topic
if(this._remoteSubscriptions[peer.name][topic]) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/mem_peer_registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const PeerRegistry = require('../../lib/peer_registry');

const MemPeerRegistry = module.exports = function() {
const db = levelup({ db: memdown });
PeerRegistry.call(this, { db: db, collection: 'peers' });
PeerRegistry.call(this, { db, collection: 'peers' });
};
util.inherits(MemPeerRegistry, PeerRegistry);

2 changes: 1 addition & 1 deletion test/fixture/mem_registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const DeviceRegistry = require('../../lib/device_registry');

const MemRegistry = module.exports = function() {
const db = levelup({ db: memdown });
DeviceRegistry.call(this, { db: db, collection: 'devices' });
DeviceRegistry.call(this, { db, collection: 'devices' });
};
util.inherits(MemRegistry, DeviceRegistry);

Loading

0 comments on commit 650150a

Please sign in to comment.