Coder Social home page Coder Social logo

babel-plugin-ivi-jsx's Introduction

babel-plugin-ivi-jsx

babel-plugin-ivi-jsx is a jsx plugin for ivi and is fully typed for TypeScript users.

Installation

# npm
npm install --save-dev babel-plugin-ivi-jsx

# yarn
yarn add --dev babel-plugin-ivi-jsx

Usage

In your .babelrc

{
  "plugins": ["ivi-jsx"]
}

And now this:

function Foo(props) {
  return <div>
    <h1>{props.text}</h1>
    <div class="content">{props.children}</div>
  </div>;
}

is compiled to:

import { div, h1 } from "ivi-html";

function Foo(props) {
  return div().children(
      h1().children(props.text),
      div("content").children(props.children)
  );
}

Usage with TypeScript

Since babel-plugin-ivi-jsx is not required explicitely in your code your editor will not load the types automatically. This is solved by simply adding jsx.d.ts to your tsconfig.json to have a fully typed programming experience.

{
  "compilerOptions": {...},
  "files": [
    "node_modules/babel-plugin-ivi-jsx/jsx.d.ts", // <- Add this
    "path/to/your/entry.ts"
  ]
}

For React users

Since most people dealing with jsx come from the react world, this plugin eases the transition by allowing react-specific attributes:

  • both class and className are supported
  • both unsafeHTML and setDangerouslyInnerHTML are supported
function Foo(props) {
  return <div className="foobar">
    <div setDangerouslyInnerHTML="<h1>Hello World</h1>" />
  </div>;
}

// ... is the same as
function Foo(props) {
  return <div class="foobar">
    <div unsafeHTML="<h1>Hello World</h1>" />
  </div>;
}

Limitations

Currently props which are not of type object are not supported. For those you should fall back to simple function calls.

Example:

function Article(text) {
  return <article>{text}</article>;
}

function Foo() {
  return <div>{Article("Some Content")}</div>;
}

License

MIT, see LICENSE.

babel-plugin-ivi-jsx's People

Contributors

marvinhagemeister avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

babel-plugin-ivi-jsx's Issues

Incompatible use of `input`

Hi @marvinhagemeister thank you for your work on ivi-jsx!

I tried to use it today with ivi 0.8.0 and ivi-* 0.1.0 (core, dom, html, etc.) but it fails on input. It looks like this is because the latest release uses inputText instead of input. This is changed in the current master branch, but that is not yet released.

Any advice? Thanks in advance!

Fix brittle class detection of imported components

Currently the way to detect if a component is a class or a function is really brittle. At it's core babel is meant to work on a file by file basis and doesn't really support parsing file dependencies.

Only import helpers which are needed

We should only import the helpers we need instead of everything at once. This should give a nice improvement in bundle size.

Instead of:

import * as h from "ivi-html";

we should do:

import { div, span } from "ivi-html";

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.