It's pretty easy to pass simple objects between the client and the server using DDP. But did you know that you can pass custom, named objects complete with methods? The folks at Meteor have extended JSON to allow customized, complete objects to be passed over DDP, without you having to worry about serialization/deserialization. This recipe will teach you how to create and use custom EJSON objects, and pass those custom objects between the client and the server.
We will be using the previous recipe found in this chapter, Building custom server methods, as a baseline. Please complete that recipe, and then make the following modifications.
Create a new file named
[project root]/both/swatch.js ...