export, import, use class with coffeescript in rails5 app

15 views Asked by At

I am trying to fix pusher process in rails 5 app.

However, coffeescript is not working what I expected with export, import error on browser like:

SyntaxError: [stdin]:1:1: reserved word 'export'

or

SyntaxError: [stdin]:1:1: reserved word 'import'

and I tried require but I need to add any library with editing existing settings a lot.

I just want to use pusher settings for creating pusher instances without editing existing codes or adding library.

Is there anyway to export and import with (following) my coffee files?

(WITHOUT libraries which say that I can use require function for importing on browser like browserify-rails, requirejs, etc)

# assets/javascript/config.coffee -------------------------------

export =
  messagingService: 'pusher'
  pusherConfig:
     key: xxx
     (etc...)


# assets/javascript/messagingService.coffee ---------------------

import * as config from "./config.coffee"
class MessagingService
   constructor: ->
      ...
      if config.messagingService.includes('pusher')
         @services.push(new PusherWay1())

   sendMessage: (msg) ->
      ...

   
 # assets/javascript/top_page.coffee ----------------------------
 # pusher fuctions js code for working on browser

 import { MessagingService } from './messaging_service.coffee'
 action_push = () ->
     service = new MessagingService()
     ...
0

There are 0 answers