Last active
December 2, 2017 08:06
-
-
Save AngelMunoz/a11c3bf0461236f9a534ef43638710c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Let say I have a fancy class with some fancy methods in services|helpers | |
withoud any sails logic in it, eg no waterline, no sails.*.*.js | |
*/ | |
class FancyService { | |
async fancyMethod() { | |
return await Promise.resolve('Fancy Result') | |
} | |
} | |
module.exports = { FancyService }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Let say I have a fancy class in Service.js which I do want to use as a service | |
the convention is to call that service like this | |
sails.services.service.notSoFancyMethod() | |
is there any overhead/problem antipattern, etc in requiring the service instead of calling it from sails.*.*.js? | |
*/ | |
const { FancyService } = require('../services/FancyService'); | |
module.exports = { | |
someAction: async function(req, res) { | |
const fancy = new FancyService(); // this? | |
// or this: const fancy = new sails.services.fancyservice.FancyService(); ? | |
// some logic, etc, etc | |
const results = await fancy.fancyMethod(); | |
res.send({ results }); | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment