Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • beat.web beat.web
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 54
    • Issues 54
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 2
    • Merge requests 2
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • beat
  • beat.webbeat.web
  • Issues
  • #456
Closed
Open
Created Feb 17, 2017 by Jaden DIEFENBAUGH@jdiefenbaughContributor

Refactor globals/"namespaces" in JS to Angular entities

For reasons why global variables are bad, people commonly reference the "GlobalVariablesAreBad" article. Additionally, Angular already provides solutions to homebrew namespaces, so they don't have to be used.

I was going to add example files, but it's so widespread, just look in any of the JS for the experiments/toolchains/etc. apps. A common manifestation of the globals:

// Declaration of our namespaces
if (beat === undefined)
    var beat = {}

if (beat.toolchains === undefined)
    beat.toolchains = {}

if (beat.toolchains.dialogs === undefined)
    beat.toolchains.dialogs = {}

And later in the file, fields are assigned to these globals.

A better approach may be to instead use Angular Services which support DI (dependency injection) and are designed to support heavy processing/data functionality.

Assignee
Assign to
Time tracking