tricky

0.2.0 • Public • Published

Tricky

This repository is the home of the Tricky NPM package.

Tricky was heavily inspired by Meteor. One of the primary goals of Tricky was to bring Meteor-inspired functionality to existing Node projects. If you like what you see, but want the full package, I strongly recommend you check out Meteor.

Do note that while Meteor is open source, Tricky does not actually use any of Meteor's code to do things; this was a decision made because standard Node and Meteor work quite differently. So, instead of using Meteor code and inevitably trying to change things until it works, Tricky just tries to copy the functionality. That means that even if Tricky functionality is based on Meteor, they may not work exactly the same. This is worth submitting an Issue about, but a fix may not be implemented due to the previously mentioned differences.

Installation

  • Use npm install tricky to use the latest published version in your project

Setting up Tricky

  • In your server, give Tricky a global variable via Tricky = require('tricky');
  • Set up Tricky on your web server with Tricky.init(server);. This takes an HTTP server. For use with Express, see below.
  • Set up Tricky on your client with <script type="application/javascript" src="/tricky-client.js"></script>.
    • This needs to be before any code that depends on Tricky, and like all JavaScript it should be at the end of your <body>.
    • Tricky will run Tricky.ready() when it's finished starting up, so if you want to do things afterwards just override that function.
    • Tricky registers a global variable, Tricky, in your browser.

Tricky with Express

Express provides an HTTP server object, so use it something like the following:

var Tricky = require('tricky');

// set up express
var express = require('express');
var app = express();
var server = require('http').createServer(app);

// set up tricky
Tricky.init(server);

Note that the Tricky Demo uses Express, so it offers a real-world use case of Tricky to look at.

Using Tricky

Tricky Methods

A clone of Meteor methods, Tricky methods allow you to call a function from the client that runs on the server, then sends back the response.

  • On the server, construct a method with a given name and with the parameters you expect to have passed to the method. The callback is optional, but if you want to send data back to the client it's required.
  • On the client, call the method using its name and pass any parameters to the method. These parameters are passed wholesale to the server to be executed, and the response is sent directly back to the client.
Server
Tricky.methods({
    add5: function(input, callback) {
        callback(null, input + 5);
    }
});
Client
Tricky.call('add5', 10, function(err, response) {
    console.log('Response: %d', response);
});

Readme

Keywords

none

Package Sidebar

Install

npm i tricky

Weekly Downloads

0

Version

0.2.0

License

MIT

Last publish

Collaborators

  • codechimera