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.

Feature request: Prevent tag name collisions

See original GitHub issue

In order to avoid name collisions for Redux action types it is currently necessary (or at least best practice) to repeat the domain in the type name, for instance:

export const AuthActions = unionize({
  AUTH_LOGIN: ofType<LoginData>(),
  AUTH_LOGIN_SUCCESS: ofType<AuthData>(),
  AUTH_LOGOUT: ofType<void>(),
  AUTH_ERROR: ofType<any>(),
}, {
  tag: 'type',
  value: 'payload',
});

One way to alleviate the issue would be if the type string could be prefixed, for instance:

export const AuthActions = unionize({
  LOGIN: ofType<LoginData>(),
  LOGIN_SUCCESS: ofType<AuthData>(),
  LOGOUT: ofType<void>(),
  ERROR: ofType<any>(),
}, {
  tag: 'type',
  value: 'payload',
  tagPrefix:  'AUTH_'
});

Consumers could then reference things by their short names, e.g. AuthActions.LOGIN while the actual string behind the scenes would be AUTH_LOGIN, thus avoiding collisions with other non-auth domains.

However, this still wouldn’t guarantee that tag name collisions wouldn’t occur. For that a registry of tags would be necessary as well as a way to configure whether the tag names should be considered unique. The registry could have a structure like

const TAG_REGISTRY: {[tag: string]: string[]} = {
  'type': [
    'AUTH_LOGIN',
    'AUTH_LOGIN_SUCCESS',
    'AUTH_LOGOUT',
    'AUTH_ERROR',
  ]
};

and the configuration whether a tag should be considered unique could be done by an option unique: true or similar:

{
  tag: 'type',
  value: 'payload',
  tagPrefix:  'AUTH_',
  unique: true
};

Then if a tag name for the same tag (e.g. type) were to be used twice, an error could be thrown, thus preventing accidental action type collisions.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
pelotomcommented, Apr 18, 2018

So, I guess now that I think about it, this might be a pretty useful combinator to have on the unionized object itself.

const Union1 = unionize(/*...*/);
const Union2 = unionize(/*...*/);
const Union3 = unionize(/*...*/);

// verifies statically that no tags are repeated
const Union4 = Union1.add(Union2).add(Union3);
1reaction
insidewhycommented, May 12, 2018

I want something like:

const friendActions = unionize({
  cuddle: withTag('[Friend] cuddle').ofType({}),
})

const enemyActions = unionize({
  cuddle: withTag('[Enemy] cuddle').ofType({}),
})

Then I can have nice unique tags to read in my redux devtools.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Protected tags - GitLab Docs
Prevent accidental update or deletion once created. Each rule allows you to match either: An individual tag name. Wildcards to control multiple tags...
Read more >
Dealing with special characters in branch and tag names
When using Git from a command-line shell, you may need to escape or quote special characters. About branch and tag names. Most repositories...
Read more >
Auto create pages and assign page-tags when using ...
Collapse namespace prefixes Feature Requests. When creating new pages, in order to avoid conflicts, it's useful to add a prefix.
Read more >
ETag - HTTP - MDN Web Docs
Additionally, etags help to prevent simultaneous updates of a resource from overwriting each other ("mid-air collisions").
Read more >
Feature requests - Perfmatters
21] Option to Woocommerce reviews section from disable comments toggle. [04.26.21] Option to inline select CSS files instead of loading from script tag....
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