To be clear, are you saying that from hence-forth I must use simple-schema
to build Meteor apps? Or are you saying this is just considered best-practices by MDG?
Thoughtful, and I like the spirit of it generally! Still, Promises are part of core now, and theyāre not used, thatās my only critique. Can you omit the callback parameter and get a Promise ? If not, is there any guarantee of whether the callback is invoked sync or async, or multiple times, for the simulation, and the eventual real ?
Ah I was hoping you would comment! What do you think is the best way to integrate promise support here? I feel like itās not yet a good time to switch to always returning a promise, and doing it only sometimes seems weird. Some options:
- Add support for mixins, have a promise mixin that wraps
call
- Make a subclass
class PromiseMethod extends Method
that wrapscall
- Add a new method
callAsync
orcallPromise
As for the callback, it has the same semantics as Meteor.call
- is there some case where that invokes the callback twice, or synchronously? This wrapper could be a good place to fix that, if so.
You donāt need to use simple-schema
, but that will be the path we recommend. The idea is that the core Meteor framework can remain flexible (and actually become more flexible) and the guide project can be completely opinionated.
Iām not sure if you saw this https://github.com/meteor/meteor/pull/5005 but my impression was that making methods return promises is a non-trivial exercise for some complicated reasonsā¦
Youāre making a good point by mentioning Astronomy here. I think that Meteor is definitely lacking a robust and standardized way to set up model classes and hook them to the underlying collections (including validation) in a DRY way. Something that BaseModel and Astronomy are trying to achieve.
Iām using neither of them at the moment (because I did not have enough time to rework my code), so I know the pain that arises from not having such a model wrapper. If I change a field in one of my model classes, I also have to update my SimpleSchema for the collection (which I am not forced to use, but helped me a lot to detect issues), and this of course is double work.
So, instead of just hooking SS into this new way of method invocation, wouldnāt it be better to introduce a more object-oriented modeling paradigm to Meteor, by which the method invocation itself could then decide which validation to use, based on the types of the input parameters? I am speaking of a way of introducing stronger typing to Meteor.
To keep things simple for beginners, this strong typing mechanism could be made opt-in (just like autopublish), but for a maintainable app it would be a must.
We did actually spend some time looking around and calling for suggestions: https://github.com/meteor/guide/issues/534
Looking around (with only one more person other than you and aldeed) is one thing, bringing this up with the community, like you guys did on the Blaze topic is another thing. Besides, it was a āguideā issue, not a ācoreā issue that revolved around redefining how methods work.
JSON Schema seems to be the closest thing to a āstandardā right now, but I think itās a long way away from being that
So yeah, instead of embracing and contributing to the standards, letās do something else (Blaze?) and then when the broader JS community finally comes up with a standard, letās ditch all the hard work and the effort?
f weād been quicker to embrace SS, then I would guess Astronomy ā¦ would probably have used SS for its schemas, and weād be in a better place right now
Well, itās not what happened and you really canāt say that on behalf of Astronomyās author. In fact aldeed himself said the exact opposite, that he would have not bothered creating SS had astronomy existed back then. But thatās besides the point. Iām not advocating astronomy here.
I donāt think we are āshutting out alternativesā, except if you mean choosing something to recommend in the guide and elsewhere
Again, are we talking about the guide or a package thatās very likely to become core? For the latter, taking in SS is not recommending anything, it is a bold statement for SS and against anything else. Subclassing etc are then just technical politics and far cries of the remaining alternatives.
I think the consensus is that itās a very good idea for us to do this.
Again, whose consensus? From the github issue youāve linked, it looks like two or three people.
So my overall point is, I think this decision of yours is a statement of how MDG operates and how Meteor and the community is governed. And it just does not help heal the many similar catastrophies weāve had until now.
Iād say every time since its important to know how it works and what problems it solves. It can be like a pre-requisite. Maybe the package could be offered in the end as a shortcut ānow you know, letās save some timeā - but Iām not comfortable with this being a core package.
This is a big improvement of methods, and I would happily switch over to use the package. I understand @serkandurusoy though. Playing with the package is one thing, but using it in business apps is another with real money at stake.
It would help to know if it will become part of core or being maintained in the long run, so @sashko or @tmeasday maybe can tell something on their plans or long term commitment?
@aldeed after all this blaze drama, news of simpleschema v2 node package is a surprising ray of sunshine!!!
Yeah, now you will have to rewrite your schemas too!
So if check goes by the wayside in favor of Simple Schema, should be then possibly develop a pattern for using it in our publications as well?
An interim would be to use check(input, schema)
since SS already supports use as a match pattern.
Right, Iām just wondering what happens when check is no longer maintained.
Check is a fairly straightforward package which has not seen too many major updates since its inception. I guess one could continue using it with some piece of mind. That being said, Iāll no longer be surprized if/when MDG decides pulling things from under me.
Ah, thanks! I was confusing the platform with the Guide Thanks again for pushing out a best practices document for us all!
Really like your point here of Meteor being flexible but the Guide being opinionated. As noob to development, I always feel like Iām doing something wrong and missing out on important features. It can be discouraging sometimes, so thatās where I think the Guide comes to the rescue. My humble suggestion for the Guide (and Meteor docs perhaps):
Iām a huge fan o the way Stripe structured their documentation: https://stripe.com/docs/api#intro , with the 3 panels split screen showing the menu | explanations | code syntax + examples. Itās really easy to navigate and grasp whatās going on. The examples are few but encompassing, giving you full acknowledgment of the features available. The overall formatting is outstanding.
To start out, I want to say that if building/releasing this kind of package is not the best way forward, then we wonāt do it. This is definitely a request for feedback rather than a set in stone thing.
So hereās how this package came about:
- We needed to write an article for the guide about forms and methods.
- We started thinking about the best ways to call methods, in line with the patterns @tmeasday had been using at Percolate.
- In the initial exploration of the article, the pattern for defining and calling methods became quite verbose - that is from an earlier exploration of best practices for methods.
- Even that verbose pattern didnāt handle
returnStubValue
, and didnāt let you actually display helpful errors on the client when a method invocation failed to validate.
We figured that recommending 15+ lines of boilerplate for every single method call was a bit much, but anything less was not using the Method system to its full potential. Our analysis was that any serious project would need to build its own wrapper class for methods.
Analysis of this thread
Please let me know if Iāve mis-represented your position.
For:
- @efrancis says āitās really greatā
- @avital says āI love the idea of eliminating magic strings, but I donāt want to be forced to use simple-schemaā
- @waldgeist says āGood idea to make method invocation easier, this has some built in features that are very hard to find otherwise, but we shouldnāt tie it to simple-schemaā
- @Steve says āmeteor-call-sync has been doing this for a while, having returnStubValue and throwStubExceptions on by default is a good idea.ā
- @jhartma says āThis is a big improvement of methods, and I would happily switch over to use the package. However, I wouldnāt want to use it in a real business app without a guarantee of support.ā
Against:
- @msavin says āThe guide should explain the underlying issues and teach people how to make a method wrapper for themselves. We should make sure this package is not presented as a replacement for methods.ā
- @serkandurusoy says "I really donāt want MDG to start building things around simple-schema, since itās not a standard and there are some alternatives that might be better. The proposed API seems much better than the previous method API, but Iām uncomfortable for new packages to be introduced in this way.
Neither:
- @SkinnyGeek1010 says āI also wrote a wrapper for methods, which looks different and enforces some modularity in a different way. I think the most important part is understanding what methods exist, and making them easily testable.ā
- @deanius says āA good method API would include support for promises.ā
Conclusions
Itās clear from the conversation that the current method API isnāt ideal, and there is some boilerplate involved to write good, maintainable methods. A wrapper package isnāt necessarily the best way to deal with the situation, but if we had to reproduce the boilerplate in every place in the guide where methods are involved, it would be very difficult to read.
Decouple simple-schema: The built-in simple-schema integration set off some alarms for people. aldeed proposed a simpler API that allows any type of schema to be used, as long as you can write a function that throws validation errors. I think going with that is a good idea. While we are definitely going to be writing code samples for the Meteor guide using simple-schema for a lot of stuff, thereās no reason for it to be hardcoded into anything if it doesnāt have to be.
Guarantee of support: If we release this as a package that we intend people to use, it needs to be maintained. Methods are a crucial part of the Meteor app writing experience, and you wouldnāt want to have bugs in that system introduced by some wrapper code.
Another option - DIY method wrappers?
Thereās one other option other than introducing a package - teach people to write their own method wrapper that encodes some of the same practices. The main downside here is that encouraging people to write custom wrappers for methods will significantly cut down how easy it is for someone to understand a Meteor app they havenāt worked with before. First youāll have to read and understand that particular projectās method wrapper code. So there are benefits to a standardized wrapper package.
Wow, I like this analysis. Would love to see such things in another topics.
Great job, @sashko!
@sashko although the for/against/neither breakdown is somewhat convoluted in its own regard, I think this is a great breakdown and it fills me with joy to see how well you/mdg can assess a given situtation with all of its complexity. Kudos.
I sincerely believe that all arguments pro/con given for the blaze announcement applies here as well, in fact to everything Meteor and I guess the overall concerns are about the API stability and long term support. For this thread specifically, I wish the proposed method api did take cue from the openness of the view layer such that things like schemas/models could be planned out to be more interchangeable.
Apart from that, I find the direction quite pleasing and in line with the overall feel of Meteor.