![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
babel-plugin-cycle-circular
Advanced tools
Babel plugin allowing to have circular dependencies in cycle.js functions.
Babel plugin allowing to have circular dependencies with cycle.js
This (note that componentBar
is used before declared):
const componentFoo = ComponentFoo({value$: componentBar.value$, DOM})
const componentBar = ComponentBar({HTTP, componentFoo.prop$})
will just work.
This is your ES6 source:
import {ComponentFoo} from './ComponentFoo'
import {ComponentBar} from './ComponentBar'
const main = ({DOM, HTTP}) => {
const componentFoo = ComponentFoo({value$: componentBar.value$, DOM})
const componentBar = ComponentBar({HTTP, componentFoo.prop$})
return {
DOM: componentFoo.DOM,
HTTP: componentBar.HTTP
}
}
To get the same result without this plugin
you may
sacrifice functional style and do the following with your hands:
// import subject which is usually not needed
import {Subject} from 'rx'
import {ComponentFoo} from './ComponentFoo'
import {ComponentBar} from './ComponentBar'
const main = ({DOM, HTTP}) => {
// declare proxy subject which will be used to subscribe
// to target stream, and be a source for consumption
const valueProxy$ = new Subject()
// make proxy stream safe - when it ends (or terminates)
// remove subscription to prevent memory leak
const valueSafeProxy$ = valueProxy$.finally(() => {
valueProxySub.dispose()
})
const componentFoo = ComponentFoo({valueSafeProxy$, DOM})
const componentBar = ComponentBar({HTTP, componentFoo.prop$})
// create subscription for target stream
// subscription is actually `side effect`
const valueProxySub = componentBar.value$.subscribe(valueProxy$)
return {
DOM: componentFoo.DOM,
HTTP: componentBar.HTTP
}
}
npm install bable-plugin-cycle-circular
Just add plugin to to your .babelrc
file or transform options:
{
"presets": ["es2015"],
"plugins": ["cycle-circular"]
}
NB!
Current version works only with rx@4.x.x
requires that you have Subject
, or Rx
imported:
import {Subject} from 'rx'
or
const Rx = require('rx')
There are some options that you can supply to the plugin:
minimatch
mask (can be array)minimatch
mask (can be array)Options example:
This options for plugin will exclude from processing all files in models/
folder
and will proxy only if last identifier of reference ends with $
for example component.value$
,
(references like component.value
won't be handled)
{
"presets": ["es2015"],
"plugins": [
["cycle-circular", {
"identifiers": ["\\$$"],
"exlude": ["**/models/**"]
}]
]
}
Tests checks if actual transformed source from fixtures
corresponds to fixed transformed version in the same fixtures/{case}
folder.
npm run test
FAQs
Babel plugin allowing to have circular dependencies in cycle.js functions.
The npm package babel-plugin-cycle-circular receives a total of 3 weekly downloads. As such, babel-plugin-cycle-circular popularity was classified as not popular.
We found that babel-plugin-cycle-circular demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.