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.

Use `Symbol` rather than `OpaqueToken`

See original GitHub issue

Given the use case for OpaqueToken it seems like you could do away with that type and use Symbol instead. Symbols are immutable and unique, and the polyfills for Symbol are generally lightweight.

More information on Symbol

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
benleshcommented, Oct 4, 2016

As mentioned in Slack:

Advantages to using Symbol:

  • Symbols are completely unique and immutable, no one else’s module can collide with your symbol.
  • Symbols can be used directly as keys to hash tables (might improve your DI perf, depending on your impl)
  • You’ll be reusing a type that already exists in the language
  • You can optionally provide symbols that can be shared globally with Symbol.for.
5reactions
benleshcommented, Oct 8, 2016

@tbosch so this runtime class exists to support build-time typing ergonomics? That doesn’t seem good.

Why not just allow generics on the get method?

const symbol = Symbol.for('foo');
const thing = Injector.get<SomeType>(symbol);

vs

const token = new OpaqueToken<SomeType>('foo');
const thing = Injector.get(token);
Read more comments on GitHub >

github_iconTop Results From Across the Web

angular-cli AOT error resolving symbols - Stack Overflow
I do import some external values into my app using Opaque tokens like this: export let dnnModId: any = new OpaqueToken('moduleId'); ...
Read more >
ubiquityIdentityToken - Documentation - Apple Developer
An opaque token that represents the current user's iCloud Drive Documents ... In macOS, you can instead use an NSDocument object, which establishes...
Read more >
Expression-Based Access Control :: Spring Security
Spring Security uses SpEL for expression support and you should look at how that works if you are interested in understanding the topic...
Read more >
Fix list for IBM WebSphere Application Server V8.5
PH37872, LTPA token getting refreshed using the custom cacheKey instead having to ... PH25547, OIDC incorrect behavior if opaque token is in Authorization ......
Read more >
Using Spring Cloud Gateway with OAuth 2.0 Patterns | Baeldung
OAuth Client; OAuth Resource Server. Let's discuss each of those cases in more detail. 3.1. Spring Cloud Gateway as an OAuth 2.0 Client....
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