Skip to content

Proposal: Support for symbols #146

@jshthornton

Description

@jshthornton

Symbols offer nice features such as ensuring that enums values are actually distinct across different enums.

It would be nice to be able to supply symbols as modifiers so that multiple modifiers of different enums were supported.

Take this example.

const MyEnum = {
  A: 'A',
  B: 'B',
  C: 'C',
};

const YourEnum = {
  A: 'A',
  B: 'B',
  C: 'C',
};

const styles = reactCSS({
  default: {
    root: {
      width: 10,
    }
  },
  [MyEnum.A]: {
    root: {
        width: 20,
    }
  },

  [YourEnum.A]: {
    root: {
      height: 10,
    }
   }
}, {
  [MyEnum.A]: x === MyEnum.A,
  [YourEnum.A]: y === YourEnum.A,
});

This would cause a conflict in keys. To solve this problem enums are often written using symbols.

const MyEnum = {
  A: Symbol('A'),
  B: Symbol('B'),
  C: Symbol('C'),
};

const YourEnum = {
  A: Symbol('A'),
  B: Symbol('B'),
  C: Symbol('C'),
};

The current for own, and to string of key-value doesn't permit symbols to be used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions