babel-plugin-reactivars-solid
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

babel-plugin-reactivars-solid

babel-plugin-reactivars-solid is a Babel plugin that lets you use a Svelte like syntax with Solid (a React version is a WIP).

import { $ } from 'babel-plugin-reactivars-solid'

const getDouble = ({ $sig }) => 
	({ $doubled: $([
		() => $sig * 2,
		newVal => $sig = newVal / 2
	])})

const CounterChild = ({ $doubleCount }) =>
   <button onClick={() => $doubleCount++}>
      {$doubleCount} (click to add 0.5 to count)
   </button>

const CounterParent = () => {
   let $count = 0
   let { $doubled: $doubleCount } = getDouble({ $sig: $count })
   const incrementCount = () => $doubleCount += 2
   return <>
      <button onClick={incrementCount}>
         {$count}
      </button>
      <CounterChild {...{ $doubleCount }} />
   </>
}

Disclaimer: this plugin doesn't have any known bugs at the moment, but is still not ready for production use. If you find any bugs please open an issue.

Getting Started

See reactivars-example

npm i -D babel-plugin-reactivars-solid @rollup/plugin-babel

Example config:

import { defineConfig } from 'vite';
import solidPlugin from 'vite-plugin-solid';
import { babel } from '@rollup/plugin-babel';

export default defineConfig({
   plugins: [
      {
         ...babel({
            plugins: [
               ["@babel/plugin-syntax-typescript", { isTSX: true }],
               "babel-plugin-reactivars-solid",
            ],
            extensions: [".tsx"]
         }),
         enforce: 'pre'
      },
      solidPlugin()
   ],
   build: {
      target: 'esnext',
      polyfillDynamicImport: false,
   },
});

Roadmap / Missing Features

  • Handle batching, update functions and pending values
  • $ label for effects

Under consideration

  • Reactive variable factory functions (`let doubleCount = double$($count))
  • Two way binding support for input elements

Other cool plugins

Package Sidebar

Install

npm i babel-plugin-reactivars-solid

Weekly Downloads

0

Version

0.0.4

License

MIT

Unpacked Size

83.1 kB

Total Files

32

Last publish

Collaborators

  • orenelb