Repository navigation
Remote method generator - #124
Conversation
There was a problem hiding this comment.
Please remove my name from the NOTE since it's not me who added it ;-) It's ok to keep the note itself though.
There was a problem hiding this comment.
I think we should come up with a convention for targeting people in comments: ie @bajtos like GH to make it obvious.
|
Thank you @jannyHou for the pull request. The implementation looks mostly good! I need you to add tests before this can be landed. |
|
thanks @bajtos ! I am working on test cases now and would commit them with some trivial improvements together in the near future. |
|
hey @bajtos, I added testing and made some changes to code.
the default methodName would be PS:Test failed because I did my two push too close LOL, would be fixed automatically next time I push a new commit. |
There was a problem hiding this comment.
please use the new workspace property in L5 above too.
I find that a bit unusual that one can set method name as an argument but cannot set the model name. How about If we want to get fancy, then we could even support dot-based notation, but I think that's probably not worth our effort. |
There was a problem hiding this comment.
I find meths rather confusing, please use the full name methods.
There was a problem hiding this comment.
yes it's wired, I changed it.
There was a problem hiding this comment.
FWIW, one method may be mapped to multiple HTTP endpoints - see strongloop/loopback-workspace#237 and a real-world example in loopback/lib/persisted-model.js.
For the first version, I think it's ok to support only one http endpoint in the generator. I.e. you can keep httpPath and httpVerb, but make sure you create this.http as an array here.
There was a problem hiding this comment.
I think it's not that complex to turn it an array, same as the loop of accepts and returns, I can implement it as an array in next commit.
I think that would require you to write a custom mock of Yeoman's prompt object. I'm ok to leave this out of this PR (not covered by tests), we don't test looping questions in the model generator either.
👍 |
There was a problem hiding this comment.
We use null for custom value in other places (see e.g. getTypeChoices), please stay consistent and use the same approach here too.
choices: [
'post', 'put', 'delete', 'get', 'head', 'patch',
{ name: '(other)', value: null }
]e2f3b4e to
151272a
Compare
|
Hey @bajtos, I applied your comments and here is the major changes I made today:
Others are minor fixes like naming convention. |
There was a problem hiding this comment.
style: add a space after the assignment operator. (looks like a typo)
var typeChoices = helpers.getTypeChoices;
// ^There was a problem hiding this comment.
Trailing space in both lines above, please remove. I mean the space before \n in strings.
|
@jannyHou thank you for the update, I left few comments how to improve the solution. Also please add sample jsdoc comment per #124 (comment) |
100235d to
185dc19
Compare
|
hey @bajtos , I applied your feedback and uploaded a sample screenshot on slack. |
There was a problem hiding this comment.
I think it's better to use path.join, so that you get common\my-model.json on Windows. Thoughts?
There was a problem hiding this comment.
Actually the file name is not just a model name with .js/.json, you should use ModelDefinition.getPath(this.modelDefinition.facetName, this.modelDefinition) to get the path of the model JSON file and this.modelDefinition.getScriptPath() to get the path of the .js file.
See https://github.com/strongloop/loopback-workspace/blob/73c2fd0e624a64c6e3beee9203caf867d37825b2/common/models/model-definition.js#L91-L106 and https://github.com/strongloop/loopback-workspace/blob/73c2fd0e624a64c6e3beee9203caf867d37825b2/common/models/model-definition.js#L195-L203 for the implementation of those methods.
jsonFilePath = chalk.yellow(jsonFilePath);
// Describe what's next stepHowever, if you feel like adding a comment to introduce a block of code, then it's usually a sign that the block should be extracted into a standalone function, I get back to this below.
[
'line1',
'line2',
'line3 ' + myVar + ' here'
].join('\n')
util.format('line3 %s here', myVar)
A mockup implementation to illustrate my point: printSampleRemoteMethodSource: function() {
var text = [
buildIntroduction(this.modelDefinition),
buildJsdoc(this),
buildMethodSource(this)
].join('\n');
console.log(text);
}
function buildMethodSource(def) {
var ref = def.modelName + (def.isStatic ? '.' : '.prototype.') + def.methodName
var sourceCode = [
ref + ' = function(callback) {',
' // TODO',
' callback(%s);',
'};'
].join('\n');
var inputArgs = buildInputArgs(def.accepts);
sourceCode = sourceCode.replace(/*...*/, inputArgs);
var varDeclarations = buildVarDeclarations(def.returns);
// string replace
var callbackArgs = buildCallbackArgs(def.returns);
// string replace
return sourceCode;
}Perhaps we could do this refactoring together later today? |
There was a problem hiding this comment.
Nitpick: we add a space after //, i.e.// TODO
|
hey @bajtos thank you so much for correcting my code convention problems. According to your feedback, I mainly did four changes to refactor
|
|
Hi @jannyHou, the code building jsdoc comments looks much better now, I find it much easier to read and understand. I left three more comments to address, see above. |
522969a to
d7ae003
Compare
|
hey @bajtos I hope after my change |
d7ae003 to
19ddaa5
Compare
Implement a new generator `yo loopback:remote-method` for creating new model methods exposed via strong-remoting. The generator is also available as `slc loppback:remote-method`
3d934be to
ca3c506
Compare
|
Landed 🎉 👏 |
hey @bajtos, this is the first implementation of
remote-method generatorFurther features are recorded in this issue: #94
Please review it when you have time. And I will add new fields and features in the near future.
Thanks a lot.