Skip to content

Commit f8f75cd

Browse files
committed
More updates to devtools and docs
1 parent caf8814 commit f8f75cd

File tree

26 files changed

+720
-319
lines changed

26 files changed

+720
-319
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ level or any specific nested package level.
5858
npm install diffhtml-render-to-string
5959
```
6060

61-
Use with diffHTML to render your Virtual Trees to strings. This is useful for
62-
server-side rendering and testing.
61+
Use with diffHTML to render your complex markup to strings. This is useful
62+
for server-side rendering, testing, and HTML/XML transformations.
6363

6464
* **[babel-plugin-transform-diffhtml](/packages/babel-plugin-transform-diffhtml)**
6565

6666
``` sh
6767
npm install babel-plugin-transform-diffhtml
6868
```
69-
70-
Converts HTML found in tagged template strings to `createTree` calls and
71-
allows you to shave bytes off your bundles by switching to the
72-
diffHTML runtime build.
69+
Converts markup into function calls. Similar to how JSX compiles down to
70+
`React.createElement`, this module converts HTML elements to function calls.
71+
This is useful for optimizing file size and CPU time by pushing parsing to
72+
the compiler.
7373

7474
* [diffhtml-middleware-logger](/packages/diffhtml-middleware-logger)
7575

docs/api.html

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@
213213

214214

215215

216+
<a href="components.html#lifecycle-hooks" target><li>Lifecycle hooks</li></a>
217+
218+
219+
220+
221+
216222
<a href="components.html#component" target><li>Component</li></a>
217223

218224

@@ -294,18 +300,10 @@ <h1>
294300

295301
<hr></hr>
296302

297-
<section id="content"><h1 id="core-api">Core API</h1>
298-
<a href="https://github.com/tbranyen/diffhtml/tree/master/packages/diffhtml">
299-
<i class="fa fa-github"></i>
300-
</a>
301-
303+
<section id="content"><h1 id="core-api-a-classgithub-hrefhttpsgithubcomtbranyendiffhtmltreemasterpackagesdiffhtmli-classfa-fa-githubia">Core API <a class="github" href="https://github.com/tbranyen/diffhtml/tree/master/packages/diffhtml"><i class="fa fa-github"></i></a></h1>
302304
<p>This reference contains all stable API documentation which is up-to-date with
303305
the latest release. The core was designed to be minimal and familiar if you&#39;ve
304306
used browser DOM APIs such as <code>innerHTML</code> and <code>addEventListener</code>.</p>
305-
<p>Your input will be parsed using the built-in smart HTML parser. This logic will
306-
not run under the
307-
<a href title="null">release build</a>
308-
.</p>
309307
<p><a name="inner-html"></a></p>
310308
<hr></hr>
311309
<h2 id="a-hrefinner-htmlinnerhtmla-domnode-markup-options"><a href="#inner-html">innerHTML</a> <strong><code>(domNode, markup, options)</code></strong></h2>

docs/components.html

Lines changed: 98 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@
213213

214214

215215

216+
<a href="components.html#lifecycle-hooks" target><li>Lifecycle hooks</li></a>
217+
218+
219+
220+
221+
216222
<a href="components.html#component" target><li>Component</li></a>
217223

218224

@@ -294,32 +300,36 @@ <h1>
294300

295301
<hr></hr>
296302

297-
<section id="content"><h1 id="components">Components</h1>
298-
<p>GitHub repository <a href="https://github.com/tbranyen/diffhtml/tree/master/packages/diffhtml-components"><i class="fa fa-github"></i></a></p>
299-
<pre><code class="language-sh">npm install diffhtml-components</code></pre>
300-
<ul>
301-
<li>diffHTML does not require components</li>
302-
<li>Supports a loose interpretation of the React component model and web components</li>
303-
<li>Components are either stateless (cannot re-render, vs stateful and can re-render)</li>
304-
<li></li>
305-
</ul>
306-
<p>While the diffHTML API allows you to build large applications and powerful UIs
307-
on its own, if you&#39;re coming from another framework you may be looking for a
308-
more structured component-based approach.</p>
309-
<p>While it&#39;s easy to build powerful UIs with the diffHTML API alone, if </p>
310-
<p>While you can build many great things with the diffHTML API alone, an improved
311-
way of structuring your creations is through the notion of a Component. The
312-
Component will consolidate a section of your UI and make it re-usable and
313-
encapsulated. Over the years many different &quot;component&quot; interfaces have been
314-
created, but the most popular, which diffHTML is based off of, is React&#39;s.</p>
303+
<section id="content"><h1 id="components-a-classgithub-hrefhttpsgithubcomtbranyendiffhtmltreemasterpackagesdiffhtml-componentsi-classfa-fa-githubia">Components <a class="github" href="https://github.com/tbranyen/diffhtml/tree/master/packages/diffhtml-components"><i class="fa fa-github"></i></a></h1>
304+
<p>When working on larger and more structured projects, you may find that you want
305+
to structure your code using a component paradigm like you would find using
306+
React. This module provides just that, specifically constructors and middleware
307+
necessary to render a React-like JavaScript class/function or Web Component.</p>
315308
<p><a name="overview"></a></p>
316309
<hr></hr>
317310
<h2 id="a-hrefoverviewoverviewa"><a href="#overview">Overview</a></h2>
318-
<p>This package contains middleware to render components in diffHTML. A nice
319-
feature is that you can use any class or function to render a component. So
320-
long as the function or a render method on the class returns a string, VTree,
321-
or DOM Node. The function and class used in this way do not have state and
322-
cannot influence how they re-render.</p>
311+
<p>In order to use components, you must install/fetch the components package. This
312+
contains middleware which will render functions, stateless classes, and
313+
stateful classes. Unlike middleware, this package will automatically hook its
314+
middleware into the running diffHTML build.</p>
315+
<p>Using components in diffHTML always requires installing or including the base
316+
package:</p>
317+
<pre><code class="language-sh">npm install diffhtml-components</code></pre>
318+
<p>If you need to import React components, install the compat package:</p>
319+
<pre><code class="language-sh">npm install diffhtml-react-compat</code></pre>
320+
<blockquote>
321+
<p>This will allow you to replace <code>react</code> and <code>react-dom</code> in your project and
322+
import</p>
323+
</blockquote>
324+
<p>There are two primary packages for components:
325+
<a href="#overview" title="null">diffhtml-components</a>
326+
327+
and
328+
<a href="#react-compat" title="null">diffhtml-react-compat</a>
329+
.Unlike other frameworks diffHTML is
330+
extremely flexible with what you can return, and allows for seamless JSX
331+
integration, top-level fragments, and supports stateless classes that do not
332+
need to extend from a base class.</p>
323333
<h3 id="function-component">Function component</h3>
324334
<pre><code class="language-javascript">import { html, innerHTML } from &#39;diffhtml&#39;;
325335

@@ -342,19 +352,81 @@ <h3 id="class-component">Class component</h3>
342352
}
343353

344354
innerHTML(document.body, html`&lt;${MyComponent} someProp=&quot;value&quot; /&gt;`);</code></pre>
355+
<p><a name="lifecycle-hooks"></a></p>
356+
<hr></hr>
357+
<h2 id="a-hreflifecycle-hookslifecycle-hooksa"><a href="#lifecycle-hooks">Lifecycle hooks</a></h2>
358+
<p>The following hooks will be called during the respective mounting and
359+
unmounting flow. You do not need to extend from <code>Component</code> to use these hooks.
360+
Simple classes can just define them as methods and they will be called.</p>
361+
<h3 id="hooks">Hooks</h3>
362+
<ul>
363+
<li><code>componentWillMount</code></li>
364+
<li><code>componentDidUpdate</code></li>
365+
<li><code>componentWillReceiveProps</code></li>
366+
<li><code>shouldComponentUpdate</code></li>
367+
<li><code>componentWillUnmount</code></li>
368+
</ul>
345369
<p><a name="component"></a></p>
346370
<hr></hr>
347371
<h2 id="a-hrefcomponentcomponenta"><a href="#component">Component</a></h2>
372+
<p>The stateful class component, which is used by importing the <code>Component</code> class.</p>
373+
<pre><code class="language-js">import { Component } from &#39;diffhtml-components&#39;;</code></pre>
374+
<p>Once you have this base class, you can extend your ES6 class to get access to
375+
sub-tree rendering. A component render result is treated as a fragment, and are
376+
compared with previous results. All top-level elements are tracked and
377+
efficient diffing is applied against the previously rendered contents. </p>
378+
<pre><code class="language-js">import { innerHTML, html } from &#39;diffhtml-components&#39;;
379+
import { Component } from &#39;diffhtml-components&#39;;
380+
381+
class ListComponent extends Component {
382+
render({ items }) {
383+
return html`
384+
${items.map(item =&gt; html`
385+
&lt;li&gt;${item}&lt;/li&gt;
386+
`)}
387+
`;
388+
}
389+
}
390+
391+
innerHTML(document.body, html`
392+
&lt;ul&gt;
393+
&lt;${ListComponent} items=${[&#39;List item 1&#39;, &#39;List item 2&#39;]} /&gt;
394+
&lt;/ul&gt;
395+
`);</code></pre>
396+
<h3 id="props">Props</h3>
397+
<p>These are incoming values that map to the props you set using the element
398+
attributes. Like in React, there will be a <code>children</code> prop automatically added
399+
which maps to the passed in child elements. You can access props on
400+
<code>this.props</code> or in the <code>render(props) {}</code> method.</p>
401+
<h3 id="proptypes">PropTypes</h3>
402+
<h3 id="state">State</h3>
403+
<h4 id="forceupdate">forceUpdate</h4>
404+
<h4 id="setstate">setState</h4>
348405
<p><a name="web-component"></a></p>
349406
<hr></hr>
350407
<h2 id="a-hrefweb-componentweb-componenta"><a href="#web-component">Web Component</a></h2>
408+
<p>The WebComponent implementation is nearly identical to the standard
409+
410+
<a href="#component" title="null">Component</a>
411+
, except <code>this</code> points to an HTML element, children are
412+
rendered into the Shadow DOM, and when props and attributes are set on an
413+
element that match <code>propTypes</code> cause an automatic re-render.</p>
414+
<pre><code class="language-js">import { WebComponent } from &#39;diffhtml-components&#39;;</code></pre>
351415
<p><a name="jsx"></a></p>
352416
<hr></hr>
353417
<h2 id="a-hrefjsxjsxa"><a href="#jsx">JSX</a></h2>
354-
<p><a name="react-compatibility"></a></p>
355-
<hr></hr>
356-
<h2 id="a-hrefreact-compatibilityreact-compatibilitya"><a href="#react-compatibility">React Compatibility</a></h2>
418+
<p>JSX is supported out-of-the-box. </p>
419+
<p><a name="react-compat"></a></p>
357420
<hr></hr>
421+
<h2 id="a-hrefreact-compatreact-compata"><a href="#react-compat">React Compat</a></h2>
422+
<p>This experimental module aims to replicate the public API surface-area of React
423+
that is sufficient to execute and render components from that ecosystem. The
424+
reason this is important, is that diffHTML should be able to adopt and help
425+
contribute back to the community that it borrows so much from. It also helps
426+
keep down the level of fragmentation required and initial investment if someone
427+
wants to try out diffHTML in an existing React project.</p>
428+
<p>You can install it by running:</p>
429+
<pre><code class="language-sh">npm install diffhtml-react-compat</code></pre>
358430
</section>
359431

360432
<a href="https://github.com/tbranyen/diffhtml/edit/master/packages/diffhtml-website/pages/components.md" id="edit-on-github">

docs/devtools.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@
213213

214214

215215

216+
<a href="components.html#lifecycle-hooks" target><li>Lifecycle hooks</li></a>
217+
218+
219+
220+
221+
216222
<a href="components.html#component" target><li>Component</li></a>
217223

218224

0 commit comments

Comments
 (0)