• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Javascript equivalent of @import in css

Scheduled Pinned Locked Moved General Discussion
9 Posts 2 Posters 798 Views 2 Watching
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 Offline
    sdetweil @DDE12
    last edited by Nov 21, 2022, 1:59 PM

    @DDE12 the code uses the Object .assign() method to merge the config.js module config:{} section onto the defaults section

    from Magicmirror/js/main.js

                    config = Object.assign({}, defaults, config);
    

    this says

          starting with an empty object {}
         add the module defaults
        and then add the config.js module config onto that, REPLACING any 
              properties already defined. 
       return the merged result. 
    

    so, if config.js doesn’t set any value, you get whats in the module defaults section

    thats why you can do

       {
          module:"clock",
          position:"top_left"
       }
    

    with no config

    Sam

    How to add modules

    learning how to use browser developers window for css changes

    S 1 Reply Last reply Nov 21, 2022, 2:06 PM Reply Quote 0
    • S Offline
      sdetweil @sdetweil
      last edited by sdetweil Nov 21, 2022, 4:09 PM Nov 21, 2022, 2:06 PM

      @DDE12 there is no way to do what you want in the FINAL config.js

      one can make a preprocessing step that handles the imports/requires, and produces the final config.js

      we have discussed using this approach for variable substitution, (hide userids/password/apikeys…), without having to interntegrate all that code into the MM base
      see https://github.com/MichMich/MagicMirror/issues/1756

      the ‘issue’ in that the code loads config.js into the webpage as part of a <script> tag… so all pre-processing has to be done before the file is loaded… and it has to be ‘on filesystem’, unless there is a fetch hook added to check for this one filename and handle it differently

      technical debt just gets deeper and deeper as you think about solving different problems here… priacy/security/modularization(yours)/etc…

      edit: editor thought script tag as a REAL script tag and deleted all the content after

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      D 1 Reply Last reply Nov 21, 2022, 3:45 PM Reply Quote 0
      • D Offline
        DDE12 @sdetweil
        last edited by Nov 21, 2022, 3:45 PM

        @sdetweil said in Javascript equivalent of @import in css:

        the ‘issue’ in that the code loads config.js into the webpage as part of a

        Did you have more to discuss?

        I read through the link you posted and the possible solution there and did not see a clear solution that I could follow and tweak. I’m just a tinkerer. I tried your MMM-Config early on but was getting some unwanted results and went away from it. I might work with it again and how it goes. I also thought I could use the expand/collapse feature Notepad++ and put the name of the module after “{”. Notepad++ also has a bookmark feature (that’s the blue dot next to the line 51 indicator) and I think there is a plug-in to extend the bookmark capabilities.
        Expanded.PNG
        Collapsed.PNG.

        Ultimately, I’m trying to have the config.js be a little cleaner and make it easier work through so I am not scrolling through all the lines of code looking for the module section I need. Which, in turn, will help prevent spikes in my blood pressure :face_with_steam_from_nose: . Thank you for looking at this and explaining what the code is doing.

        S 1 Reply Last reply Nov 21, 2022, 3:52 PM Reply Quote 0
        • S Offline
          sdetweil @DDE12
          last edited by sdetweil Nov 21, 2022, 3:53 PM Nov 21, 2022, 3:52 PM

          @DDE12 show me the issues w mmm-config.

          I try to discover every modules usage thru defaults, but many are unclear or undocumented… but I provide a way to get clean content in the form, but it takes a little work.
          I can ship the schema file in MMM-Config if the module is abandoned

          there are lots of old, unmaintained modules

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          D 1 Reply Last reply Nov 21, 2022, 4:02 PM Reply Quote 0
          • D Offline
            DDE12 @sdetweil
            last edited by DDE12 Nov 21, 2022, 4:07 PM Nov 21, 2022, 4:02 PM

            @sdetweil said in Javascript equivalent of @import in css:

            but many are unclear or undocumented…
            there are lots of old, unmaintained modules

            And yayhoos like me making modules. :beaming_face_with_smiling_eyes:
            If I start using MM-Config again and find some oddities, I will post separately so it’s not “hiding” under this topic.

            S 1 Reply Last reply Nov 21, 2022, 4:14 PM Reply Quote 0
            • S Offline
              sdetweil @DDE12
              last edited by sdetweil Nov 21, 2022, 4:31 PM Nov 21, 2022, 4:14 PM

              @DDE12 thanks… and can open issue in module…

              an example fun time

                  in defaults
              
                   foo: false,   // must be boolean?
              

              later

                 if(this.config.foo)
                       element.innerHtml=this.config.foo // no is a string
              

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              1 / 1
              • First post
                8/9
                Last post
              Enjoying MagicMirror? Please consider a donation!
              MagicMirror created by Michael Teeuw.
              Forum managed by Sam, technical setup by Karsten.
              This forum is using NodeBB as its core | Contributors
              Contact | Privacy Policy