MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord
    MagicMirror² v2.24.0 is available! For more information about this release, check out this topic.

    programming model

    Development
    2
    11
    2129
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      sdetweil last edited by sdetweil

      what is the model being used for both module and helper?

      where and how do I declare variables? either global or instance? (not method variables)

      in a helper if I declare outside the NodeHelper.create(…), they are truely global, and other helpers will overwrite my variables if the names collide.

      Sam

      Create a working config
      How to add modules

      idoodler 1 Reply Last reply Reply Quote 0
      • idoodler
        idoodler Module Developer @sdetweil last edited by

        @sdetweil If you want class variables you can do the following:

        module.exports = NodeHelper.create({
        
            variable1: true,          // This is one way
        
            start: function() {
                this.variable2 = true // This is another way
        
               // Both variables can be accessed via this.VARIABLE_NAME
            }
         });
        
        1 Reply Last reply Reply Quote 0
        • S
          sdetweil last edited by

          thanks…

          strange syntax tho…

          Sam

          Create a working config
          How to add modules

          idoodler 1 Reply Last reply Reply Quote 0
          • idoodler
            idoodler Module Developer @sdetweil last edited by

            @sdetweil Thats simply how to define a variable inside an object in node.js 😄

            1 Reply Last reply Reply Quote 0
            • S
              sdetweil last edited by

              i have a lot of code running in another node/angular mirror app and have never seen this syntax…

              Sam

              Create a working config
              How to add modules

              idoodler 1 Reply Last reply Reply Quote 0
              • idoodler
                idoodler Module Developer @sdetweil last edited by

                @sdetweil Wait, I think I misunderstoodyour question.

                Do you want to have a class variable just in your node_helper.js, or do you want to share a variable between node_helper.js and your MMM-ModuleName.js file?

                1 Reply Last reply Reply Quote 0
                • S
                  sdetweil last edited by

                  not class variable (I got that now), but shared would solve a ton of problems.

                  Sam

                  Create a working config
                  How to add modules

                  idoodler 1 Reply Last reply Reply Quote 0
                  • idoodler
                    idoodler Module Developer @sdetweil last edited by

                    @sdetweil I solved this problem by using this.sendSocketNotification This allows me to communicate with the modules interface.

                    1 Reply Last reply Reply Quote 0
                    • S
                      sdetweil last edited by

                      yeh, but all this notification event handling really messes up the code i have which is all angular promise based.

                      I want to open my own browserwindow (show image), but u can’t do that in a module, only in a helper,
                      but then the window handle object needs to be stored inside the object which is managing the list of images for this ‘viewer’. that object is stored in the module… so, how do I transport the window handle object to the module… is the object valid in the other context (helper vs module).

                      see the topic ‘what can i do in a module’. (which u already have)

                      Sam

                      Create a working config
                      How to add modules

                      idoodler 1 Reply Last reply Reply Quote 0
                      • idoodler
                        idoodler Module Developer @sdetweil last edited by

                        @sdetweil I don’t think that. The helper is running on your Raspberry Pi, the module is running in every browser instance you open.

                        You need to coordinate your “show image event” from the helper and send out a notification to the module what image to show.

                        The ViewManagement must be in the module, the image downloading, handling must be in the helper.

                        Note: You only have one helper, but you can have multiple modules!

                        1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 1 / 2
                        • First post
                          Last post
                        Enjoying MagicMirror? Please consider a donation!
                        MagicMirror created by Michael Teeuw.
                        Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                        This forum is using NodeBB as its core | Contributors
                        Contact | Privacy Policy