tiagolr / hxmeteor

Haxe externs and tools for Meteor.js
MIT License
8 stars 5 forks source link

Meteor Haxe Externs

Externs and tools to build meteor applications using Haxe language.

This is an early version and the externs are not complete, also some of the workflows/concepts are subject to change.

Currently up-to-date:

How it works

Meteor.js has a very specific workflow designed for javascript language, some of its features are slightly modified or workaround when using Haxe.

Check out the example folder

Meteor applications distribute client and server code in many source files or a single one for small apps, haxe uses classes that can be compiled to a single file or a client and a server file containing all the application logic. The examples folder contain different approaches.

In Meteor, the this keyword has a different context and properties in callbacks like: Meteor.publish(), Meteor.method(), template.helpers(), Router.route():

Template.myTemplate.helpers = {
    firstId:function () {
        return this.firstNode().id;
    }
}

Router.route('/', function () {
  this.render('MyTemplate');
});

To mimic these namespaces in a typed manner, context objects like TemplateCtx, PublishCtx, MethodCtx and RouterCtx are provided. The example above becomes:

Templace.get('myTemplate').helpers = {
    firstId:function () {
        return TemplateCtx.firstNode().id;
    }
}

Route.route('/', function () {
    RouterCtx.render('MyTemplate');
});

In meteor it's common to assign global variables when creating collections, these collections become then available from the browser console.

Players = new Mongo.Collection("players");

In Haxe its harder to create global variables, a workaround is to assign the collections to the window object.

var collection = new Collection("players");
untyped js.Browser.window["Players"] = untyped collection._collection;

TODOS

Some ideas for macros and utilities that may improve the haxe-meteor workflow in the future:

Templace.get('myTemplate').helpers = {
    firstId:function (ctx:TemplateCtx) {
        return ctx.firstNode().id;
    }
}

Route.route('/', function (ctx:RouterCtx) {
    ctx.render('MyTemplate');
});

haxelib local use

Besides using Haxelib, you can use this git repos as a development directory:

haxelib dev hxmeteor path/to/folder

or use git directly

haxelib git hxmeteor https://github.com/MatthijsKamstra/hxmeteor.git

don't forget to add it to your build file

-lib hxmeteor