Closed elie222 closed 8 years ago
This is another example it would be nice to be able to access name
:
Lists.methods.makePrivate = new ValidatedMethod({
name: 'Lists.methods.makePrivate',
validate: LIST_ID_ONLY,
run({ listId }) {
if (!this.userId) {
throw new Meteor.Error('Lists.methods.makePrivate.notLoggedIn',
'Must be logged in to make private lists.');
}
The string 'Lists.methods.makePrivate'
appears twice in this code. Would be cleaner to be able to access this.name
instead of rewriting it for every error we throw.
This ties in with another idea: It might not make sense for this
inside the method body to be status about the connection. Given that this looks like a class definition, it could make sense for this
to be the actual method instance, which could contain name
, validate
, etc. However in that case we would have to pass the connection state like userId
and ipAddress
, etc as an argument.
What do you think?
Well it is nice that you're keeping the same API as method. Is there anyway
we could add to this
. Or use the regular this
for the class and then
add things like userId
so it still works as it did before?
On 6 December 2015 at 05:37, Sashko Stubailo notifications@github.com wrote:
This ties in with another idea: It might not make sense for this inside the method body to be status about the connection. Given that this looks like a class definition, it could make sense for this to be the actual method instance, which could contain name, validate, etc. However in that case we would have to pass the connection state like userId and ipAddress, etc as an argument.
What do you think?
— Reply to this email directly or view it on GitHub https://github.com/meteor/validated-method/issues/12#issuecomment-162268043 .
Fixed, published as 0.2.2. I think it wasn't worth it to think too hard about the API.
Speaking of which, being able to add extra stuff like this easily is one of the reasons having a wrapper package is valuable!
5a7ac0b8c7cd3fd1f8ffed9da7ab7eea4492ecde
Sometimes I like to print the name of the method to the console. It would be nice if we could do:
console.log(this.name);
with this package.