https://github.com/keajs/babel-plugin-kea
Kea Babel Plugin
https://github.com/keajs/babel-plugin-kea
Last synced: about 1 month ago
JSON representation
Kea Babel Plugin
- Host: GitHub
- URL: https://github.com/keajs/babel-plugin-kea
- Owner: keajs
- License: mit
- Created: 2020-04-24T13:00:33.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T14:13:28.000Z (about 2 years ago)
- Last Synced: 2024-03-26T22:59:23.026Z (about 1 year ago)
- Language: JavaScript
- Size: 1.02 MB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/babel-plugin-kea)
[](#backers)
[](#sponsors)Note! Version `3.0.0` is designed to work with Kea v3+
# babel-plugin-kea
This plugin helps auto-generate paths for kea logic.
```js
// IN FILE: scenes/homepage/homepageLogic.js// input:
kea({
// ... anything but `path`
})// output:
kea({
path: ['scenes', 'homepage', 'homepageLogic'],
// ... anything but `path`
})// IN FILE: scenes/dashboard/dashboardLogic.js
// input:
kea({
key: (props) => props.id,
// ... anything but `path`
})// output:
kea({
key: (props) => props.id,
path: ['scenes', 'homepage', 'homepageLogic'],
// ... anything but `path`
})// IN FILE: lib/customPage.js
// input:
kea({
path: () => ['special', 'customStuff'],
// other keys
})// output:
kea({
path: () => ['special', 'customStuff'], // path was not modified
// other keys
})// 3.0.0 logic builders
// input:
import { kea } from 'kea'
kea([])// output:
import { kea, path } from 'kea'
kea([path(['special', 'customStuff'])])
```## Installation
First install the package
```bash
# with yarn
yarn add babel-plugin-kea --dev# with npm
npm install babel-plugin-kea --save-dev
```Then add it to the list of plugins in your `.babelrc`:
```js
// .babelrc
{
"plugins": [
"babel-plugin-kea"
]
}
```## Configuration
Logic paths are scoped from the current path. If you wish to skip a few parts of the path, for example
if your frontend lives under `frontend/src` and you don't want every kea path to start with
`frontend.src`, specify it in the config as follows:```js
// .babelrc
{
"plugins": [
["babel-plugin-kea", { "path": "./frontend/src" }]
]
}
```