smashingpumpkin smashingpumpkin - 27 days ago 11
CoffeeScript Question

using meteor with coffeescript and jade: callback[i].call is not a function

I have been trying out Meteor with Coffeescript and Jade. And for the most basic app I wrote the following code.

main.coffee

import './hello.coffee'

import './main.jade'


main.jade

head
title Chatter

body
h1 Welcome to Chatter!
+hello


hello.coffee

import { Template } from 'meteor/templating'
import { ReactiveVar } from 'meteor/reactive-var'

import './hello.jade'

Template.hello.onCreated
helloOnCreated: ->
@counter = new ReactiveVar 0
return

Template.hello.helpers
counter: -> Template.instance().counter.get()

Template.hello.events
'click button': (event, instance) ->
instance.counter.set instance.counter.get() + 1
return


hello.jade

template(name="hello")
button Click me!
p You have pressed the button #{counter} times.


Now when I am trying to run this app I am getting this error
Uncaught TypeError: callbacks[i].call is not a function
. I am rather new to this, so any help will be greatly appreciated. Thanks!

dom dom
Answer Source

You're currently passing Template.hello.onCreated an object with a helloOnCreated property. Just pass Template.hello.onCreated a function directly.

Template.hello.onCreated ->
    @counter = new ReactiveVar 0
    return

From Meteor's documentation, the onCreated, onRendered and onDestroyed properties accept functions.

The events and helpers properties accept objects, just like you have.