punund
punund

Reputation: 4421

client/server approach in Meteor

I am wondering if something as basic as client/server operation model is easily doable with Meteor (meteor.com) framework.

A primitive template should

<template name="input">
  <div>
    <input type="text" val="">
    <input type="submit">
  </div>
</template>

<template name="output">
  <div id="output">
  </div>
</template>

wait for input, calls a server to execute serverFunction() on the input's value, and insert the result into the output tag. No collections, mongo, or authentication required. Of course, every client is supposed to receive its own results. It seems that Meteor.publish() operates only on collections.

Upvotes: 0

Views: 529

Answers (3)

punund
punund

Reputation: 4421

This is what I was looking for:

server:

Meteor.methods = 
  doStuff: (input) ->
    serverFunction input

client:

Template.input.events =
  'submit': ->
    Meteor.call 'doStuff', $('input[type=text]').val(), (error, result) -›
      Session.set 'result', result

Template.output.output = ->
  Session.get 'result

Upvotes: 0

mz2
mz2

Reputation: 4702

Have a look at the Methods section in Meteor documentation: http://docs.meteor.com/#methods_header

"Methods are remote functions that Meteor clients can invoke."

There's also code in the Wordplay example to show how to work this RPC mechanism (see the definition of Meteor.methods({ ... }) in model.js and game.js in this example project for more info).

Upvotes: 1

Lloyd
Lloyd

Reputation: 8406

a Meteor Collection is only associated with a Mongo collection if you tell it to be.. you can also use them to wrap arbitrary data.

The three main benefits of Meteor Collections (for me, at least):

  1. the publish / subscribe model for keeping server and client data in sync
  2. they can wrap persisted (Mongo) or arbitrary data
  3. the ability to query them with Mongo-like syntax

Upvotes: 0

Related Questions