Edited at

Meteorのあんちょこ꒰。・ω・`;꒱ CoffeeScript

More than 3 years have passed since last update.


目的


  • Meteorを他のスクリプト言語でも書けるかな?と思ってトライ。

  • CoffeeScriptが古いっていうのは置いといてください。

  • がんがん、CoffeeScriptで書く気負いもありません。


参考


パッケージの追加


console

$ meteor add coffeescript



  • .meteor/packagesにcoffee scriptが追加される。

  • 下記を見てるとEcmascriptで書くのが良さそう。


packages

# Meteor packages used by this project, one per line.

# Check this file (and the other files in this directory) into your repository.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

meteor-base # Packages every Meteor app needs to have
mobile-experience # Packages for a great mobile UX
mongo # The database Meteor supports right now
blaze-html-templates # Compile .html files into Meteor Blaze views
reactive-var # Reactive variable for tracker
jquery # Helpful client-side library
tracker # Meteor's client-side reactive programming library

standard-minifier-css # CSS minifier run for production mode
standard-minifier-js # JS minifier run for production mode
es5-shim # ECMAScript 5 compatibility for older browsers.
ecmascript # Enable ECMAScript2015+ syntax in app code

autopublish # Publish all data to the clients (for prototyping)
insecure # Allow all DB writes from clients (for prototyping)
coffeescript



JavascriptからCoffeeScriptに変換


server/main.coffee

`import { Meteor } from 'meteor/meteor';`

Meteor.startup ->
console.log "code to run on server at startup"



client/main.coffee

`import { Template } from 'meteor/templating'`

`import { ReactiveVar } from 'meteor/reactive-var'`
`import './main.html'`

Template.hello.events "click button": ->
console.log "You pressed the button" if typeof console isnt "undefined"
return




チャットアプリを作成してみる