0.0.19 • Published 5 years ago

babel-plugin-create-object-id v0.0.19

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

babel-plugin-create-object-id

Creates a sequential id inside objects (only the ones with a render method -aka components-) for later use in (for example) scoping CSS classes by prepending this id to classnames, for example (this is up to you) wrapper => 1000--wrapper.

usage

In .babelrc file include

plugins: [
  [
    "create-object-id"
  ]
]

if you want to use a custom method name that the object must have (instead of render), use the methodName config option:

plugins: [
  [
    "create-object-id", { "methodName": "my custom name" }
  ]
]

input

Any object containing a render method, like:

export default () => {
  return {
    render() {
      return 'Someting';
    }
  }
}

output

Will be transpiled to:

export default () => {
  return {
    render() {
      return 'Someting';
    },
    id: 1000
  }
}

Where the 1000 is a unique id for this component (the definition not the instances that may exists) and starts at 1000 and increments by 1 for each file: 1001, 1002, ....

Why?

This way to can have a unique id for each component that you can use, for example, to scope classes, like:

render() {
  return (
    <div className={`${this.id}--wrapper`}>
      Content
    </div>
  );
}

Or (a better option) to generate this automatically with a Higher Order Function for each component.

This is not an official plugin, just experimental, use it at your own risk.

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago