Skip to content

Instantly share code, notes, and snippets.

@HallM
Last active February 9, 2016 23:28
Show Gist options
  • Save HallM/e7d42805794d589c559d to your computer and use it in GitHub Desktop.
Save HallM/e7d42805794d589c559d to your computer and use it in GitHub Desktop.
// Methods could be any of the CRUD actions
// they may return data like newest info, result data, or just a status
// they could set flash vars (universally) using Flash.post('error', 'something went wrong')
// POST->redirect flow without JS
// the result is probably ok to ignore when you think about the workflow.
// the redirect-to should load a page that loads data anyway.
// we expose Flash system on both sides anyway, so call that in here.
// would just need a way to know where to redirect following a non-XHR
// need to think about reads and how the use case works.
// React component could request data via method to render (one time thing, not thinking of meteor pubsub)
// maybe an Insert method needs to perform a Read method? could happen.
// thinking on the universal aspect, generally these would be called during the rendering
// using a method for rendering may be a bad pattern. could be Router -> Layout/Controller -> methods
// maybe that's it. Router calls controller which can specify the layout/etc and makes method calls (those inner functions in the ogre pattern)
// export if we want this method to be require()'d and callable as like a sub-method
// doesn't *have* to be. if it's only a sub-method, server/client call all be falsey.
// in that case, only the server could call it.
export Platform.method({
params: [
'param1', // no validators or anything. quick and easy
{
name: 'param2',
type: String,
validators: [
{
fn: function(item) {return true;},
// XOR
regex: /\\w+/,
message: 'You got param2 wrong bro'
}
]
}
]
// if client is set, it's callable on the client side as just a function that uses RPC
// we could set client (or server) to falsey to disable over RPC and only work server side
client: {
name: 'myMethodName', // called frontend if Methods.myMethodName(param1, param2)
// on the backend:
// json-rpc or ws: {method: 'myMethodName', params: {param1: 'hello', param2: 'world'}}
// originally thought of a POST for RPC, but then it's just a RESTful interface really
// and we set restful-ness up
},
// mounted server side, mostly for universalness, but also specifies the parameters+order
// would be awesome if I could get the get params working too
// possible to have this disabled and work only via RPC or callable from controllers or other methods
server: {
method: 'post',
url: '/path/to/myMethod/{param1}?p2={param2}', // call with POST /path/to/myMethod/hello?p2=world
nonXhrRedirect: '/redirect/to/page', // could use a better name here
},
// if it returns a promise, itll wait to return result via JSON. or use a then() to alter return result
handler: function(param1, param2) {
return didStuffAsync(param1, param2).then(function(stuff) {
Flash.info('did the thing');
return {thisbejson: stuff};
});
}
// XOR, unless can detect it's a generator instead of a function
yieldTo: function *(param1, param2) {
var stuff = yield didStuff(param1, param2);
Flash.info('did the thing');
return {thisbejson: stuff};
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment