jridgewell / babel-plugin-transform-incremental-dom

Turn JSX into IncrementalDOM
MIT License
145 stars 12 forks source link

Detect patch calls as JSX Roots #81

Closed jridgewell closed 7 years ago

jridgewell commented 7 years ago

If you import { patch } from “incremental-dom”, then we will only allow the patch’s CallExpressions to contain root JSX elements.

import { patch } from “incremental-dom”;

// These will not be considered “root” nodes any longer
// That means that `todos` is an array of jsxWrappers containing the <li>.
const todos = lis.map(text => <li>{text}</li>);

// Only patch calls can contain root nodes
patch(container, () => {
  // This passes root node detection, because it is returned and is inside patch call.
  return <ul>{todos}</ul>;
});
jridgewell commented 7 years ago

@edoardocavazza: This may fix #69. Does https://github.com/jridgewell/babel-plugin-transform-incremental-dom/blob/e6bf5f51ec53c2e66ebb695bf5d6ff9d0503591b/test/fixtures/patch-root/69/actual.js match what you're doing?

jridgewell commented 7 years ago

@Tiendq: this may also fix your use case, though it will explicitly break my last code suggestion.