mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
`Match.Optional` is still only supposed to "pass" if the value is `null` or the specified type. The new `Match.Maybe` allows `undefined` or `null` in addition to the specified types. `Match.Optional` is on the track toward deprecation, however to not break existing code it was *supposed* to stay working the same as before. (per #3876). There weren't tests in place to make sure that `Match.Optional` kept working the same, and the code didn't actually make it keep working the same. Hopefully extra tests will make this better. `.Maybe` has some additional bugs, but should be addressed separately (see #6271) Fixes #6735
check
check is a lightweight package for argument checking and general pattern matching. Use it like this:
Meteor.publish("chats-in-room", function (roomId) {
// Make sure roomId is a string, not an arbitrary mongo selector object.
check(roomId, String);
return Chats.find({room: roomId});
});
Meteor.methods({addChat: function (roomId, message) {
check(roomId, String);
check(message, {
text: String,
timestamp: Date,
// Optional, but if present must be an array of strings.
tags: Match.Optional([String])
});
// ... do something with the message ...
}});
For more details see the check section of the Meteor docs.