Skip to content

Commit

Permalink
Example advantage: Use an Object.assign shim
Browse files Browse the repository at this point in the history
  • Loading branch information
gyeates committed Sep 24, 2014
1 parent 5177d12 commit 4941cfb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"canvas": "1.1.3",
"eventemitter2": "~0.4.13",
"nodejs-websocket": "~0.1.4",
"object-assign": "^1.0.0",
"xmlshim": "~0.0.9"
},
"browser": {
Expand Down
9 changes: 3 additions & 6 deletions src/RosLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

var ROSLIB = this.ROSLIB || {
REVISION : '0.10.0-SNAPSHOT',
REVISION : '0.10.0-SNAPSHOT'
};

ROSLIB.Ros = require('./core/Ros');
Expand Down Expand Up @@ -35,10 +35,7 @@ ROSLIB.UrdfModel = require('./urdf/UrdfModel');
ROSLIB.UrdfSphere = require('./urdf/UrdfSphere');
ROSLIB.UrdfVisual = require('./urdf/UrdfVisual');

//URDF types
var UrdfTypes = require('./urdf/UrdfTypes');
Object.keys(UrdfTypes).forEach(function(type) {
ROSLIB[type] = UrdfTypes[type];
});
// Add URDF types
require('object-assign')(ROSLIB, require('./urdf/UrdfTypes'));

module.exports = ROSLIB;
9 changes: 3 additions & 6 deletions src/core/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
* @author Brandon Alexander - baalexander@gmail.com
*/

var assign = require('object-assign');

/**
* Message objects are used for publishing and subscribing to and from topics.
*
* @constructor
* @param values - object matching the fields defined in the .msg definition file
*/
function Message(values) {
var that = this;
values = values || {};

Object.keys(values).forEach(function(name) {
that[name] = values[name];
});
assign(this, values);
}

module.exports = Message;
9 changes: 3 additions & 6 deletions src/core/ServiceRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
* @author Brandon Alexander - balexander@willowgarage.com
*/

var assign = require('object-assign');

/**
* A ServiceRequest is passed into the service call.
*
* @constructor
* @param values - object matching the fields defined in the .srv definition file
*/
function ServiceRequest(values) {
var that = this;
values = values || {};

Object.keys(values).forEach(function(name) {
that[name] = values[name];
});
assign(this, values);
}

module.exports = ServiceRequest;
9 changes: 3 additions & 6 deletions src/core/ServiceResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
* @author Brandon Alexander - balexander@willowgarage.com
*/

var assign = require('object-assign');

/**
* A ServiceResponse is returned from the service call.
*
* @constructor
* @param values - object matching the fields defined in the .srv definition file
*/
function ServiceResponse(values) {
var that = this;
values = values || {};

Object.keys(values).forEach(function(name) {
that[name] = values[name];
});
assign(this, values);
}

module.exports = ServiceResponse;

0 comments on commit 4941cfb

Please sign in to comment.