3

I'm using Opal in my MeteorJS project.

I'm trying to figure out a way to do the Meteor.startup code, but it doesn't seem to work..

I thought this would work:

require 'native'

@Meteor = `Meteor`
@Meteor.startup do
  puts 'Go'
end

But it doesn't. The compiled code should be like the following:

Meteor.startup( function() {
  console.log( "GO" );
} );

It's very regular to throw functions as parameters in JS, how would we do this in Opal?

Tim Baas
  • 6,035
  • 5
  • 45
  • 72

2 Answers2

4

The following should work fine:

require 'native'

@Meteor = Native(`Meteor`)
@Meteor.startup -> {
  puts 'Go'
}

Note that using Native you pass a lambda instead of a block

Elia Schito
  • 989
  • 7
  • 18
1

You can either use Native (which underneath wraps JS objects), as suggested by Elia or...

@Meteor = `Meteor`
@Meteor.JS.startup do
  puts 'Go'
end

Calls like X.JS.y compile directly to X.y(). Similarly, you can access properties like X.JS[:propname] (compiled to X.propname)

hmdne
  • 434
  • 2
  • 5