question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Avoid global state

See original GitHub issue

As for me, having global state like this:

import "./SomeController" // import result affects as a global variable
let app = createExpressServer() // express server implicitly use "SomeController"

is not a good idea, because is handles like global variables. For example, this requries to clear metadata storage before each functional test. I think it could be better, if you made this opt-in, and add ability to explicit pass controllers, interceptors and other citizens to createExpressServer:

import SomeController from "./SomeController"
import SomeInterceptor from "./SomeInterceptor"
let app = createExpressServer(
  SomeController,
  SomeInterceptor
)

or somehow else. What do you think about it?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Stratecommented, Sep 10, 2016

Global state for decorators can be avoided, if metadata information will be stored inside class function (for example in $metadata or $reflection) property. Thank you for that points, I’ll check that.

0reactions
github-actions[bot]commented, Dec 17, 2020

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is Global State so Evil?
Mutable global state is evil because it's very hard for our brain to take into account more than a few parameters at a...
Read more >
Global Variables and States: Why So Much Hate?
The simplest way to avoid globals all together is to simply pass your variables using function arguments. Let's take a simple example: <?php ......
Read more >
How to Overcome Your Fear of Bad Global State - MethodPoet
Global state is generally considered bad in programming for a variety of reasons. Let's explore some of the reasons and look at the...
Read more >
Avoiding mutable global state in browser JS | by Josh Wulf
This means that a local function cannot set the global state by passing in an array of members, and then mutate the global...
Read more >
How do you guys manage "global" state? : r/cpp
I like to avoid global's and just pass stuff in as much as possible. I think singletons are kind of an anti-pattern.... certainly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found