Skip to content

Commit

Permalink
Move most RPS methods to be private.
Browse files Browse the repository at this point in the history
  • Loading branch information
sgress454 committed Oct 4, 2016
1 parent c017084 commit c981c6e
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 121 deletions.
6 changes: 3 additions & 3 deletions lib/hooks/blueprints/actions/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ module.exports = function addToCollection (req, res) {
ChildModel.subscribe(req, newChildRecord);
ChildModel.introduce(newChildRecord);
}
ChildModel.publishCreate(newChildRecord, !req.options.mirror && req);
ChildModel._publishCreate(newChildRecord, !req.options.mirror && req);
}

createdChild = true;
Expand Down Expand Up @@ -159,7 +159,7 @@ module.exports = function addToCollection (req, res) {
async_data.parent.save(function saved(err) {

// Ignore `insert` errors for duplicate adds
// (but keep in mind, we should not publishAdd if this is the case...)
// (but keep in mind, we should not _publishAdd if this is the case...)
var isDuplicateInsertError = (err && typeof err === 'object' && err.length && err[0] && err[0].type === 'insert');
if (err && !isDuplicateInsertError) return res.negotiate(err);

Expand All @@ -170,7 +170,7 @@ module.exports = function addToCollection (req, res) {
// Subscribe to the model you're adding to, if this was a socket request
if (req.isSocket) { Model.subscribe(req, async_data.parent); }
// Publish to subscribed sockets
Model.publishAdd(async_data.parent[Model.primaryKey], relation, async_data.actualChildPkValue, !req.options.mirror && req, {noReverse: createdChild});
Model._publishAdd(async_data.parent[Model.primaryKey], relation, async_data.actualChildPkValue, !req.options.mirror && req, {noReverse: createdChild});
}

// Finally, look up the parent record again and populate the relevant collection.
Expand Down
64 changes: 32 additions & 32 deletions lib/hooks/blueprints/actions/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,36 @@ var _ = require('lodash');
*/
module.exports = function createRecord (req, res) {

var Model = actionUtil.parseModel(req);

// Create data object (monolithic combination of all parameters)
// Omit the blacklisted params (like JSONP callback param, etc.)
var data = actionUtil.parseValues(req);


// Create new instance of model using data from params
Model.create(data).exec(function created (err, newInstance) {

// Differentiate between waterline-originated validation errors
// and serious underlying issues. Respond with badRequest if a
// validation error is encountered, w/ validation info.
if (err) return res.negotiate(err);

// If we have the pubsub hook, use the model class's publish method
// to notify all subscribers about the created item
if (req._sails.hooks.pubsub) {
if (req.isSocket) {
Model.subscribe(req, newInstance);
Model.introduce(newInstance);
}
// Make sure data is JSON-serializable before publishing
var publishData = _.isArray(newInstance) ?
_.map(newInstance, function(instance) {return instance.toJSON();}) :
newInstance.toJSON();
Model.publishCreate(publishData, !req.options.mirror && req);
}

// Send JSONP-friendly response if it's supported
res.created(newInstance);
});
var Model = actionUtil.parseModel(req);

// Create data object (monolithic combination of all parameters)
// Omit the blacklisted params (like JSONP callback param, etc.)
var data = actionUtil.parseValues(req);


// Create new instance of model using data from params
Model.create(data).exec(function created (err, newInstance) {

// Differentiate between waterline-originated validation errors
// and serious underlying issues. Respond with badRequest if a
// validation error is encountered, w/ validation info.
if (err) return res.negotiate(err);

// If we have the pubsub hook, use the model class's publish method
// to notify all subscribers about the created item
if (req._sails.hooks.pubsub) {
if (req.isSocket) {
Model.subscribe(req, newInstance);
Model.introduce(newInstance);
}
// Make sure data is JSON-serializable before publishing
var publishData = _.isArray(newInstance) ?
_.map(newInstance, function(instance) {return instance.toJSON();}) :
newInstance.toJSON();
Model._publishCreate(publishData, !req.options.mirror && req);
}

// Send JSONP-friendly response if it's supported
res.created(newInstance);
});
};
2 changes: 1 addition & 1 deletion lib/hooks/blueprints/actions/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function destroyOneRecord (req, res) {
if (err) return res.negotiate(err);

if (req._sails.hooks.pubsub) {
Model.publishDestroy(pk, !req._sails.config.blueprints.mirror && req, {previous: record});
Model._publishDestroy(pk, !req._sails.config.blueprints.mirror && req, {previous: record});
if (req.isSocket) {
Model.unsubscribe(req, record);
Model.retire(record);
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/blueprints/actions/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = function remove(req, res) {
// If we have the pubsub hook, use the model class's publish method
// to notify all subscribers about the removed item
if (req._sails.hooks.pubsub) {
Model.publishRemove(parentRecord[Model.primaryKey], relation, childPk, !req._sails.config.blueprints.mirror && req);
Model._publishRemove(parentRecord[Model.primaryKey], relation, childPk, !req._sails.config.blueprints.mirror && req);
}

return res.ok(parentRecord);
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/blueprints/actions/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module.exports = function updateOneRecord (req, res) {
// to notify all subscribers about the update.
if (req._sails.hooks.pubsub) {
if (req.isSocket) { Model.subscribe(req, records); }
Model.publishUpdate(pk, _.cloneDeep(values), !req.options.mirror && req, {
Model._publishUpdate(pk, _.cloneDeep(values), !req.options.mirror && req, {
previous: _.cloneDeep(matchingRecord.toJSON())
});
}
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/pubsub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ socket.on('debug', function (msg) { .. });
###### Server
```javascript
// Any of the pubsub methods..
User.publishUpdate()
User._publishUpdate()
sails.sockets.emit()
```

Expand Down
Loading

0 comments on commit c981c6e

Please sign in to comment.