Code Monkey home page Code Monkey logo

hxmeteor's Introduction

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:

  • Meteor 1.4.2.3.
  • Haxe > 3.2.0

##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

  • File Structuring

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.

  • Context / namespace

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');
});
  • Exposing collections

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:

  • Typed Collections like in haxe-mongoose externs.

  • Expose Collections to the browser automatically on creation.

  • Context Object provided in callbacks, (this objects would need to be removed during compile-time using macros) example:

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

Route.route('/', function (ctx:RouterCtx) {
	ctx.render('MyTemplate');
});
  • Templates List showing available templates and type-check them using macros, something like in this article.

  • ES6 modules output with modular-js

#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

hxmeteor's People

Contributors

matthijskamstra avatar tiagolr avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.